Преглед изворни кода

作品附件-调试-修复bug

bruce пре 5 година
родитељ
комит
77b51f7e76
2 измењених фајлова са 33 додато и 17 уклоњено
  1. 15 4
      components/works/editor.vue
  2. 18 13
      mixins/oos.js

+ 15 - 4
components/works/editor.vue

@@ -49,10 +49,10 @@
       </el-upload>
       <div v-if="uploadFileList.length > 0" class="app__mw_40_p">
         <div class="app__f_r app__al_c">
-          <p class="app__fs_15">{{uploadFileList.length > 0 ? uploadFileList[0].name : ""}}</p>
+          <p class="app__fs_15 app__txt_ellipsis">{{uploadFileList.length > 0 ? uploadFileList[0].name : ""}}</p>
           <button class="app__fc_999 app__fs_18 app__ml_20" @click="uploadFileDelete">x</button>
         </div>
-        <el-progress :percentage="uploadPercentage" status="success" :stroke-width="8" class="app__mt_10" />
+        <el-progress :percentage="uploadPercentage" status="success" :stroke-width="8" class="app__mt_10"/>
       </div>
     </div>
 
@@ -118,6 +118,7 @@
       this.getHejiList();
       if (this.$route.query.wid) {
         this.getWorkDetail();
+        this.getWorkFile();
       }
       console.log("url", this.$route.query.wid);
     },
@@ -136,6 +137,16 @@
           });
       },
 
+      getWorkFile() {
+        this.$axios.$post(`/api/UserWorks/getWorkFile`, {wid: this.$route.query.wid}).then(res => {
+          console.log(res);
+          if (res.status === 1) {
+            this.uploadFileList.push({name: res.data.file_name, url: res.data.file_url_abs, path: res.data.file_url});
+            console.log(this.uploadFileList)
+          }
+        });
+      },
+
       setWorkImages(data) {
         let images = data.images;
         if (images && images.length > 0) {
@@ -202,7 +213,7 @@
             }
             if (res.status === 1) {
               this.$message.success("编辑成功!");
-              window.location.href = res.data.work_url;
+              // window.location.href = res.data.work_url;
             } else {
               this.$message.error("编辑提交失败,请重试");
             }
@@ -216,7 +227,7 @@
             }
             if (res.status === 1) {
               this.$message.success("发布成功!");
-              // this.$router.go(-1);
+              this.$router.go(-1);
             }
             this.isPublishing = false;
           });

+ 18 - 13
mixins/oos.js

@@ -10,7 +10,7 @@ export default {
       uploadFileList: [],
       fileUploadCallBackParams: {return_data: {data: {}, status: 0}, upload_id: ""},
       tempCheckpoint: {},
-      uploadPercentage: "0",
+      uploadPercentage: 0,
       oosClient: null,
       isUploading: false
     }
@@ -27,17 +27,21 @@ export default {
       this.prepareUpload(file);
     },
 
+    initUpload(file) {
+      if (this.isUploading) {
+        this.oosClient.cancel();
+      }
+      this.uploadPercentage = 0;
+      this.uploadFileList = [];
+      if (file)
+        this.uploadFileList.push({name: file.name, url: ""});
+    },
+
     uploadFileOnProgress(event, file, fileList) {
 
     },
     uploadFileDelete(file = null) {
-
-      this.uploadFileList = [];
-      console.log(this.uploadFileList);
-      if (this.isUploading) {
-        this.oosClient.cancel();
-        this.uploadPercentage = 0;
-      }
+      this.initUpload();
     },
     /**
      * 上传文件出错
@@ -51,8 +55,9 @@ export default {
      * @param callback
      */
     prepareUpload(file) {
+      //初始化上传状态
+      this.initUpload(file);
       const formData = new FormData();
-      this.uploadFileList.push({name: file.name, url: ""});
       let wid = this.$route.query.wid;
       formData.append("target", `{ "type": 5 ,"work_id":${wid || -1}}`);
       formData.append("filename", file.name);
@@ -86,7 +91,7 @@ export default {
         this.oosClient.put(data.post_params.policy['save-key'], file.raw).then(res => {
           console.log("*******", res);
           if (res.res.status === 200) {
-            this.setUploadComplete(res);
+            this.setUploadComplete(res, file);
           }
         }).catch(err => {
           console.log(err);
@@ -96,7 +101,7 @@ export default {
       }
     },
 
-    async _ossMultipartUpload(data, file) {
+    _ossMultipartUpload(data, file) {
       try {
         this.oosClient = OSS({
           region: "oss-cn-beijing",
@@ -120,7 +125,7 @@ export default {
           mime: file.type,
         }).then(res => {
           console.log("multipartUpload res", res);
-          this.setUploadComplete(res);
+          this.setUploadComplete(res, file);
         }).catch(err => {
           console.log("multipartUpload err", err);
         })
@@ -129,7 +134,7 @@ export default {
       }
     },
 
-    setUploadComplete(res) {
+    setUploadComplete(res, file) {
       this.fileUploadCallBackParams.return_data.status = 1;
       this.fileUploadCallBackParams.return_data.data.url = "https:\/\/filescdn.proginn.com/" + res.name;
       this.fileUploadCallBackParams.return_data.data.path = res.name;