Explorar el Código

TASK #5043 测试调整(PDF)

Tony Kang hace 5 meses
padre
commit
92e7b58490

+ 22 - 16
app/controller/report_controller.js

@@ -1721,27 +1721,33 @@ function fillWaterMark(pageRstArray) {
 
 async function encodeSignatureDataUri(roleRel, baseDir) {
     if (roleRel) {
+        const _setImage = async role => {
+            if (role.sign_path !== '') {
+                const filePath = baseDir + '/app' + role.sign_path;
+                try {
+                    const res = await isFileExisted(filePath);
+                    if (res) {
+                        const bData = fs.readFileSync(filePath);
+                        const base64Str = bData.toString('base64');
+                        const datauri = 'data:image/png;base64,' + base64Str;
+                        role.sign_pic = datauri;
+                    } else {
+                        console.log('文件不存在:' + filePath);
+                    }
+                } catch (err) {
+                    console.error(err);
+                }
+            }
+        };
         for (const singleRoleRel of roleRel) {
             if (singleRoleRel.rel_content !== null && singleRoleRel.rel_content !== undefined && singleRoleRel.rel_content !== '') {
                 const roleRelContent = JSON.parse(singleRoleRel.rel_content);
                 for (const role of roleRelContent) {
-                    // console.log(role);
-                    if (role.sign_path !== '') {
-                        const filePath = baseDir + '/app' + role.sign_path;
-                        try {
-                            const res = await isFileExisted(filePath);
-                            if (res) {
-                                const bData = fs.readFileSync(filePath);
-                                const base64Str = bData.toString('base64');
-                                const datauri = 'data:image/png;base64,' + base64Str;
-                                role.sign_pic = datauri;
-                            } else {
-                                console.log('文件不存在:' + filePath);
-                            }
-                        } catch (err) {
-                            console.error(err);
+                    if (role.type === '流程') {
+                        for (const flowRole of role.assFlowInfos) {
+                            await _setImage(flowRole);
                         }
-                    }
+                    } else await _setImage(role);
                 }
                 singleRoleRel.rel_content = JSON.stringify(roleRelContent);
             } else {

+ 20 - 11
app/public/report/js/rpt_jspdf.js

@@ -89,7 +89,7 @@ const JpcJsPDFHelper = {
         }
         // let signatureCounter = {"allAmt": 0, "picAmt": 0};
         if (pageObj && pageObj.items.length > 0 ) {
-            for(let i = 0; i < pageObj.items.length; i++) {
+            for (let i = 0; i < pageObj.items.length; i++) {
                 if (i > 0) {
                     doc.addPage(actPageSize.toLowerCase(), orientation);
                 }
@@ -129,9 +129,9 @@ const JpcJsPDFHelper = {
                 // let ppStatus = zTreeOprObj._chkPrePayStatus();
                 for (let cell of page.signature_cells) {
                     if (auditStatus === 3) {
-                        private_drawSignature(doc, ctx, cell, styles, controls, newPageMergeBand, false, signatureRelArr);
+                        private_drawSignature(doc, ctx, cell, styles, controls, newPageMergeBand, false, signatureRelArr, i);
                     } else {
-                        private_drawSignature(doc, ctx, cell, styles, controls, newPageMergeBand, true, signatureRelArr);
+                        private_drawSignature(doc, ctx, cell, styles, controls, newPageMergeBand, true, signatureRelArr, i);
                     }
                 }
                 if (PAGE_SHOW['closeWatermark'] === 0) {
@@ -164,7 +164,7 @@ const JpcJsPDFHelper = {
             private_drawImage(doc, ctx, cell, control, cell.pic, (!!cell.isStamp), [1, 1, 1, 1]);
         }
 
-        function private_drawSignature(doc, ctx, cell, styles, controls, mergedBand, onlyShowBorder, signatureRelArr) {
+        function private_drawSignature(doc, ctx, cell, styles, controls, mergedBand, onlyShowBorder, signatureRelArr, pageIdx) {
             ctx.beginPath();
             let style = styles[cell[JV.PROP_STYLE]];
              // 印章的cell表框都要去掉
@@ -179,18 +179,18 @@ const JpcJsPDFHelper = {
             ctx.closePath();
             if (PAGE_SHOW.isTextSignature === 0 || cell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
                 if (!onlyShowBorder || cell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
-                    private_drawSignatureCellText(doc, ctx, cell, controls, signatureRelArr);
+                    private_drawSignatureCellText(doc, ctx, cell, controls, signatureRelArr, pageIdx);
                 } else {
                     for (const signRel of signatureRelArr) {
                         if (cell.signature_name === signRel.signature_name && rptSignatureHelper._chkIfAudit(signRel)) {
-                            private_drawSignatureCellText(doc, ctx, cell, controls, signatureRelArr);
+                            private_drawSignatureCellText(doc, ctx, cell, controls, signatureRelArr, pageIdx);
                         }
                     }
                 }
             }
         }
 
-        function private_drawSignatureCellText(doc, ctx, cell, controls, signatureRelArr) {
+        function private_drawSignatureCellText(doc, ctx, cell, controls, signatureRelArr, pageIdx) {
             let control = null;
             if (typeof cell[JV.PROP_CONTROL] === "string") {
                 control = controls[cell[JV.PROP_CONTROL]];
@@ -207,11 +207,20 @@ const JpcJsPDFHelper = {
             } else {
                 // 导出PDF时,根本不需要判断cell.path是不是null or undefined
                 for (const signRel of signatureRelArr) {
-                    if (cell.signature_name === signRel.signature_name && signRel.sign_pic !== null && signRel.sign_pic !== undefined) {
-                        if (!(signRel.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) < 0 && signRel.sign_output.indexOf('normal_sign') < 0)) {
-                            private_drawImage(doc, ctx, cell, control, signRel.sign_pic);
+                    if (cell.signature_name === signRel.signature_name) {
+                        if (signRel.type === '流程') {
+                            if (signRel.flowAccList[pageIdx] >= 0 && signRel.assFlowInfos[signRel.flowAccList[pageIdx]].sign_pic) {
+                                private_drawImage(doc, ctx, cell, control, signRel.assFlowInfos[signRel.flowAccList[pageIdx]].sign_pic);
+                                break;
+                            }
+                        } else {
+                            if (signRel.sign_pic !== null && signRel.sign_pic !== undefined) {
+                                if (!(signRel.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) < 0 && signRel.sign_output.indexOf('normal_sign') < 0)) {
+                                    private_drawImage(doc, ctx, cell, control, signRel.sign_pic);
+                                }
+                                break;
+                            }
                         }
-                        break;
                     }
                 }
             }

+ 10 - 7
app/public/report/js/rpt_main.js

@@ -1114,13 +1114,16 @@ let rptControlObj = {
         //这里尝试下异步加载字体文件
         let me = rptControlObj;
         me.isLoading = true;
-        // dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js', 'normal', me.getPdfFontCallbackLight);
-        // dynamicLoadJs('/public/jspdf/SmartSimsun-normal2.js', 'normal', me.getPdfFontCallbackLight);
-        // dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js', 'bold', me.getPdfFontCallbackLight);
-
-        // dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', me.getPdfFontCallbackLight);
-        dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal2.js', 'normal', me.getPdfFontCallbackLight);
-        dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', me.getPdfFontCallbackLight);
+        const urlStr = window.location.href;
+        if (urlStr.includes('localhost') || urlStr.includes('jlqa')) {
+            // dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js', 'normal', me.getPdfFontCallbackLight);
+            dynamicLoadJs('/public/jspdf/SmartSimsun-normal2.js', 'normal', me.getPdfFontCallbackLight);
+            dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js', 'bold', me.getPdfFontCallbackLight);
+        } else {
+            // dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', me.getPdfFontCallbackLight);
+            dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal2.js', 'normal', me.getPdfFontCallbackLight);
+            dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', me.getPdfFontCallbackLight);
+        }
     },
     getPDFPre: function () {
         let me = rptControlObj;