Pārlūkot izejas kodu

表格也优化加载

cxmo 7 mēneši atpakaļ
vecāks
revīzija
6e622061ff
1 mainītis faili ar 40 papildinājumiem un 23 dzēšanām
  1. 40 23
      src/views/ppt_manage/mixins/pptMixins.js

+ 40 - 23
src/views/ppt_manage/mixins/pptMixins.js

@@ -25,6 +25,13 @@ import FormatNine from '../newVersion/components/formatPage/FormatNine.vue';
 import FormatTen from '../newVersion/components/formatPage/FormatTen.vue';
 import FormatEle from '../newVersion/components/formatPage/FormatEle.vue';
 import FormatTwelve from '../newVersion/components/formatPage/FormatTwelve.vue';
+const chunkArray = (array, chunkSize)=>{
+    let result = [];
+    for (let i = 0; i < array.length; i += chunkSize) {
+        result.push(array.slice(i, i + chunkSize));
+    }
+    return result;
+}
 export default {
   components:{ FormatOne,FormatTwo,FormatThree,
     FormatFour,FormatFive,FormatSix,FormatSeven,FormatEight,FormatNine,FormatTen,FormatEle,FormatTwelve},
@@ -499,7 +506,7 @@ export default {
     async listHandle(chartElements,fromType='') {
         let needGetDataArr = []
         for(let i=0;i<chartElements.length;i++) {
-            if(!this.optionMap[chartElements[i].chartId]){
+            if(!this.optionMap[chartElements[i].chartId]&&!needGetDataArr.includes(chartElements[i].chartId)){
                 /* needGetDataArr.push(new Promise((res,rej)=>{
                     res(this.getchartData(chartElements[i].chartId))
                 })) */
@@ -508,29 +515,26 @@ export default {
         }
         if(needGetDataArr.length){
             //由于存在加载过程中会切换PPT/页面的情况,不能一股脑加载
-            const chunkArray = (array, chunkSize)=>{
-                let result = [];
-                for (let i = 0; i < array.length; i += chunkSize) {
-                result.push(array.slice(i, i + chunkSize));
-                }
-                return result;
-            }
             //将需要加载的数据分组
             const chunkedArray = chunkArray(needGetDataArr, 6);
+
             for(let i=0;i<chunkedArray.length;i++){
-                if(!chunkedArray[i].length) continue
-                if(this.interruptLoad) return
+                if(!chunkedArray[i].length) continue //如果组内无数据,跳过
+                if(this.interruptLoad) return //若需要中断加载,返回
+
                 const promisesList = chunkedArray[i].map(chartId=>{
                     return new Promise((res,rej)=>{
                         res(this.getchartData(chartId))
                     })
                 })
+
                 await Promise.all(promisesList).then(()=>{}).catch((e)=>{
                     console.log('catch',e)
                 })
-                console.log(`第${i}组加载完成`)
+                console.log(`第${i}组chart加载完成`)
             }
-            console.log('全部加载完成')
+            console.log('全部chart加载完成')
+
             if(fromType==='present'){
                 for(let i=0;i<chartElements.length;i++) {
                     let temp = getChartInfo(this.optionMap[chartElements[i].chartId])
@@ -542,19 +546,32 @@ export default {
     async sheetListHandle(sheetElements){
       let needGetDataArr = []
       for(let i=0;i<sheetElements.length;i++){
-        if(!this.sheetDataMap[sheetElements[i].sheetId]){
-            needGetDataArr.push(new Promise((res,rej)=>{
-                res(this.getsheetData(sheetElements[i].sheetId))
-            }))
+        if(!this.sheetDataMap[sheetElements[i].sheetId]&&!needGetDataArr.includes(sheetElements[i].sheetId)){
+            needGetDataArr.push(sheetElements[i].sheetId)
         }
-        /* await this.getsheetData(sheetElements[i].sheetId) */
       }
-      if(needGetDataArr.length)
-        await Promise.all(needGetDataArr).then(()=>{
-            //console.log('promise all then sheet')
-        }).catch((e)=>{
-            console.log('catch',e)
-        })
+      if(needGetDataArr.length){
+        //由于存在加载过程中会切换PPT/页面的情况,不能一股脑加载
+        //将需要加载的数据分组
+            const chunkedArray = chunkArray(needGetDataArr, 6);
+            for(let i=0;i<chunkedArray.length;i++){
+                if(!chunkedArray[i].length) continue //如果组内无数据,跳过
+                if(this.interruptLoad) return //若需要中断加载,返回
+
+                const promisesList = chunkedArray[i].map(sheetId=>{
+                    return new Promise((res,rej)=>{
+                        res(this.getsheetData(sheetId))
+                    })
+                })
+
+                await Promise.all(promisesList).then(()=>{}).catch((e)=>{
+                    console.log('catch',e)
+                })
+                console.log(`第${i}组sheet加载完成`)
+            }
+            console.log('全部sheet加载完成')
+      }
+      
     },
     async getsheetData(id){
       const res = await sheetInterface.getSheetData({