木邻有你前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
6.9 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <template>
  2. <view class="publish-page">
  3. <!-- 顶部提示容器 -->
  4. <view class="tip-container">
  5. <uv-icon name="info-circle-fill" size="16" color="#007AFF"></uv-icon>
  6. <text class="tip-text">留言板内容要经过审核才能发布成功提交审核中请耐心等待审核通过后会上线</text>
  7. </view>
  8. <!-- 主要内容容器 -->
  9. <view class="main-container">
  10. <!-- 木邻说标题 -->
  11. <view class="title-section">
  12. <!-- 加一个小竖条 -->
  13. <view class="vertical-line" :class="isPhoto ? 'red' : 'blue'"></view>
  14. <text class="title-text"> {{ isPhoto ? '木龄见' : '木龄说' }} </text>
  15. </view>
  16. <!-- 留言板输入区域 -->
  17. <view class="message-section">
  18. <text class="section-label">您对本社区发展有什么建议和期待欢迎留言</text>
  19. <view class="textarea-container">
  20. <textarea
  21. class="message-textarea"
  22. v-model="content"
  23. placeholder="请输入您的留言内容..."
  24. maxlength="500"
  25. :show-confirm-bar="false"
  26. ></textarea>
  27. <view class="char-count">
  28. <text class="count-text">{{ content.length }}/500</text>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 添加图片区域 -->
  33. <view class="image-section">
  34. <view class="image-grid">
  35. <!-- 已选择的图片 -->
  36. <view
  37. class="image-item"
  38. v-for="(image, index) in image"
  39. :key="index"
  40. >
  41. <image class="preview-image" :src="image" mode="aspectFill"></image>
  42. <view class="delete-btn" @click="removeImage(index)">
  43. <uv-icon name="close" size="12" color="white"></uv-icon>
  44. </view>
  45. </view>
  46. <!-- 添加图片按钮 -->
  47. <view
  48. class="add-image-btn"
  49. v-if="image.length < 9"
  50. @click="chooseImage"
  51. >
  52. <uv-icon name="plus" size="24" color="#999"></uv-icon>
  53. <text class="add-text">添加图片</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 提交按钮容器 -->
  59. <view class="submit-container">
  60. <uv-button
  61. class="submit-btn"
  62. type="primary"
  63. shape="circle"
  64. :disabled="!content.trim()"
  65. @click="submitPost"
  66. >
  67. 提交审核
  68. </uv-button>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. export default {
  74. name: 'PublishPost',
  75. data() {
  76. return {
  77. content: '',
  78. image: [],
  79. isPhoto: false
  80. }
  81. },
  82. methods: {
  83. chooseImage() {
  84. const remainingCount = 9 - this.image.length
  85. uni.chooseImage({
  86. count: 1,
  87. sourceType: ['album', 'camera'],
  88. success: async (res) => {
  89. // const tempFiles = res.tempFiles.map(file => file.tempFilePath)
  90. // this.image = [...this.image, ...tempFiles]
  91. // console.log(...res.tempFilePaths);
  92. const file = {
  93. path: res.tempFilePaths[0]
  94. }
  95. const uploadRes = await this.$utils.uploadImage(file)
  96. this.image.push(uploadRes.url)
  97. uni.showToast({
  98. title: '图片上传成功',
  99. icon: 'success'
  100. })
  101. },
  102. fail: (err) => {
  103. console.error('选择图片失败:', err)
  104. }
  105. })
  106. },
  107. removeImage(index) {
  108. this.image.splice(index, 1)
  109. },
  110. async submitPost() {
  111. if (!this.content.trim()) {
  112. uni.showToast({
  113. title: '请输入留言内容',
  114. icon: 'none'
  115. })
  116. return
  117. }
  118. const res = await this.$api.community.addPost({
  119. content: this.content,
  120. image: this.image.toString(),
  121. type: this.isPhoto ? 1 : 0
  122. })
  123. if (res.code === 200) {
  124. uni.showToast({
  125. title: '提交成功',
  126. icon: 'success'
  127. })
  128. setTimeout(() => {
  129. uni.navigateBack()
  130. }, 1000)
  131. }else {
  132. uni.showToast({
  133. title: `${res.message}`,
  134. icon: 'none'
  135. })
  136. }
  137. }
  138. },
  139. onLoad(options) {
  140. if (options.page === 'photo') {
  141. this.isPhoto = true
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .publish-page {
  148. min-height: 100vh;
  149. background-color: #F3F7F8;
  150. // display: flex;
  151. // flex-direction: column;
  152. }
  153. // 顶部提示容器
  154. .tip-container {
  155. background-color: #E3F2FD;
  156. padding: 24rpx 32rpx;
  157. margin: 20rpx;
  158. border-radius: 12rpx;
  159. display: flex;
  160. align-items: flex-start;
  161. gap: 16rpx;
  162. border-left: 6rpx solid #007AFF;
  163. }
  164. .tip-text {
  165. font-size: 26rpx;
  166. color: #1976D2;
  167. line-height: 1.5;
  168. flex: 1;
  169. }
  170. // 主要内容容器
  171. .main-container {
  172. flex: 1;
  173. margin: 0 20rpx;
  174. background-color: white;
  175. border-radius: 16rpx;
  176. padding: 32rpx;
  177. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  178. }
  179. .title-section {
  180. margin-bottom: 32rpx;
  181. display: flex;
  182. align-items: center;
  183. gap: 16rpx;
  184. }
  185. .vertical-line {
  186. width: 8rpx;
  187. height: 40rpx;
  188. border-radius: 4rpx;
  189. &.red {
  190. background-color: #FF4757;
  191. }
  192. &.blue {
  193. background-color: #007AFF;
  194. }
  195. }
  196. .title-text {
  197. font-size: 36rpx;
  198. font-weight: bold;
  199. color: #333;
  200. }
  201. // 留言板区域
  202. .message-section {
  203. margin-bottom: 40rpx;
  204. }
  205. .section-label {
  206. font-size: 28rpx;
  207. color: #666;
  208. display: block;
  209. margin-bottom: 20rpx;
  210. }
  211. .textarea-container {
  212. position: relative;
  213. background-color: #f5f5f5;
  214. border-radius: 12rpx;
  215. padding: 24rpx;
  216. }
  217. .message-textarea {
  218. width: 100%;
  219. min-height: 300rpx;
  220. font-size: 30rpx;
  221. color: #333;
  222. background-color: transparent;
  223. border: none;
  224. outline: none;
  225. resize: none;
  226. line-height: 1.6;
  227. }
  228. .char-count {
  229. position: absolute;
  230. bottom: 16rpx;
  231. right: 16rpx;
  232. }
  233. .count-text {
  234. font-size: 24rpx;
  235. color: #999;
  236. }
  237. // 图片区域
  238. .image-section {
  239. margin-bottom: 40rpx;
  240. }
  241. .image-grid {
  242. display: flex;
  243. flex-wrap: wrap;
  244. gap: 16rpx;
  245. }
  246. .image-item {
  247. position: relative;
  248. width: 200rpx;
  249. height: 200rpx;
  250. border-radius: 12rpx;
  251. overflow: hidden;
  252. }
  253. .preview-image {
  254. width: 100%;
  255. height: 100%;
  256. }
  257. .delete-btn {
  258. position: absolute;
  259. top: 8rpx;
  260. right: 8rpx;
  261. width: 40rpx;
  262. height: 40rpx;
  263. background-color: rgba(0, 0, 0, 0.6);
  264. border-radius: 50%;
  265. display: flex;
  266. align-items: center;
  267. justify-content: center;
  268. }
  269. .add-image-btn {
  270. width: 200rpx;
  271. height: 200rpx;
  272. border: 2rpx dashed #ddd;
  273. border-radius: 12rpx;
  274. display: flex;
  275. flex-direction: column;
  276. align-items: center;
  277. justify-content: center;
  278. gap: 12rpx;
  279. background-color: #fafafa;
  280. transition: all 0.3s ease;
  281. &:active {
  282. background-color: #f0f0f0;
  283. border-color: #007AFF;
  284. }
  285. }
  286. .add-text {
  287. font-size: 24rpx;
  288. color: #999;
  289. }
  290. // 提交按钮容器
  291. .submit-container {
  292. padding: 32rpx 40rpx;
  293. // background-color: white;
  294. margin-top: 60rpx;
  295. border-top: 1rpx solid #f0f0f0;
  296. }
  297. .submit-btn {
  298. width: 100%;
  299. height: 88rpx;
  300. border-radius: 44rpx;
  301. font-size: 32rpx;
  302. font-weight: bold;
  303. }
  304. </style>