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

350 lines
7.4 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. <template>
  2. <view class="publish-page">
  3. <!-- 顶部提示容器 -->
  4. <view class="tip-container" :class="isPhoto ? 'red' : 'blue'" >
  5. <uv-icon name="info-circle-fill" size="16" :color="isPhoto ? '#FF4757' : '#007AFF'"></uv-icon>
  6. <text class="tip-text" :class="isPhoto ? 'red' : 'blue'">{{ configParamText('photo_and_word_introduce') }}</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"> {{ isPhoto ? configParamText('photo_title') : configParamText('word_title') }}</text>
  19. <view class="textarea-container">
  20. <textarea
  21. class="message-textarea"
  22. v-model="content"
  23. :placeholder="isPhoto ? configParamText('photo_tip') : configParamText('word_tip')"
  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=" isPhoto ? 'error' : '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. }, 300)
  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. &.red{
  169. border-left-color: #FF4757;
  170. background-color: rgba(255, 71, 87, 0.1);
  171. }
  172. &.blue{
  173. border-left-color: #007AFF;
  174. }
  175. }
  176. .tip-text {
  177. font-size: 26rpx;
  178. color: #1976D2;
  179. &.red{
  180. color: #FF4757;
  181. }
  182. line-height: 1.5;
  183. flex: 1;
  184. }
  185. // 主要内容容器
  186. .main-container {
  187. flex: 1;
  188. margin: 0 20rpx;
  189. background-color: white;
  190. border-radius: 16rpx;
  191. padding: 32rpx;
  192. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  193. }
  194. .title-section {
  195. margin-bottom: 32rpx;
  196. display: flex;
  197. align-items: center;
  198. gap: 16rpx;
  199. }
  200. .vertical-line {
  201. width: 8rpx;
  202. height: 40rpx;
  203. border-radius: 4rpx;
  204. &.red {
  205. background-color: #FF4757;
  206. }
  207. &.blue {
  208. background-color: #007AFF;
  209. }
  210. }
  211. .title-text {
  212. font-size: 36rpx;
  213. font-weight: bold;
  214. color: #333;
  215. }
  216. // 留言板区域
  217. .message-section {
  218. margin-bottom: 40rpx;
  219. }
  220. .section-label {
  221. font-size: 28rpx;
  222. color: #666;
  223. display: block;
  224. margin-bottom: 20rpx;
  225. }
  226. .textarea-container {
  227. position: relative;
  228. background-color: #f5f5f5;
  229. border-radius: 12rpx;
  230. padding: 24rpx;
  231. }
  232. .message-textarea {
  233. width: 100%;
  234. min-height: 300rpx;
  235. font-size: 30rpx;
  236. color: #333;
  237. background-color: transparent;
  238. border: none;
  239. outline: none;
  240. resize: none;
  241. line-height: 1.6;
  242. }
  243. .char-count {
  244. position: absolute;
  245. bottom: 16rpx;
  246. right: 16rpx;
  247. }
  248. .count-text {
  249. font-size: 24rpx;
  250. color: #999;
  251. }
  252. // 图片区域
  253. .image-section {
  254. margin-bottom: 40rpx;
  255. }
  256. .image-grid {
  257. display: flex;
  258. flex-wrap: wrap;
  259. gap: 16rpx;
  260. }
  261. .image-item {
  262. position: relative;
  263. width: 200rpx;
  264. height: 200rpx;
  265. border-radius: 12rpx;
  266. overflow: hidden;
  267. }
  268. .preview-image {
  269. width: 100%;
  270. height: 100%;
  271. }
  272. .delete-btn {
  273. position: absolute;
  274. top: 8rpx;
  275. right: 8rpx;
  276. width: 40rpx;
  277. height: 40rpx;
  278. background-color: rgba(0, 0, 0, 0.6);
  279. border-radius: 50%;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. }
  284. .add-image-btn {
  285. width: 200rpx;
  286. height: 200rpx;
  287. border: 2rpx dashed #ddd;
  288. border-radius: 12rpx;
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. justify-content: center;
  293. gap: 12rpx;
  294. background-color: #fafafa;
  295. transition: all 0.3s ease;
  296. &:active {
  297. background-color: #f0f0f0;
  298. border-color: #007AFF;
  299. }
  300. }
  301. .add-text {
  302. font-size: 24rpx;
  303. color: #999;
  304. }
  305. // 提交按钮容器
  306. .submit-container {
  307. padding: 32rpx 40rpx;
  308. // background-color: white;
  309. margin-top: 60rpx;
  310. border-top: 1rpx solid #f0f0f0;
  311. }
  312. .submit-btn {
  313. width: 100%;
  314. height: 88rpx;
  315. border-radius: 44rpx;
  316. font-size: 32rpx;
  317. font-weight: bold;
  318. }
  319. </style>