Parcourir la source

调整图片输出 + code sync

Tony Kang il y a 2 ans
Parent
commit
b3a06ba781

+ 1 - 59
app/public/report/js/jpc_output.js

@@ -490,64 +490,6 @@ let JpcCanvasOutput = {
                 }
             }
         }
-        function private_getProperSignatureArea(cell, control) {
-            // 约定默认长宽比例是2:1,图片分辨率是600*300
-            const rst = [0, 0, 0, 0]; // left, top, right, bottom
-            if (cell && cell[JV.PROP_AREA]) {
-                if (cell.hasOwnProperty('isOrgShow') && cell.isOrgShow) {
-                    rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
-                    rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
-                    rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
-                    rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
-                } else {
-                    let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
-                        height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP],
-                        centerPh = (cell[JV.PROP_AREA][JV.PROP_RIGHT] + cell[JV.PROP_AREA][JV.PROP_LEFT]) / 2,
-                        centerPv = (cell[JV.PROP_AREA][JV.PROP_BOTTOM] + cell[JV.PROP_AREA][JV.PROP_TOP]) / 2
-                    ;
-                    if (width > height * 2) {
-                        width = height * 2;
-                    } else {
-                        height = width / 2;
-                    }
-                    switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
-                        case 'left':
-                            rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
-                            rst[JV.IDX_RIGHT] = rst[0] + width;
-                            break;
-                        case 'right':
-                            rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
-                            rst[JV.IDX_LEFT] = rst[JV.IDX_RIGHT] - width;
-                            break;
-                        default:
-                            //center
-                            rst[JV.IDX_LEFT] = centerPh - width / 2;
-                            rst[JV.IDX_RIGHT] = centerPh + width / 2;
-                            break;
-                    }
-                    switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
-                        case 'top':
-                            rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
-                            rst[JV.IDX_BOTTOM] = rst[JV.IDX_TOP] + height;
-                            break;
-                        case 'bottom':
-                            rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
-                            rst[JV.IDX_TOP] = rst[JV.IDX_BOTTOM] - height;
-                            break;
-                        default:
-                            //center
-                            rst[JV.IDX_TOP] = centerPv - height / 2;
-                            rst[JV.IDX_BOTTOM] = centerPv + height / 2;
-                            break;
-                    }
-                }
-            }
-            rst[0] = rst[0] + JpcCanvasOutput.offsetX;
-            rst[2] = rst[2] + JpcCanvasOutput.offsetX;
-            rst[1] = rst[1] + JpcCanvasOutput.offsetY;
-            rst[3] = rst[3] + JpcCanvasOutput.offsetY;
-            return rst;
-        }
         function private_drawImage(cell, control, imageData,moveSignatureTool, orgSize = false, offsetArea) {
             // 新增签章数据到移动工具中
             if(moveSignatureTool){
@@ -563,7 +505,7 @@ let JpcCanvasOutput = {
                     cell.signType
                 );
             }  
-            let area = private_getProperSignatureArea(cell, control);
+            let area = getProperSignatureArea(cell, control, JV);
             if (orgSize) {
                 area[0] = cell.area.Left + JpcCanvasOutput.offsetX; // Left
                 area[1] = cell.area.Top + JpcCanvasOutput.offsetY; // Top

+ 1 - 0
app/public/report/js/rpt_preview_common.js

@@ -29,6 +29,7 @@ Date.prototype.Format = function(fmt) {
 
 async function printPageLoading() {
     if (sessionStorage.report_direct_data) {
+        OSS_PATH = sessionStorage.OSS_PATH;
         printPageDirectLoading();
     } else {
         let params = JSON.parse(sessionStorage.report_params);

+ 20 - 16
app/public/report/js/rpt_print.js

@@ -351,20 +351,7 @@ function buildCellSvg(cell, fonts, styles, controls, pageMergeBorder, rptMergeBo
 
 function buildImage(destRst, cell, control, offsetX, offsetY, HtoVStr, orgSize = false, offsetArea) {
     let href = '';
-    if (cell.pic) {
-        href = 'href="' + cell.pic +'"';
-    } else {
-        href = 'xlink:href="' + cell.path +'"';
-    }
     const area = getProperSignatureArea(cell, control, offsetX, offsetY);
-    /*
-    if (cell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
-        area[0] = cell[JV.PROP_AREA][JV.PROP_LEFT] + 1 + offsetX; // Left
-        area[1] = cell[JV.PROP_AREA][JV.PROP_TOP] + 1 + offsetY; // Top
-        area[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT] - 1 + offsetX; // Right
-        area[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - 1 + offsetY; // Bottom
-    }
-    /*/
     if (orgSize) {
         area[0] = cell[JV.PROP_AREA][JV.PROP_LEFT] + offsetX; // Left
         area[1] = cell[JV.PROP_AREA][JV.PROP_TOP] + offsetY; // Top
@@ -377,9 +364,26 @@ function buildImage(destRst, cell, control, offsetX, offsetY, HtoVStr, orgSize =
         area[2] = area[2] - offsetArea[2]; // Right
         area[3] = area[3] - offsetArea[3]; // Bottom
     }
-    //*/
-    destRst.push('<image x="' + area[0] + '" y="' + area[1] + '" width="' + (area[2] - area[0]) + '" height="' + (area[3] - area[1]) + '" ');
-    destRst.push(href + HtoVStr + ' />');
+    if (cell.pic) {
+        href = 'href="' + cell.pic +'"';
+        destRst.push('<image x="' + area[0] + '" y="' + area[1] + '" width="' + (area[2] - area[0]) + '" height="' + (area[3] - area[1]) + '" ');
+        destRst.push(href + HtoVStr + ' />');
+    } else {
+        let paths = cell.path.split('!;!');
+        for (let dtlPath of paths) {
+            if (typeof dtlPath === 'string' && dtlPath.length > 10) {
+                let imgSrc = dtlPath;
+                if (dtlPath.indexOf(OSS_PATH) < 0 && dtlPath[0] !== '/') {
+                    imgSrc = OSS_PATH + dtlPath;
+                } else {
+                    imgSrc = dtlPath;
+                }
+                href = 'xlink:href="' + imgSrc +'"';
+                destRst.push('<image x="' + area[0] + '" y="' + area[1] + '" width="' + (area[2] - area[0]) + '" height="' + (area[3] - area[1]) + '" ');
+                destRst.push(href + HtoVStr + ' />');
+            }
+        }
+    }
 }
 
 function getProperSignatureArea(cell, control, offsetX, offsetY) {

+ 169 - 1
app/public/report/js/rpt_public.js

@@ -1,3 +1,6 @@
+const PUB_STAMP_SIZE_WIDTH = 5 * 96 / 2.54;   // 公章大小:宽度(5 CM)
+const PUB_STAMP_SIZE_HEIGHT = 5 * 96 / 2.54;  // 公章大小:高度(5 CM)
+
 function getScreenDPI() {
     if (SCREEN_DPI.length === 0) {
         if (window.screen.deviceXDPI != undefined) {
@@ -66,4 +69,169 @@ function dynamicLoadJs(url, type, callback) {
         };
         xhr.send();
     });
-}
+}
+
+function getProperSignatureArea(cell, control, JV = null) {
+    // 约定默认长宽比例是2:1,图片分辨率是600*300
+    const rst = [0, 0, 0, 0]; // left, top, right, bottom
+    if (JV) {
+        if (cell && cell[JV.PROP_AREA]) {
+            if (cell.hasOwnProperty('isOrgShow') && cell.isOrgShow) {
+                rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
+                rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
+                rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
+                rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
+            } else {
+                let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
+                    height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP],
+                    centerPh = (cell[JV.PROP_AREA][JV.PROP_RIGHT] + cell[JV.PROP_AREA][JV.PROP_LEFT]) / 2,
+                    centerPv = (cell[JV.PROP_AREA][JV.PROP_BOTTOM] + cell[JV.PROP_AREA][JV.PROP_TOP]) / 2
+                ;
+                if (width > height * 2) {
+                    width = height * 2;
+                } else {
+                    height = width / 2;
+                }
+                switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
+                    case 'left':
+                        rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
+                        rst[JV.IDX_RIGHT] = rst[0] + width;
+                        break;
+                    case 'right':
+                        rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
+                        rst[JV.IDX_LEFT] = rst[JV.IDX_RIGHT] - width;
+                        break;
+                    default:
+                        //center
+                        rst[JV.IDX_LEFT] = centerPh - width / 2;
+                        rst[JV.IDX_RIGHT] = centerPh + width / 2;
+                        break;
+                }
+                switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
+                    case 'top':
+                        rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
+                        rst[JV.IDX_BOTTOM] = rst[JV.IDX_TOP] + height;
+                        break;
+                    case 'bottom':
+                        rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
+                        rst[JV.IDX_TOP] = rst[JV.IDX_BOTTOM] - height;
+                        break;
+                    default:
+                        //center
+                        rst[JV.IDX_TOP] = centerPv - height / 2;
+                        rst[JV.IDX_BOTTOM] = centerPv + height / 2;
+                        break;
+                }
+            }
+        }
+    }
+    rst[0] = rst[0] + JpcCanvasOutput.offsetX;
+    rst[2] = rst[2] + JpcCanvasOutput.offsetX;
+    rst[1] = rst[1] + JpcCanvasOutput.offsetY;
+    rst[3] = rst[3] + JpcCanvasOutput.offsetY;
+    return rst;
+}
+
+function resetStampArea(ctrl, stampCell, JV, stampFeature = 'not found!') {
+    let pLeft = stampCell.orgArea.Left,
+        pTop = stampCell.orgArea.Top;
+    if (stampFeature !== 'not found!') {
+        let std_stamp_size_width = PUB_STAMP_SIZE_WIDTH, std_stamp_size_height = PUB_STAMP_SIZE_HEIGHT;
+        let widthRate = 1, heightRate = 1;
+        if (stampFeature) {
+            std_stamp_size_width = parseFloat(stampFeature.ImageWidth.value);
+            std_stamp_size_height = parseFloat(stampFeature.ImageHeight.value);
+            if (stampFeature.ImageWidth.value !== stampFeature.ImageHeight.value) {
+                //设置比例
+                if (std_stamp_size_width > std_stamp_size_height) {
+                    heightRate = std_stamp_size_height / std_stamp_size_width;
+                } else {
+                    widthRate = std_stamp_size_width / std_stamp_size_height;
+                }
+            }
+            if (std_stamp_size_width > PUB_STAMP_SIZE_WIDTH || std_stamp_size_height > PUB_STAMP_SIZE_HEIGHT) {
+                if (widthRate === 1) {
+                    std_stamp_size_width = Math.min(std_stamp_size_width, PUB_STAMP_SIZE_WIDTH);
+                    std_stamp_size_height = std_stamp_size_width * heightRate;
+                } else {
+                    std_stamp_size_height = Math.min(std_stamp_size_height, PUB_STAMP_SIZE_HEIGHT);
+                    std_stamp_size_width = std_stamp_size_height * widthRate;
+                }
+            }
+        }
+        switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
+            case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
+                pLeft = stampCell.orgArea.Left;
+                break;
+            case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
+                pLeft = (stampCell.orgArea.Left + stampCell.orgArea.Right - std_stamp_size_width) / 2;
+                break;
+            case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
+                pLeft = stampCell.orgArea.Right - std_stamp_size_width;
+                break;
+            default:break;
+        }
+        switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
+            case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
+                pTop = stampCell.orgArea.Top;
+                break;
+            case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
+                pTop = (stampCell.orgArea.Top + stampCell.orgArea.Bottom - std_stamp_size_height) / 2;
+                break;
+            case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
+                pTop = stampCell.orgArea.Bottom - std_stamp_size_height;
+                break;
+            default:break;
+        }
+        stampCell.area.Left = pLeft;
+        stampCell.area.Top = pTop;
+        stampCell.area.Right = pLeft + std_stamp_size_width;
+        stampCell.area.Bottom = pTop + std_stamp_size_height;
+        // 最后一步,如超过报表范围,则要调整坐标
+        const maxRect = stampCell.maxRect;
+        if (stampCell.area.Left < maxRect[0]) {
+            const width = maxRect[0] - stampCell.area.Left;
+            stampCell.area.Left += width;
+            stampCell.area.Right += width;
+        }
+        if (stampCell.area.Top < maxRect[1]) {
+            const height = maxRect[1] - stampCell.area.Top;
+            stampCell.area.Top += height;
+            stampCell.area.Bottom += height;
+        }
+        if (stampCell.area.Right > maxRect[2]) {
+            const width = maxRect[2] - stampCell.area.Right; // 负
+            stampCell.area.Left += width;
+            stampCell.area.Right += width;
+        }
+        if (stampCell.area.Bottom > maxRect[3]) {
+            const height = maxRect[3] - stampCell.area.Bottom;
+            stampCell.area.Top += height;
+            stampCell.area.Bottom += height;
+        }
+    }
+}
+
+async function getPicFeature(picPath) {
+    const rst = await getHttpBlobText(picPath + '?x-oss-process=image/info');
+    return rst;
+}
+
+function getHttpBlobText(url) {
+    return new Promise(resolve => {
+        const xhr = new XMLHttpRequest();
+
+        // let fullUrl = url + '?x-oss-process=image/info';
+        xhr.open('GET', url, true);
+        xhr.responseType = 'json';
+        xhr.onload = () => {
+            if (xhr.status === 200) {
+                resolve(xhr.response);
+            } else {
+                resolve('not found!');
+            }
+        };
+
+        xhr.send();
+    });
+}

+ 0 - 19
app/public/report/js/rpt_signature.js

@@ -1256,23 +1256,4 @@ function _resetStampArea(ctrl, stampCell, roleRelItem) {
     }
 }
 
-function getHttpBlobText(url) {
-    return new Promise(resolve => {
-        const xhr = new XMLHttpRequest();
-
-        // let fullUrl = url + '?x-oss-process=image/info';
-        xhr.open('GET', url, true);
-        xhr.responseType = 'json';
-        xhr.onload = () => {
-            if (xhr.status === 200) {
-                resolve(xhr.response);
-            } else {
-                resolve('not found!');
-            }
-        };
-
-        xhr.send();
-    });
-}
-
 

+ 17 - 2
app/view/payment/detail.ejs

@@ -155,6 +155,20 @@
     let auditRptPrintHelper = {
         currentPageData: null,
         currentDownloadIdx: 0,
+        resetPicArea: async function(pageData) {
+                // const picFeature = await getPicFeature(imgSrc);
+                // resetStampArea(control, cell, JV, picFeature);
+                // area[0] = cell[JV.PROP_AREA][JV.PROP_LEFT] + offsetX; // Left
+                // area[1] = cell[JV.PROP_AREA][JV.PROP_TOP] + offsetY; // Top
+                // area[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT] + offsetX; // Right
+                // area[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM] + offsetY; // Bottom
+            for (let page of pageData.items) {
+                for (let signCell of page.signature_cells) {
+                    //
+                }
+            }
+        },
+
         showPage: function() {
             JpcCanvasOutput.cleanCanvas(VIEW_CANVAS);
             JpcCanvasOutput.drawPageBorder(tesRpttData, VIEW_CANVAS, getScreenDPI());
@@ -164,6 +178,7 @@
             sessionStorage.report_direct_data = JSON.stringify(tesRpttData);
             sessionStorage.closeWaterMark = 1;
             sessionStorage.pageSize = 'A4';
+            sessionStorage.OSS_PATH = OSS_PATH;
             window.open('/printReport/A4');
         },
         
@@ -174,13 +189,13 @@
             }
             if (rptTplObj.pdfFont['SmartSimsun'].length >= 2) {
                 $.bootstrapLoading.end();
-                downloadPDFReport([tesRpttData], 'A4', ['测试审核表'], [], [], [-1], []);
+                downloadPDFReport([tesRpttData], 'A4', [tesRpttData['打印页面_信息']['报表名称']], [], [], [-1], []);
             }
         },
 
         directPDF: function() {
             if (rptTplObj.pdfFont['SmartSimsun'].length >= 2) {
-                downloadPDFReport([tesRpttData], 'A4', ['测试审核表'], [], [], [-1], []);
+                downloadPDFReport([tesRpttData], 'A4', [tesRpttData['打印页面_信息']['报表名称']], [], [], [-1], []);
             } else {
                 dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal2.js', 'normal', this._getPdfFontCallback);
                 dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', this._getPdfFontCallback);