Browse Source

code sync / 自动行高属性处理

TonyKang 7 years ago
parent
commit
30cd09ee46

+ 16 - 0
modules/reports/rpt_component/helper/jpc_helper_common.js

@@ -166,6 +166,22 @@ let JpcCommonHelper = {
         if (rst === 0) rst = 1; //即使是空字符串,也得有一行啊
         return rst;
         //备注: 其实是想用canvas的,但node canvas装起来麻烦,暂时用PDF Kit来顶用一下,以后换新方法再用
+    },
+    splitString: function (area, strVal, pdfDoc) {
+        let rst = [];
+        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));
+            if (txtWidth > areaWidth) {
+                rst.push(strVal.substr(preSIdx, sIdx - preSIdx - 1));
+                preSIdx = sIdx - 1;
+            }
+            if (sIdx === strVal.length) {
+                rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
+            }
+        }
+        return rst;
     }
 };
 

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

@@ -311,8 +311,27 @@ JpcFlowTabSrv.prototype.createNew = function(){
                             doc.font(__dirname.slice(0, __dirname.length - 14) + '/util/pdf_base_files/Smart.ttf');
                             doc.fontSize(12);
                         }
+                        let hasSplitStr = false, splitStrArr = [];
                         for (let i = 0; i < values.length; i++) {
-                            rst = rst + JpcCommonHelper.getStringLinesInArea(area, values[i], doc) - 1;
+                            let amt = JpcCommonHelper.getStringLinesInArea(area, values[i], doc) - 1;
+                            rst += amt;
+                            if (amt > 0) {
+                                hasSplitStr = true;
+                                splitStrArr.push(i);
+                            }
+                        }
+                        if (hasSplitStr) {
+                            let newValArr = [];
+                            for (let i = 0; i < values.length; i++) {
+                                if (splitStrArr.indexOf(i) < 0) {
+                                    newValArr.push(values[i]);
+                                } else {
+                                    newValArr = newValArr.concat(JpcCommonHelper.splitString(area, values[i], doc));
+                                }
+                            }
+                            JpcFieldHelper.setValue(data_field, theRecIdx, newValArr.join('|'));
+                            splitStrArr = [];
+                            newValArr = [];
                         }
                     }
                 }

+ 11 - 0
web/maintain/report/js/rpt_tpl_cfg_helper.js

@@ -94,6 +94,12 @@ let rpt_tpl_cfg_helper = {
             } else {
                 $("#element_pre_suff")[0].style.display = "none";
             }
+            //setup auto height
+            if (treeNode[JV.PROP_IS_AUTO_HEIGHT]) {
+                $("#eleAutoHeight").get(0).checked = true;
+            } else {
+                $("#eleAutoHeight").get(0).checked = false;
+            }
             //setup font
             let fontDom = $("#elementFonts").get(0);
             fontDom.removeAttribute("disabled");
@@ -300,5 +306,10 @@ let rpt_tpl_cfg_helper = {
         if (dataInfoMapTreeOprObj.currentNode) {
             dataInfoMapTreeOprObj.currentNode[JV.PROP_FORMAT] = dom.value;
         }
+    },
+    changeAutoHeight: function(dom) {
+        if (dataInfoMapTreeOprObj.currentNode) {
+            dataInfoMapTreeOprObj.currentNode[JV.PROP_IS_AUTO_HEIGHT] = dom.checked;
+        }
     }
 };

+ 2 - 18
web/maintain/report/js/rpt_tpl_data_map.js

@@ -236,6 +236,8 @@ let dataInfoMapTreeOprObj = {
         destination[JV.PROP_PREFIX] = source[JV.PROP_PREFIX];
         destination[JV.PROP_SUFFIX] = source[JV.PROP_SUFFIX];
         if (source[JV.PROP_FORMAT]) destination[JV.PROP_FORMAT] = source[JV.PROP_FORMAT];
+        if (source[JV.PROP_IS_AUTO_HEIGHT]) destination[JV.PROP_IS_AUTO_HEIGHT] = true
+        else destination[JV.PROP_IS_AUTO_HEIGHT] = false;
         destination[JV.PROP_AREA] = {};
         me.private_copy_area(source[JV.PROP_AREA], destination[JV.PROP_AREA]);
     },
@@ -529,24 +531,6 @@ let dataInfoMapTreeOprObj = {
                     rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_COLUMN] = newColumn;
                 } else if (node[JV.PROP_NAME] === JV.NODE_FLOW_SEG_SUM) {
                     let newSegSum = me.private_extract_sum_info(node);
-                    // newSegSum[JV.PROP_BAND_NAME] = node[JV.PROP_BAND_NAME];
-                    // newSegSum[JV.PROP_SUM_FIELDS] = [];
-                    // newSegSum[JV.PROP_TEXTS] = [];
-                    // for (let subNode of node.items) {
-                    //     if (subNode[JV.PROP_NAME] === "统计指标集") {
-                    //         for (let sumField of subNode.items) {
-                    //             let item = {};
-                    //             newSegSum[JV.PROP_SUM_FIELDS].push(item);
-                    //             me.private_copy_field_properties(sumField, item);
-                    //         }
-                    //     } else if (subNode[JV.PROP_NAME] === "文本集") {
-                    //         for (let txt of subNode.items) {
-                    //             let item = {};
-                    //             newSegSum[JV.PROP_TEXTS].push(item);
-                    //             me.private_copy_text_properties(txt, item);
-                    //         }
-                    //     }
-                    // }
                     rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM] = newSegSum;
                 } else if (node[JV.PROP_NAME] === JV.NODE_FLOW_PAGE_SUM) {
                     let newSegSum = me.private_extract_sum_info(node);

+ 9 - 0
web/maintain/report/rpt_tpl_detail_field_location.html

@@ -154,6 +154,15 @@
                     <div class="input-group-addon">格式</div>
                     <input class="form-control" id="eleFormat" value="" onkeyup="rpt_tpl_cfg_helper.changeFormat(this)">
                 </div>
+                <div class="input-group col-3">
+                    <label></label>
+                    <div class="form-check">
+                        <label class="form-check-label">
+                            <input type="checkbox" class="form-check-input" id="eleAutoHeight" onchange="rpt_tpl_cfg_helper.changeAutoHeight(this)">
+                            自动行高调整
+                        </label>&nbsp&nbsp
+                    </div>
+                </div>
             </div>
             <div class="row">
                 <div class="form-group col-md-7">