Browse Source

增加容错逻辑(合计、树排序) 调整Date对象Format函数

TonyKang 7 years ago
parent
commit
a4b9c54560

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

@@ -922,7 +922,12 @@ JpcFlowTabSrv.prototype.createNew = function(){
             if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
                 let tab_fields = me.seg_sum_tab_fields;
                 for (let i = 0; i < tab_fields.length; i++) {
-                    let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_fields[i], me.segSumValLst[segIdx][i], controls);
+                    let sumVal = 0;
+                    if (me.segSumValLst[segIdx] && me.segSumValLst[segIdx].length > i) {
+                        sumVal = me.segSumValLst[segIdx][i];
+                    }
+                    //备注:考虑到有时候会出现没有数据可合计的scenario,得有容错处理
+                    let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_fields[i], sumVal, controls);
                     cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_fields[i][JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, me.multiCols, 0, true, false);
                     rst.push(cellItem);
                 }

+ 17 - 0
public/stringUtil.js

@@ -263,5 +263,22 @@ module.exports = {
             }
         }
         return rst;
+    },
+    setupDateFormat: function () {
+        Date.prototype.Format = function (fmt) {
+            let o = {
+                "M+": this.getMonth() + 1, //月份
+                "d+": this.getDate(), //日
+                "h+": this.getHours(), //小时
+                "m+": this.getMinutes(), //分
+                "s+": this.getSeconds(), //秒
+                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
+                "S": this.getMilliseconds() //毫秒
+            };
+            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
+            for (let k in o)
+                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
+            return fmt;
+        };
     }
 }

+ 2 - 3
server.js

@@ -104,9 +104,8 @@ app.use(function(err, req, res, next) {
 });
 
 //设置外增的Date对象Format函数
-fs.readFile(__dirname + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
-    eval(data);
-});
+//备注: 经过测试nodejs 8.9.3版本不支持eval的方式修改prototype,为兼容考虑,把方法调整到stringUtil文件里
+require('./public/stringUtil').setupDateFormat();
 
 app.listen(6060, function(){
     console.log('server started!');

+ 5 - 4
test/unit/reports/test_rpt_test_template.js

@@ -32,7 +32,8 @@ let demoPrjId = - 1;
 // let demoRptId = 361; //封1
 // let demoRptId = 279; //表04
 // let demoRptId = 261; //封3
-let demoRptId = 232; //09
+// let demoRptId = 232; //09
+let demoRptId = 280; //11-1 暂列金
 // let demoRptId = 2260; //测试基本信息
 let pagesize = "A4";
 //288: 11-2表(新)
@@ -89,9 +90,9 @@ test('测试 - 测试模板啦: ', function (t) {
                     let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
                     if (pageRst) {
                         // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_测试模板.jsp");
-                        rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
-                            console.log("excel uuid: " + uuidName);
-                        });
+                        // rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
+                        //     console.log("excel uuid: " + uuidName);
+                        // });
                         // rpt_pdf_util.export_pdf_file(pageRst, pagesize, 'local_test_rpt_pdf', function(uuidName){
                         //     console.log("pdf uuid: " + uuidName);
                         // });