فهرست منبع

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

zhangweicheng 7 سال پیش
والد
کامیت
bffa613595
2فایلهای تغییر یافته به همراه36 افزوده شده و 1 حذف شده
  1. 16 0
      modules/reports/rpt_component/helper/jpc_helper_common.js
  2. 20 1
      modules/reports/rpt_component/jpc_flow_tab.js

+ 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 = [];
                         }
                     }
                 }