TonyKang 7 anos atrás
pai
commit
b98b076892

+ 30 - 0
modules/reports/controllers/rpt_controller_operation.js

@@ -72,6 +72,28 @@ function getAllPagesCommonOrg(rpt_id, pageSize, option, cb) {
     );
 }
 
+function getPreViewPage(rpt_id, pageSize, cb) {
+    let rptTpl = null;
+    rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
+        rptTpl = rst;
+        if (rptTpl) {
+            let printCom = JpcEx.createNew();
+            let defProperties = rptUtil.getReportDefaultCache();
+            rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
+            printCom.initialize(rptTpl);
+            let pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
+            if (pageRst) {
+                //fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/previewPageResult.jsp");
+                cb(null, pageRst);
+            } else {
+                cb('Have errors while on going...', null);
+            }
+        } else {
+            cb('No report template was found!', null);
+        }
+    });
+}
+
 /*
 function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, option, cb) {
     let rptTpl = null;
@@ -110,6 +132,14 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, option, cb) {
 }
 //*/
 module.exports = {
+    getPreviewPage: function(req, res) {
+        let params = JSON.parse(req.body.params),
+            rpt_id = params.rpt_tpl_id,
+            pageSize = params.pageSize;
+        getPreViewPage(rpt_id, pageSize, function (err, pageRst) {
+            callback(req, res, err, pageRst);
+        });
+    },
     // getReportAllPages: function (req, res) {
     //     let rpt_id = req.body.rpt_tpl_id, prj_id = req.body.prj_id,
     //         user_id = req.body.user_id, pageSize = req.body.pageSize;

+ 1 - 0
modules/reports/routes/report_router_operation.js

@@ -25,6 +25,7 @@ module.exports =function (app) {
     rptRouter.get('/getTestPDF/:id/:size/:rptName', reportController.getTestPDF);
     //now is the real:
     rptRouter.post('/getReport', reportController.getReportAllPages);
+    rptRouter.post('/getPreviewPage', reportController.getPreviewPage);
     // rptRouter.get('/getExcel/:id/:size/:rptName/:isOneSheet/:option', reportController.getExcel);
     // rptRouter.get('/getExcelInOneBook/:ids/:size/:rptName/:option', reportController.getExcelInOneBook);
     // rptRouter.get('/getPDF/:id/:size/:rptName', reportController.getPDF);

+ 32 - 18
modules/reports/rpt_component/jpc_bill_tab.js

@@ -46,24 +46,8 @@ JpcBillTabSrv.prototype.createNew = function(){
         let pageStatus = [true, true, false, true, false, false, false, false];
         JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, true, false);
         let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
-        let tab = rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT];
-        let band = bands[tab[JV.PROP_BAND_NAME]];
-        if (band) {
-            if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
-                if (tab[JV.PROP_TEXT]) {
-                    rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
-                }
-                if (tab[JV.PROP_TEXTS]) {
-                    for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
-                        rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
-                    }
-                }
-                if (tab[JV.NODE_DISCRETE_INFO]) {
-                    rst.push(JpcDiscreteHelper.outputPreviewDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus, page - 1, 1, 0));
-                }
-            }
-        }
-        rst.push(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus));
+        rst = rst.concat(me.outputPreviewContent(rptTpl, bands, unitFactor, controls, pageStatus));
+        rst = rst.concat(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus));
         return rst;
     };
     JpcBillTabResult.outputAsSimpleJSONPage = function (rptTpl, dataObj, page, bands, controls, $CURRENT_RPT) {
@@ -83,6 +67,36 @@ JpcBillTabSrv.prototype.createNew = function(){
         }
         return rst;
     };
