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

337 lines
7.1 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
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. <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. })
  131. setTimeout(() => {
  132. uni.navigateBack()
  133. }, 2000)
  134. }else {
  135. uni.showToast({
  136. title: `${res.message}`,
  137. icon: 'none'
  138. })
  139. }
  140. }
  141. },
  142. onLoad(options) {
  143. if (options.page === 'photo') {
  144. this.isPhoto = true
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .publish-page {
  151. min-height: 100vh;
  152. background-color: #F3F7F8;
  153. // display: flex;
  154. // flex-direction: column;
  155. }
  156. // 顶部提示容器
  157. .tip-container {
  158. background-color: #E3F2FD;
  159. padding: 24rpx 32rpx;
  160. margin: 20rpx;
  161. border-radius: 12rpx;
  162. display: flex;
  163. align-items: flex-start;
  164. gap: 16rpx;
  165. border-left: 6rpx solid #007AFF;
  166. }
  167. .tip-text {
  168. font-size: 26rpx;
  169. color: #1976D2;
  170. line-height: 1.5;
  171. flex: 1;
  172. }
  173. // 主要内容容器
  174. .main-container {
  175. flex: 1;
  176. margin: 0 20rpx;
  177. background-color: white;
  178. border-radius: 16rpx;
  179. padding: 32rpx;
  180. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  181. }
  182. .title-section {
  183. margin-bottom: 32rpx;
  184. display: flex;
  185. align-items: center;
  186. gap: 16rpx;
  187. }
  188. .vertical-line {
  189. width: 8rpx;
  190. height: 40rpx;
  191. border-radius: 4rpx;
  192. &.red {
  193. background-color: #FF4757;
  194. }
  195. &.blue {
  196. background-color: #007AFF;
  197. }
  198. }
  199. .title-text {
  200. font-size: 36rpx;
  201. font-weight: bold;
  202. color: #333;
  203. }
  204. // 留言板区域
  205. .message-section {
  206. margin-bottom: 40rpx;
  207. }
  208. .section-label {
  209. font-size: 28rpx;
  210. color: #666;
  211. display: block;
  212. margin-bottom: 20rpx;
  213. }
  214. .textarea-container {
  215. position: relative;
  216. background-color: #f5f5f5;
  217. border-radius: 12rpx;
  218. padding: 24rpx;
  219. }
  220. .message-textarea {
  221. width: 100%;
  222. min-height: 300rpx;
  223. font-size: 30rpx;
  224. color: #333;
  225. background-color: transparent;
  226. border: none;
  227. outline: none;
  228. resize: none;
  229. line-height: 1.6;
  230. }
  231. .char-count {
  232. position: absolute;
  233. bottom: 16rpx;
  234. right: 16rpx;
  235. }
  236. .count-text {
  237. font-size: 24rpx;
  238. color: #999;
  239. }
  240. // 图片区域
  241. .image-section {
  242. margin-bottom: 40rpx;
  243. }
  244. .image-grid {
  245. display: flex;
  246. flex-wrap: wrap;
  247. gap: 16rpx;
  248. }
  249. .image-item {
  250. position: relative;
  251. width: 200rpx;
  252. height: 200rpx;
  253. border-radius: 12rpx;
  254. overflow: hidden;
  255. }
  256. .preview-image {
  257. width: 100%;
  258. height: 100%;
  259. }
  260. .delete-btn {
  261. position: absolute;
  262. top: 8rpx;
  263. right: 8rpx;
  264. width: 40rpx;
  265. height: 40rpx;
  266. background-color: rgba(0, 0, 0, 0.6);
  267. border-radius: 50%;
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. }
  272. .add-image-btn {
  273. width: 200rpx;
  274. height: 200rpx;
  275. border: 2rpx dashed #ddd;
  276. border-radius: 12rpx;
  277. display: flex;
  278. flex-direction: column;
  279. align-items: center;
  280. justify-content: center;
  281. gap: 12rpx;
  282. background-color: #fafafa;
  283. transition: all 0.3s ease;
  284. &:active {
  285. background-color: #f0f0f0;
  286. border-color: #007AFF;
  287. }
  288. }
  289. .add-text {
  290. font-size: 24rpx;
  291. color: #999;
  292. }
  293. // 提交按钮容器
  294. .submit-container {
  295. padding: 32rpx 40rpx;
  296. // background-color: white;
  297. margin-top: 60rpx;
  298. border-top: 1rpx solid #f0f0f0;
  299. }
  300. .submit-btn {
  301. width: 100%;
  302. height: 88rpx;
  303. border-radius: 44rpx;
  304. font-size: 32rpx;
  305. font-weight: bold;
  306. }
  307. </style>