Ver código fonte

【我的素材-全景图片】提高上传素材相关代码可读性

任一存 4 anos atrás
pai
commit
f0a3d84bfa
1 arquivos alterados com 15 adições e 9 exclusões
  1. 15 9
      src/views/material/pano/index.vue

+ 15 - 9
src/views/material/pano/index.vue

@@ -178,7 +178,7 @@ import {
 // 1切图,2失败,3成功
 // 1切图,2失败,3成功
 
 
 const TYPE = "pano";
 const TYPE = "pano";
-const LONGPOLLINGTIME = 10;
+const LONG_POLLING_INTERVAL = 10;
 
 
 export default {
 export default {
   name: 'Pano',
   name: 'Pano',
@@ -195,7 +195,7 @@ export default {
   data() {
   data() {
     return {
     return {
       config,
       config,
-      isLongPolling: false, // TODO?
+      longPollingSwitch: false,
       showRename: false,
       showRename: false,
       showPreview: false,
       showPreview: false,
       showCover: false,
       showCover: false,
@@ -223,13 +223,13 @@ export default {
   mounted() {
   mounted() {
   },
   },
   watch: {
   watch: {
-    isLongPolling: {
+    longPollingSwitch: {
       handler: function (newVal) {
       handler: function (newVal) {
         if (!newVal) {
         if (!newVal) {
           this.getMaterialList(true);
           this.getMaterialList(true);
           this.clearinter();
           this.clearinter();
         } else {
         } else {
-          this.Longpolling();
+          this.beginLongPolling();
         }
         }
       },
       },
     },
     },
@@ -251,11 +251,11 @@ export default {
       this.interval && clearInterval(this.interval);
       this.interval && clearInterval(this.interval);
       this.interval = null;
       this.interval = null;
     },
     },
-    Longpolling() {
+    beginLongPolling() {
       this.clearinter();
       this.clearinter();
       this.interval = setInterval(() => {
       this.interval = setInterval(() => {
         this._checkMStatus(true);
         this._checkMStatus(true);
-      }, LONGPOLLINGTIME * 1000);
+      }, LONG_POLLING_INTERVAL * 1000);
     },
     },
     handleRename(newName) {
     handleRename(newName) {
       editMaterial(
       editMaterial(
@@ -361,7 +361,7 @@ export default {
               this.getMaterialList(true)
               this.getMaterialList(true)
             }
             }
             if (!tmp.some((item) => item.status == 1)) {
             if (!tmp.some((item) => item.status == 1)) {
-              this.isLongPolling = false;
+              this.longPollingSwitch = false;
             }
             }
           }
           }
         );
         );
@@ -449,7 +449,7 @@ export default {
         });
         });
       })
       })
 
 
-
+      // 检查宽高比的任务队列
       let p = [];
       let p = [];
       canUploadList.forEach((i) => {
       canUploadList.forEach((i) => {
         let promise = getImgWH(i);
         let promise = getImgWH(i);
@@ -457,9 +457,11 @@ export default {
       });
       });
 
 
       Promise.all(p).then((result) => {
       Promise.all(p).then((result) => {
+        // 上传任务队列
         let pp = [];
         let pp = [];
         p.length > 0 &&
         p.length > 0 &&
           result.forEach((data) => {
           result.forEach((data) => {
+            // 剔除图像宽高比不符合要求的那些上传任务
             let { width, height } = data.WH;
             let { width, height } = data.WH;
             if (width != 2 * height) {
             if (width != 2 * height) {
               let idx = this.uploadList.findIndex(
               let idx = this.uploadList.findIndex(
@@ -471,6 +473,8 @@ export default {
                 type: 'error'
                 type: 'error'
               });
               });
             }
             }
+
+            // 上传
             let params = {};
             let params = {};
             params["file"] = data.file;
             params["file"] = data.file;
             let promise = new Promise((resolve, reject) => {
             let promise = new Promise((resolve, reject) => {
@@ -490,6 +494,8 @@ export default {
             });
             });
             pp.push(promise);
             pp.push(promise);
           });
           });
+
+        // 所有上传任务结束后,改变this.uploadList里各任务状态,并把返回的任务结果添上去,并开始long polling
         pp.length > 0 &&
         pp.length > 0 &&
           Promise.all(pp).then((response) => {
           Promise.all(pp).then((response) => {
             if (response.length > 0) {
             if (response.length > 0) {
@@ -504,7 +510,7 @@ export default {
                       ...this.uploadList[idx],
                       ...this.uploadList[idx],
                       ...item.data,
                       ...item.data,
                     };
                     };
-                    this.isLongPolling = true;
+                    this.longPollingSwitch = true;
                   }
                   }
                 }
                 }
               });
               });