Sfoglia il codice sorgente

新增动态增加返回

lishanshan 7 mesi fa
parent
commit
aa0322558f
1 ha cambiato i file con 33 aggiunte e 11 eliminazioni
  1. 33 11
      src/pages/my/dynamic/add_dynamic.vue

+ 33 - 11
src/pages/my/dynamic/add_dynamic.vue

@@ -1,8 +1,6 @@
 <template>
   <view class="publish-container">
-    <u-navbar title="发布动态" bgColor="#fff" @leftClick="cancel"></u-navbar>
-
-    <view class="content-body" :style="{ marginTop: '44px' }">
+    <view class="content-body">
       <view class="text-area">
         <u--textarea
           v-model="formData.title"
@@ -94,11 +92,17 @@
       </u-cell-group>
     </view>
     <view class="footer-bar">
+      <u-button
+        text="返回"
+        shape="circle"
+        customStyle="height: 38px; font-size: 18px; margin-right: 20rpx;"
+        @click="cancel"
+      ></u-button>
       <u-button
         text="立即发布"
         color="linear-gradient(80deg,#02f6c1 0%,#07cdc4 100%)"
         shape="circle"
-        customStyle="height: 48px; font-size: 18px;"
+        customStyle="height: 38px; font-size: 18px;"
         @click="submit('publish')"
       ></u-button>
     </view>
@@ -221,7 +225,6 @@ export default {
               this.mediaType = 'video'
               this.uploadApi = baseUrl + '/common/uploadVi'
               this.formData.videoUrl = data.mediaList[0].mediaUrl
-              // this.formData.videoUrl = data.videoUrl
               this.formData.videoCoverUrl = data.coverUrl
             }
           }
@@ -237,13 +240,16 @@ export default {
     onSuccess(reslut) {
       // 把服务端返回的图片地址添加到list中与组件数据同步
       if (reslut.code === 200) {
-        const isVideo = reslut.url.endsWith('.mp4')
+        const isVideo =
+          reslut.url.endsWith('.mp4') ||
+          reslut.url.endsWith('.mov') ||
+          reslut.url.endsWith('.mkv') ||
+          reslut.url.endsWith('.wmv')
         if (isVideo) {
-          this.formData.videoUrl = reslut.url
-          console.log('视频地址:', this.formData.videoUrl)
-          this.formData.videoCoverUrl = reslut.coverUrl
+          this.formData.videoUrl = baseUrl + reslut.url
+          this.formData.videoCoverUrl = baseUrl + reslut.coverUrl
         } else {
-          this.fileList.push(reslut.url)
+          this.fileList.push(baseUrl + reslut.url)
         }
       } else {
         this.mediaType = 'all'
@@ -301,9 +307,25 @@ export default {
       this.formData.visibleRange = e.value[0]
       this.showScopePicker = false
     },
+    // 检查是否有未保存的内容
+    hasUnsavedContent() {
+      return (
+        this.formData.title ||
+        this.formData.content ||
+        this.fileList.length > 0 ||
+        this.formData.videoUrl ||
+        this.formData.location ||
+        this.formData.visibleRange
+      )
+    },
     // 保存草稿
     cancel() {
-      this.popShow = true
+      if (!this.hasUnsavedContent()) {
+        uni.navigateBack()
+        return
+      } else {
+        this.popShow = true
+      }
     },
     popClose() {
       this.popShow = false