Explorar el Código

修改视频投稿页面和状态发布页面提交的数据模型

reghao hace 3 años
padre
commit
a13ff771b3
Se han modificado 3 ficheros con 31 adiciones y 34 borrados
  1. 6 2
      src/components/card/status-card.vue
  2. 19 26
      src/views/mblog/mblog.vue
  3. 6 6
      src/views/studio/upload.vue

+ 6 - 2
src/components/card/status-card.vue

@@ -19,7 +19,7 @@
         <v-row v-if="item.imageUrls.length !== 0">
           <v-col
             v-for="imageUrl in item.imageUrls"
-            :key="imageUrl"
+            :key="imageUrl.thumbnailUrl"
             class="d-flex child-flex"
             cols="4"
           >
@@ -79,7 +79,11 @@ export default {
       'setImageZoom',
       'setDetailContent'
     ]),
-    showImage(imgs) {
+    showImage(imageUrls) {
+      const imgs = []
+      for (const i of imageUrls) {
+        imgs.push(i.originalUrl)
+      }
       this.$viewerApi({
         images: imgs,
         options: {

+ 19 - 26
src/views/mblog/mblog.vue

@@ -192,7 +192,7 @@ const FilePond = VueFilePond(
   FilePondPluginImagePreview,
   FilePondPluginFileValidateSize
 )
-var resp = ''
+var imgFileIds = []
 
 export default {
   name: 'Home',
@@ -203,7 +203,6 @@ export default {
   },
   data() {
     return {
-      imgMap: {},
       server: {
         url: '//file.reghao.cn/api/file/upload/image',
         revert: null,
@@ -215,12 +214,22 @@ export default {
             return formData
           },
           onload(response) {
-            resp = JSON.parse(response)
+            const resp = JSON.parse(response)
+            if (resp.code === 0) {
+              imgFileIds.push(resp.data.imageUploadId)
+            } else {
+              if (resp.msg != null) {
+                this.message = '上传文件出现异常,请重新上传!' + resp.msg
+              } else {
+                this.message = '上传文件出现异常,请重新上传!'
+              }
+              this.showMessage = true
+            }
           }
         }
       },
       statusPost: {
-        imageUrls: [],
+        imageFileIds: [],
         content: '',
         location: ''
       },
@@ -277,24 +286,7 @@ export default {
     },
     success(error, metadata) {
       if (error === null) {
-        if (resp.code === 0) {
-          const file = metadata.file
-          const filename = file.name
-          this.imgMap[filename] = resp.data.uploadId
-
-          const imageUrl = {}
-          imageUrl.imageFileId = resp.data.imageFileId
-          imageUrl.thumbnailUrl = resp.data.thumbnailUrl
-          imageUrl.originalUrl = resp.data.originalUrl
-          this.statusPost.imageUrls.push(imageUrl)
-        } else {
-          if (resp.msg != null) {
-            this.message = '上传文件出现异常,请重新上传!' + resp.msg
-          } else {
-            this.message = '上传文件出现异常,请重新上传!'
-          }
-          this.showMessage = true
-        }
+        return
       }
     },
     removeFile(error, metadata) {
@@ -308,7 +300,7 @@ export default {
           method: 'DELETE'
         }).then(response => response.json())
           .then(json => {
-            console.log('删除 this.statusPost.imageUrls 中相应的图片')
+            console.log('删除 this.statusPost.imageFileIds 中相应的图片')
           })
           .catch(e => {
             return null
@@ -408,19 +400,20 @@ export default {
         this.showMessage = true
         return
       }
+      this.statusPost.imageFileIds = imgFileIds
 
       pubStatus(this.statusPost)
         .then(res => {
           if (res.code === 0) {
-            // TODO 发布成功后应该清除本地文本和图片数据
             this.message = '状态已发布'
             this.showMessage = true
+            this.statusPost.content = ''
+            this.statusPost.imageFileIds = []
           } else {
             this.message = res.msg
             this.showMessage = true
           }
-        })
-        .catch(error => {
+        }).catch(error => {
           this.message = error.message
           this.showMessage = true
         })

+ 6 - 6
src/views/studio/upload.vue

@@ -176,8 +176,8 @@ export default {
       ],
       // 提交给后端的数据
       videoPost: {
-        videoUploadId: null,
-        imageUploadId: null,
+        videoFileId: null,
+        coverFileId: null,
         title: null,
         description: null,
         categoryId: null,
@@ -251,7 +251,7 @@ export default {
         if (resData.merged) {
           this.message = '视频已上传'
           this.showMessage = true
-          this.videoPost.videoUploadId = resData.videoUploadId
+          this.videoPost.videoFileId = resData.videoUploadId
         }
       }
     },
@@ -259,13 +259,13 @@ export default {
       console.log('文件上传错误')
     },
     publish() {
-      if (!this.videoPost.videoUploadId) {
+      if (!this.videoPost.videoFileId) {
         this.message = '你还没有上传视频'
         this.showMessage = true
         return
       }
 
-      if (!this.videoPost.imageUploadId) {
+      if (!this.videoPost.coverFileId) {
         this.message = '你还没有上传视频封面'
         this.showMessage = true
         return
@@ -342,7 +342,7 @@ export default {
           if (json.code === 0) {
             this.message = '封面已上传'
             this.showMessage = true
-            this.videoPost.imageUploadId = json.data.imageUploadId
+            this.videoPost.coverFileId = json.data.imageUploadId
             this.videoPost.imageUrl = json.data.imageUrl
           } else {
             this.message = '上传失败,请重试!' + json.message