Browse Source

归档优化增强

TonyKang 3 years ago
parent
commit
141000456c
2 changed files with 44 additions and 56 deletions
  1. 40 30
      app/public/report/js/rpt_archive.js
  2. 4 26
      app/public/report/js/rpt_main.js

+ 40 - 30
app/public/report/js/rpt_archive.js

@@ -467,7 +467,7 @@ let rptArchiveObj = {
         return psInfo;
     },
     archiveCurrentReport: function (currentRptPageRst, currentNode) {
-        let picKeys = [], picCells = [];
+        let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
         // 1. 找草图路径
         for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
             // 每页
@@ -477,8 +477,19 @@ let rptArchiveObj = {
                 if (sCell.signature_name === 'dummy_pic') {
                     //1. 草图就不考虑重复问题,重复就重复吧;
                     //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
-                    picKeys.push(sCell.path);
-                    picCells.push(sCell);
+                    let picIdx = picKeys.indexOf(sCell.path);
+                    if (picIdx < 0) {
+                        picKeys.push(sCell.path);
+                        picCells.push(sCell);
+                    } else {
+                        let dPicIdx = dupPicPath.indexOf(sCell.path);
+                        if (dPicIdx < 0) {
+                            dupPicPath.push(sCell.path);
+                            dupPicCell.push([]);
+                            dPicIdx = dupPicPath.length - 1;
+                        }
+                        dupPicCell[dPicIdx].push(sCell);
+                    }
                 }
             }
         }
@@ -486,39 +497,36 @@ let rptArchiveObj = {
         if (picCells.length > 0) {
             $.bootstrapLoading.start();
             let picAmt = picCells.length, picCnt = 0;
+            let exceptionAmt = 0;
             for (let idx = 0; idx < picCells.length; idx++) {
+                let dCell = picKeys[idx];
                 getBlob(picKeys[idx]).then(blob => {
-                    // saveAs(blob, filename);
-                    let oFileReader = new FileReader();
-                    oFileReader.onloadend = function (e) {
-                        picCnt++;
-                        let base64 = e.target.result;
-                        // console.log("方式一》》》》》》》》》", base64)
-                        picCells[idx].pic = base64;
-                        if (picCnt === picAmt) {
+                    if (blob === 'not found!') {
+                        exceptionAmt++;
+                        if ((picCnt + exceptionAmt) === picAmt) {
                             $.bootstrapLoading.end();
                             rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
                         }
-                    };
-                    oFileReader.readAsDataURL(blob);
+                    } else {
+                        let oFileReader = new FileReader();
+                        oFileReader.onloadend = function (e) {
+                            picCnt++;
+                            let base64 = e.target.result;
+                            picCells[idx].pic = base64;
+                            let pPathIdx = dupPicPath.indexOf(dCell.path);
+                            if (pPathIdx >= 0) {
+                                for (let dupCell of dupPicCell[pPathIdx]) {
+                                    dupCell.pic = base64;
+                                }
+                            }
+                            if ((picCnt + exceptionAmt) === picAmt) {
+                                $.bootstrapLoading.end();
+                                rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
+                            }
+                        };
+                        oFileReader.readAsDataURL(blob);
+                    }
                 });
-
-                // const img = new Image();
-                // img.src = picKeys[idx];
-                // img.onload = function() {
-                //     picCnt++;
-                //     if (picCnt === picAmt) {
-                //         $.bootstrapLoading.end();
-                //         rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
-                //     }
-                // };
-                // img.onerror = function() {
-                //     picCnt++;
-                //     if (picCnt === picAmt) {
-                //         $.bootstrapLoading.end();
-                //         rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
-                //     }
-                // }
             }
         } else {
             rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
@@ -649,6 +657,8 @@ function getBlob(url) {
         xhr.onload = () => {
             if (xhr.status === 200) {
                 resolve(xhr.response);
+            } else {
+                resolve('not found!');
             }
         };
 

+ 4 - 26
app/public/report/js/rpt_main.js

@@ -1000,15 +1000,15 @@ function downloadPDFReport(pageDataArr, pageSize, rpt_names, signatureRelArr, si
     /*/
 
     // 导出PDF真实优化代码
-    let pidPaths = [], dummyPicAmt = 0, dummyCells = [], dupPicPath = [], dupPicCell = [];
+    let picPaths = [], dummyPicAmt = 0, dummyCells = [], dupPicPath = [], dupPicCell = [];
     // 1. 先找有没有dummy
     for (let pageData of pageDataArr) {
         for (let page of pageData.items) {
             for (let dCell of page.signature_cells) {
                 if (dCell.signature_name === 'dummy_pic') {
-                    let picIdx = pidPaths.indexOf(dCell.path);
+                    let picIdx = picPaths.indexOf(dCell.path);
                     if (picIdx < 0) {
-                        pidPaths.push(dCell.path);
+                        picPaths.push(dCell.path);
                         dummyCells.push(dCell);
                         dummyPicAmt++;
                     } else {
@@ -1030,15 +1030,9 @@ function downloadPDFReport(pageDataArr, pageSize, rpt_names, signatureRelArr, si
         let handledAmt = 0, exceptionAmt = 0;
         for (let pIdx = 0; pIdx < dummyCells.length; pIdx++) {
             let dCell = dummyCells[pIdx];
-            _getBlob(dCell.path).then(blob => {
-                // console.log(`pIdx: ${pIdx}`);
+            getBlob(dCell.path).then(blob => {
                 if (blob === 'not found!') {
                     exceptionAmt++;
-                    // console.log(`已出错草图: ${exceptionAmt}`);
-                    // let pPathIdx = dupPicPath.indexOf(dCell.path);
-                    // if (pPathIdx >= 0) {
-                    //     console.log(`dupPicCell[pPathIdx].length: ${dupPicCell[pPathIdx].length}`);
-                    // }
                     if ((handledAmt + exceptionAmt) === dummyPicAmt) {
                         $.bootstrapLoading.end();
                         private_download(pageDataArr, rpt_names);
@@ -1137,19 +1131,3 @@ function getExcelOutputOption() {
         return 'normal'; // 目前是普通方式
     }
 }
-
-function _getBlob(url) {
-    return new Promise((resolve, reject) => {
-        const xhr = new XMLHttpRequest();
-        xhr.open('GET', url, true);
-        xhr.responseType = 'blob';
-        xhr.onload = () => {
-            if (xhr.status === 200) {
-                resolve(xhr.response);
-            } else {
-                resolve('not found!');
-            }
-        };
-        xhr.send();
-    });
-}