木邻有你前端代码仓库
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.

340 lines
7.2 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month 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. <GlobalPopup ref="globalPopupRef"></GlobalPopup>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. name: 'PublishPost',
  76. data() {
  77. return {
  78. content: '',
  79. image: [],
  80. isPhoto: false
  81. }
  82. },
  83. methods: {
  84. chooseImage() {
  85. const remainingCount = 9 - this.image.length
  86. uni.chooseImage({
  87. count: 1,
  88. sourceType: ['album', 'camera'],
  89. success: async (res) => {
  90. // const tempFiles = res.tempFiles.map(file => file.tempFilePath)
  91. // this.image = [...this.image, ...tempFiles]
  92. // console.log(...res.tempFilePaths);
  93. const file = {
  94. path: res.tempFilePaths[0]
  95. }
  96. const uploadRes = await this.$utils.uploadImage(file)
  97. this.image.push(uploadRes.url)
  98. uni.showToast({
  99. title: '图片上传成功',
  100. icon: 'success'
  101. })
  102. },
  103. fail: (err) => {
  104. console.error('选择图片失败:', err)
  105. }
  106. })
  107. },
  108. removeImage(index) {
  109. this.image.splice(index, 1)
  110. },
  111. async submitPost() {
  112. if (!this.content.trim()) {
  113. uni.showToast({
  114. title: '请输入留言内容',
  115. icon: 'none'
  116. })
  117. return
  118. }
  119. const res = await this.$api.community.addPost({
  120. content: this.content,
  121. image: this.image.toString(),
  122. type: this.isPhoto ? 1 : 0
  123. })
  124. if (res.code === 200) {
  125. this.$refs.globalPopupRef.open({
  126. content: '您的随手拍内容已提交审核!',
  127. subContent: '审核通过后会自动展示在随手拍上!',
  128. titleType: 'submit',
  129. popupType: 'success',
  130. closefn: () => {
  131. setTimeout(() => {
  132. uni.navigateBack()
  133. }, 1500)
  134. }
  135. })
  136. }else {
  137. uni.showToast({
  138. title: `${res.message}`,
  139. icon: 'none'
  140. })
  141. }
  142. }
  143. },
  144. onLoad(options) {
  145. if (options.page === 'photo') {
  146. this.isPhoto = true
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .publish-page {
  153. min-height: 100vh;
  154. background-color: #F3F7F8;
  155. // display: flex;
  156. // flex-direction: column;
  157. }
  158. // 顶部提示容器
  159. .tip-container {
  160. background-color: #E3F2FD;
  161. padding: 24rpx 32rpx;
  162. margin: 20rpx;
  163. border-radius: 12rpx;
  164. display: flex;
  165. align-items: flex-start;
  166. gap: 16rpx;
  167. border-left: 6rpx solid #007AFF;
  168. }
  169. .tip-text {
  170. font-size: 26rpx;
  171. color: #1976D2;
  172. line-height: 1.5;
  173. flex: 1;
  174. }
  175. // 主要内容容器
  176. .main-container {
  177. flex: 1;
  178. margin: 0 20rpx;
  179. background-color: white;
  180. border-radius: 16rpx;
  181. padding: 32rpx;
  182. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  183. }
  184. .title-section {
  185. margin-bottom: 32rpx;
  186. display: flex;
  187. align-items: center;
  188. gap: 16rpx;
  189. }
  190. .vertical-line {
  191. width: 8rpx;
  192. height: 40rpx;
  193. border-radius: 4rpx;
  194. &.red {
  195. background-color: #FF4757;
  196. }
  197. &.blue {
  198. background-color: #007AFF;
  199. }
  200. }
  201. .title-text {
  202. font-size: 36rpx;
  203. font-weight: bold;
  204. color: #333;
  205. }
  206. // 留言板区域
  207. .message-section {
  208. margin-bottom: 40rpx;
  209. }
  210. .section-label {
  211. font-size: 28rpx;
  212. color: #666;
  213. display: block;
  214. margin-bottom: 20rpx;
  215. }
  216. .textarea-container {
  217. position: relative;
  218. background-color: #f5f5f5;
  219. border-radius: 12rpx;
  220. padding: 24rpx;
  221. }
  222. .message-textarea {
  223. width: 100%;
  224. min-height: 300rpx;
  225. font-size: 30rpx;
  226. color: #333;
  227. background-color: transparent;
  228. border: none;
  229. outline: none;
  230. resize: none;
  231. line-height: 1.6;
  232. }
  233. .char-count {
  234. position: absolute;
  235. bottom: 16rpx;
  236. right: 16rpx;
  237. }
  238. .count-text {
  239. font-size: 24rpx;
  240. color: #999;
  241. }
  242. // 图片区域
  243. .image-section {
  244. margin-bottom: 40rpx;
  245. }
  246. .image-grid {
  247. display: flex;
  248. flex-wrap: wrap;
  249. gap: 16rpx;
  250. }
  251. .image-item {
  252. position: relative;
  253. width: 200rpx;
  254. height: 200rpx;
  255. border-radius: 12rpx;
  256. overflow: hidden;
  257. }
  258. .preview-image {
  259. width: 100%;
  260. height: 100%;
  261. }
  262. .delete-btn {
  263. position: absolute;
  264. top: 8rpx;
  265. right: 8rpx;
  266. width: 40rpx;
  267. height: 40rpx;
  268. background-color: rgba(0, 0, 0, 0.6);
  269. border-radius: 50%;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. }
  274. .add-image-btn {
  275. width: 200rpx;
  276. height: 200rpx;
  277. border: 2rpx dashed #ddd;
  278. border-radius: 12rpx;
  279. display: flex;
  280. flex-direction: column;
  281. align-items: center;
  282. justify-content: center;
  283. gap: 12rpx;
  284. background-color: #fafafa;
  285. transition: all 0.3s ease;
  286. &:active {
  287. background-color: #f0f0f0;
  288. border-color: #007AFF;
  289. }
  290. }
  291. .add-text {
  292. font-size: 24rpx;
  293. color: #999;
  294. }
  295. // 提交按钮容器
  296. .submit-container {
  297. padding: 32rpx 40rpx;
  298. // background-color: white;
  299. margin-top: 60rpx;
  300. border-top: 1rpx solid #f0f0f0;
  301. }
  302. .submit-btn {
  303. width: 100%;
  304. height: 88rpx;
  305. border-radius: 44rpx;
  306. font-size: 32rpx;
  307. font-weight: bold;
  308. }
  309. </style>