+    JpcBillTabResult.outputPreviewContent = function(rptTpl, bands, unitFactor, controls, pageStatus) {
+        let rst = [];
+        let tab = rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT];
+        let band = bands[tab[JV.PROP_BAND_NAME]];
+        if (band) {
+            if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
+                let tab_fields = tab[JV.PROP_BILL_FIELDS];
+                for (let i = 0; i < tab_fields.length; i++) {
+                    let tab_field = tab_fields[i];
+                    if (!(tab_field[JV.PROP_HIDDEN])) {
+                        let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_field, "", controls);
+                        cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
+                        rst.push(cellItem);
+                    }
+                }
+                if (tab[JV.PROP_TEXT]) {
+                    rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
+                }
+                if (tab[JV.PROP_TEXTS]) {
+                    for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
+                        rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
+                    }
+                }
+                if (tab[JV.NODE_DISCRETE_INFO]) {
+                    rst = rst.concat(JpcDiscreteHelper.outputDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, pageStatus, page - 1, 1, 0));
+                }
+            }
+        }
+        return rst;
+    };
     JpcBillTabResult.outputContent = function(rptTpl, dataObj, page, bands, unitFactor, controls, pageStatus, $CURRENT_RPT) {
         let me = this, rst = [];
         let tab = rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT];

+ 26 - 12
modules/reports/rpt_component/jpc_flow_tab.js

@@ -598,29 +598,25 @@ JpcFlowTabSrv.prototype.createNew = function(){
         let me = this, rst = [], vIdx = [];
         //只预览第一页的数据
         let pageStatus = [true, true, false, true, false, false, false, false];
+        me.pageStatusLst.push(pageStatus);
+        JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS], null, me.disp_fields_idx, false);
         JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, true, false);
         let maxRowRec = JpcFlowTabHelper.getMaxRowsPerPage(bands, rptTpl, false);
         for (let i = 0; i < maxRowRec; i++) {
             vIdx.push([-1, JV.DISPLAY_VAL_TYPE_NORMAL, JV.BLANK_VALUE_INDEX]);
         }
-        let bkdispValueIdxLst = me.dispValueIdxLst;
-        me.pageStatusLst = [];
-        me.pageStatusLst.push(pageStatus);
-        me.dispValueIdxLst = [];
-        me.dispValueIdxLst.push(vIdx);
         let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
         // 2.2 Column tab
-        rst.push(me.outputColumn(rptTpl, null, 1, 0, bands, unitFactor, controls, 0));
+        rst = rst.concat(me.outputColumn(rptTpl, null, 1, 0, bands, unitFactor, controls, 0));
         // 2.1 Content-Tab
-        // rst.push(me.outputContent(rptTpl, null, 1, bands, unitFactor, controls, 0, $CURRENT_RPT));
+        rst = rst.concat(me.outputPreviewContent(rptTpl, bands, unitFactor, controls, pageStatus, maxRowRec));
         // 2.3 Sum Seg
-        // rst.push(me.outputSegSum(rptTpl, dataObj, 1, 0, bands, unitFactor, controls));
+        // rst = rst.concat(me.outputSegSum(rptTpl, dataObj, 1, 0, bands, unitFactor, controls));
         // 2.4 Sum Page
-        // rst.push(me.outputPageSum(rptTpl, dataObj, 1, 0, bands, unitFactor, controls));
+        // rst = rst.concat(me.outputPageSum(rptTpl, dataObj, 1, 0, bands, unitFactor, controls));
         // 2.5 Group
         // 2.6 Discrete
-        rst.push(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus));
-        me.dispValueIdxLst = bkdispValueIdxLst;
+        rst = rst.concat(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus));
         return rst;
     };
     JpcFlowTabResult.outputAsSimpleJSONPage = function (rptTpl, dataObj, page, bands, controls, adHocMergePos, $CURRENT_RPT) {
@@ -692,6 +688,25 @@ JpcFlowTabSrv.prototype.createNew = function(){
         }
         return rst;
     };
