Browse Source

可视化 ‘应用’ 表头指标map错误

TonyKang 6 years ago
parent
commit
6db932779c

+ 20 - 2
modules/reports/rpt_component/helper/jpc_helper_common.js

@@ -1,4 +1,5 @@
 let JV = require('../jpc_value_define');
+let stringUtil = require('../../../../public/stringUtil');
 
 let JpcCommonHelper = {
     commonConstant: {},
@@ -134,7 +135,15 @@ let JpcCommonHelper = {
     },
     getStringLinesInArea: function(area, strVal, pdfDoc) {
         let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 2;
-        let txtWidth = pdfDoc.widthOfString(strVal);
+        // let re = /[\u4E00-\u9FA5]/g;
+        let re = /[^\x00-\xff]/ig; //普通ASCII以外的字符
+        let cStr = strVal.match(re);
+        let chnAmt = (cStr)?cStr.length:0;
+        let chnW = pdfDoc.widthOfString('一'), otherW = pdfDoc.widthOfString('_');
+        //备注: 因后台的pdfDoc判断字符串长度与前端的不一样,需要做些调整,不一次性地判断字符串长度。
+        //      分2种字符:中文与非中文,按照各种字符的数量分别乘以相关一个字符的宽度再累计。
+        // let txtWidth = pdfDoc.widthOfString(strVal);
+        let txtWidth = chnAmt * chnW + (strVal.length - chnAmt) * otherW;
         let rst = parseInt(txtWidth / areaWidth);
         if (txtWidth % areaWidth > 0) {
             rst++;
@@ -145,10 +154,19 @@ let JpcCommonHelper = {
     },
     splitString: function (area, strVal, pdfDoc) {
         let rst = [];
+        // let re = /[\u4E00-\u9FA5]/g;
+        let re = /[^\x00-\xff]/ig; //普通ASCII以外的字符
+        let chnW = pdfDoc.widthOfString('一'), otherW = pdfDoc.widthOfString('_');
         let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 2;
         let preSIdx = 0, txtWidth = 0;
+
         for (let sIdx = 1; sIdx <= strVal.length; sIdx++) {
-            txtWidth = pdfDoc.widthOfString(strVal.substr(preSIdx, sIdx - preSIdx));
+            let tmpStr = strVal.substr(preSIdx, sIdx - preSIdx);
+            let cStr = tmpStr.match(re);
+            let chnAmt = (cStr)?cStr.length:0;
+            // let chnAmt = tmpStr.match(re).length;
+            // txtWidth = pdfDoc.widthOfString(strVal.substr(preSIdx, sIdx - preSIdx));
+            txtWidth = chnAmt * chnW + (tmpStr.length - chnAmt) * otherW;
             if (txtWidth > areaWidth) {
                 rst.push(strVal.substr(preSIdx, sIdx - preSIdx - 1));
                 preSIdx = sIdx - 1;

+ 1 - 0
modules/reports/rpt_component/jpc_flow_tab.js

@@ -324,6 +324,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
                         let value = JpcFieldHelper.getValue(data_field, theRecIdx);
                         let area = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, 1, 1, 0, 1, 0, 1, 0, false, false);
                         if (value !== null && value !== undefined) {
+                            value = value.replace('\t', '');
                             value = value.replace(reg1, '|').replace(reg2, '|').replace(reg3, '|').replace(reg4, '|');
                         } else {
                             value = '';

+ 1 - 0
web/maintain/report/js/rpt_tpl_vis_common.js

@@ -349,6 +349,7 @@ let visualCommonOprObj = {
                         }
                     }
                 }
+                if (isReverse) nodes.reverse();
             };
             if (fieldMapTreeOprObj.treeObj) {
                 private_getNameByTree(fieldMapTreeOprObj.treeObj, true);

+ 37 - 15
web/maintain/report/js/rpt_tpl_vis_jumbo.js

@@ -835,7 +835,7 @@ let visualJumbo = {
         let contentNodes = [];
         for (let field of textFldArr) {
             if (field.isField) {
-                let node = me.private_create_field_param_node(sheet, field, startRow, colWidthArr, rowHeightArr, rptTpl);
+                let node = me.private_create_field_param_node(sheet, field, startRow, colWidthArr, rowHeightArr, null);
                 contentNodes.push(node);
             }
         }
@@ -964,20 +964,42 @@ let visualJumbo = {
                 }
             }
         };
-        if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
-            native_chk_field_param(rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]);
-        }
-        if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS].length > 0) {
-            native_chk_field_param(rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]);
-        }
-        if (!hasChkField && rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
-            native_chk_field_param(rptTpl[JV.NODE_NO_MAPPING_FIELDS]);
-        }
-        if (!hasChkField && rptTpl[JV.NODE_DISCRETE_PARAMS] !== undefined && rptTpl[JV.NODE_DISCRETE_PARAMS].length > 0) {
-            native_chk_field_param(rptTpl[JV.NODE_DISCRETE_PARAMS]);
-            if (hasChkField) {
-                rst.ParamID = rst.FieldID;
-                delete rst.FieldID;
+        if (rptTpl) {
+            if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
+                native_chk_field_param(rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]);
+            }
+            if (!hasChkField && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS].length > 0) {
+                native_chk_field_param(rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]);
+            }
+            if (!hasChkField && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS].length > 0) {
+                native_chk_field_param(rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS]);
+            }
+            if (!hasChkField && rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
+                native_chk_field_param(rptTpl[JV.NODE_NO_MAPPING_FIELDS]);
+            }
+            if (!hasChkField && rptTpl[JV.NODE_DISCRETE_PARAMS] !== undefined && rptTpl[JV.NODE_DISCRETE_PARAMS].length > 0) {
+                native_chk_field_param(rptTpl[JV.NODE_DISCRETE_PARAMS]);
+                if (hasChkField) {
+                    rst.ParamID = rst.FieldID;
+                    delete rst.FieldID;
+                }
+            }
+        } else {
+            let nodes1 = fieldMapTreeOprObj.treeObj.getNodes();
+            for (let node of nodes1) {
+                if (node.items && node.items.length > 0) {
+                    native_chk_field_param(node.items);
+                }
+                if (hasChkField) break;
+            }
+            if (!hasChkField) {
+                let nodes2 = discreteFieldParamTreeOprObj.treeObj.getNodes();
+                for (let node of nodes2) {
+                    if (node.items && node.items.length > 0) {
+                        native_chk_field_param(node.items);
+                    }
+                    if (hasChkField) break;
+                }
             }
         }