+    JpcFlowTabResult.outputPreviewContent = function(rptTpl, bands, unitFactor, controls, pageStatus, maxRec) {
+        let me = this, rst = [];
+        let tab = rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT];
+        let band = bands[tab[JV.PROP_BAND_NAME]];
+        if (band) {
+            if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
+                let tab_fields = tab[JV.PROP_FLOW_FIELDS];
+                for (let rowIdx = 0; rowIdx < maxRec; rowIdx++) {
+                    for (let i = 0; i < tab_fields.length; i++) {
+                        let tab_field = tab_fields[i];
+                        if (!(tab_field[JV.PROP_HIDDEN])) {
+                            rst.push(me.outputTabField(band, tab_field, null, -1, -1, maxRec, rowIdx, 1, 0, unitFactor, true, controls, 0));
+                        }
+                    }
+                }
+            }
+        }
+        return rst;
+    };
     JpcFlowTabResult.outputContent = function(rptTpl, dataObj, page, bands, unitFactor, controls, multiColIdx, $CURRENT_RPT) {
         let me = this, rst = [];
         let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
@@ -730,7 +745,6 @@ JpcFlowTabSrv.prototype.createNew = function(){
                         }
                         if (!(tab_field[JV.PROP_HIDDEN])) {
                             // rst.push(me.outputTabField(band, tab_field, data_field, contentValuesIdx[rowIdx], -1, contentValuesIdx.length, rowIdx, 1, 0, unitFactor, true, controls, multiColIdx));
-                            //测试中
                             if (contentValuesIdx[rowIdx][0] !== JV.TYPE_FOLLOW_MODE && contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_NORMAL) {
                                 rst.push(me.outputTabField(band, tab_field, data_field, contentValuesIdx[rowIdx][2], -1, contentValuesIdx.length, rowIdx, 1, 0, unitFactor, true, controls, multiColIdx));
                             } else if (contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_AUTO_HEIGHT) {

+ 25 - 8
web/maintain/report/js/rpt_tpl_preview_util.js

@@ -65,14 +65,14 @@ let preview_util = {
         }
 
         let private_translateUnit = function(unitStr) {
-            let me = this, rst = 1.0;
+            let rst = 1.0;
             if (unitStr) {
                 if (JV.MEASUREMENT.PIXEL.indexOf(unitStr) >= 0) {
                     rst = 1.0;
                 } else if (JV.MEASUREMENT.CM.indexOf(unitStr) >= 0) {
-                    rst = 1.0 * resolution[0] / 2.54;
+                    rst = resolution[0] / 2.54;
                 } else if (JV.MEASUREMENT.INCH.indexOf(unitStr) >= 0) {
-                    rst = 1.0 * resolution[0];
+                    rst = resolution[0];
                 }
             }
             return rst;
@@ -91,7 +91,7 @@ let preview_util = {
             let rstArea = [].concat(parentArea);
             switch (JV.LAYOUT.indexOf(band[JV.BAND_PROP_ALIGNMENT])) {
                 case JV.LAYOUT_TOP:
-                    if (band[JV.PROP_CALCULATION] == JV.CAL_TYPE_ABSTRACT) {
+                    if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
                         rstArea[JV.IDX_BOTTOM] = rstArea[JV.IDX_TOP] + unitFactor * parseFloat(band[JV.BAND_PROP_HEIGHT]);
                     } else {
                         rstArea[JV.IDX_BOTTOM] = rstArea[JV.IDX_TOP] + (rstArea[JV.IDX_BOTTOM] - rstArea[JV.IDX_TOP]) * parseFloat(band[JV.BAND_PROP_HEIGHT]) / 100;
@@ -99,7 +99,7 @@ let preview_util = {
                     parentArea[JV.IDX_TOP] = rstArea[JV.IDX_BOTTOM];
                     break;
                 case JV.LAYOUT_BOTTOM:
-                    if (band[JV.PROP_CALCULATION] == JV.CAL_TYPE_ABSTRACT) {
+                    if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
                         rstArea[JV.IDX_TOP] = rstArea[JV.IDX_BOTTOM] - unitFactor * parseFloat(band[JV.BAND_PROP_HEIGHT]);
                     } else {
                         rstArea[JV.IDX_TOP] = rstArea[JV.IDX_BOTTOM] - (rstArea[JV.IDX_BOTTOM] - rstArea[JV.IDX_TOP]) * parseFloat(band[JV.BAND_PROP_HEIGHT]) / 100;
@@ -107,7 +107,7 @@ let preview_util = {
                     parentArea[JV.IDX_BOTTOM] = rstArea[JV.IDX_TOP];
                     break;
                 case JV.LAYOUT_LEFT:
-                    if (band[JV.PROP_CALCULATION] == JV.CAL_TYPE_ABSTRACT) {
+                    if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
                         rstArea[JV.IDX_RIGHT] = rstArea[JV.IDX_LEFT] + unitFactor * parseFloat(band[JV.BAND_PROP_WIDTH]);
                     } else {
                         rstArea[JV.IDX_RIGHT] = rstArea[JV.IDX_LEFT] + (rstArea[JV.IDX_RIGHT] - rstArea[JV.IDX_LEFT]) * parseFloat(band[JV.BAND_PROP_WIDTH]) / 100;
@@ -115,7 +115,7 @@ let preview_util = {
                     parentArea[JV.IDX_LEFT] = rstArea[JV.IDX_RIGHT];
                     break;
                 case JV.LAYOUT_RIGHT:
-                    if (band[JV.PROP_CALCULATION] == JV.CAL_TYPE_ABSTRACT) {
+                    if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
                         rstArea[JV.IDX_LEFT] = rstArea[JV.IDX_RIGHT] - unitFactor * parseFloat(band[JV.BAND_PROP_WIDTH]);
                     } else {
                         rstArea[JV.IDX_LEFT] = rstArea[JV.IDX_RIGHT] - (rstArea[JV.IDX_RIGHT] - rstArea[JV.IDX_LEFT]) * parseFloat(band[JV.BAND_PROP_WIDTH]) / 100;
@@ -163,5 +163,22 @@ let preview_util = {
         if (bandTreeOprObj.currentNode) {
             //need to high-light the band?
         }
+    },
+    getPreviewPage: function(canvas) {
+        if (zTreeOprObj.currentNode.refId) {
+            let params = {}, me = this;
+            params.rpt_tpl_id = zTreeOprObj.currentNode.refId;
+            params.pageSize = "A4";
+            CommonAjax.postEx("report_api/getPreviewPage", params, 10000, true, function(result){
+                    if (result) {
+                        JpcCanvasOutput.cleanCanvas(canvas);
+                        JpcCanvasOutput.drawPageBorder(result, canvas, [96,96]);
+                        JpcCanvasOutput.drawToCanvas(result, canvas, 1);
+                    } else {
+                        alert('preview error!');
+                    }
+                }, null, null
+            );
+        }
     }
-}
+};

+ 1 - 0
web/maintain/report/rpt_tpl_main.html

@@ -83,6 +83,7 @@
     <script src="/web/maintain/report/js/rpt_tpl_pre_handle.js"></script>
     <script src="/web/maintain/report/js/cfg_const.js"></script>
     <script src="/web/maintain/report/js/rpt_tpl_preview_util.js"></script>
+    <script src="/web/maintain/report/js/jpc_output.js"></script>
     <!-- zTree -->
     <script type="text/javascript" src="/public/web/date_util.js"></script>
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>

+ 1 - 1
web/maintain/report/rpt_tpl_preview.html

@@ -1,7 +1,7 @@
 <div class="form-view col-lg-7 p-0">
     <div class="main-data-h" style="position:relative">
         <div class="sub-button p-2">
-            <button class="btn btn-primary" onclick="preview_util.preview($('#tplCanvas')[0], zTreeOprObj.getRefTpl()) ">预览</button>
+            <button class="btn btn-primary" onclick="preview_util.getPreviewPage($('#tplCanvas')[0], zTreeOprObj.getRefTpl()) ">预览</button>
             <button class="btn btn-primary" onclick="tplHelper.saveRptTpl()">保存</button>
             <button class="btn btn-secondary">保存并发布</button>
             <button class="btn btn-danger">删除模板</button>