Browse Source

后台加导出SVG

TonyKang 7 năm trước cách đây
mục cha
commit
f1f5228563

+ 16 - 0
modules/reports/controllers/rpt_controller.js

@@ -18,6 +18,7 @@ import JpcEx from "../rpt_component/jpc_ex";
 import rptUtil from "../util/rpt_util";
 import rpt_xl_util from "../util/rpt_excel_util";
 import rpt_pdf_util from "../util/rpt_pdf_util";
+import rpt_svg_util from "../util/rpt_svg_util";
 import fs from "fs";
 import strUtil from "../../../public/stringUtil";
 import rptDataExtractor from "../util/rpt_construct_data_util";
@@ -264,6 +265,21 @@ module.exports = {
         });
     },
 
+    getReportAllPagesSvg: function (req, res) {
+        let params = JSON.parse(req.body.params),
+            rpt_id = params.rpt_tpl_id,
+            prj_id = params.prj_id,
+            pageSize = params.pageSize,
+            orientation = params.orientation,
+            customizeCfg = params.custCfg
+        ;
+        let user_id = req.session.sessionUser.id;
+        getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, function (err, pageRst) {
+            let svgRstStrArr = rpt_svg_util.exportSvgStr(pageRst, 0, 0);
+            callback(req, res, err, svgRstStrArr);
+        });
+    },
+
     getTestReportAllPages: function(req, res){
         let rpt_id = req.body.ID;
         let pageSize = req.body.pageSize;

+ 1 - 0
modules/reports/routes/report_router.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('/getReportSvg', reportController.getReportAllPagesSvg);
     rptRouter.get('/getExcel/:prj_id/:rpt_id/:size/:orientation/:rptName/:isOneSheet/:option', reportController.getExcel);
     rptRouter.get('/getPDF/:prj_id/:rpt_id/:size/:orientation/:rptName', reportController.getPDF);
     // rptRouter.get('/getExcelInOneBook/:ids/:size/:rptName/:option', reportController.getExcelInOneBook);

+ 136 - 39
modules/reports/util/rpt_svg_util.js

@@ -4,63 +4,129 @@
  */
 
 let JV = require('../rpt_component/jpc_value_define');
-const SCREEN_DPI = [96,96];
+let pdf = require('pdfkit');
+let jpcCmnHelper = require('../rpt_component/helper/jpc_helper_common');
+let SCREEN_DPI = jpcCmnHelper.getScreenDPI();
 
 module.exports = {
-    exportSvgStr: function (pagesData, callback) {
+    exportSvgStr: function (pagesData, offsetX, offsetY) {
+        let rst = [];
         let styles = pagesData[JV.NODE_STYLE_COLLECTION],
             fonts = pagesData[JV.NODE_FONT_COLLECTION],
             controls = pagesData[JV.NODE_CONTROL_COLLECTION]
         ;
-        for (let page of pagesData.items) {
+        let pdf_doc = new pdf({autoFirstPage: false});
+        for (let idx = 0; idx < pagesData.items.length; idx++) {
+            let page = pagesData.items[idx];
             let svgPageArr = [], pixelSize = getPixelSize(pagesData);
             svgPageArr.push("<svg width='" + pixelSize[0] + "' height='" + pixelSize[1] + "'>");
+            let adjustY = 0.5 * ((idx + 1) % 2);
+            // let cnt = 0;
             for (let cell of page.cells) {
-                svgPageArr.push(buildCellSvg(cell, fonts, styles, controls, page[JV.PROP_PAGE_MERGE_BORDER]));
+                svgPageArr.push(buildCellSvg(cell, fonts, styles, controls, page[JV.PROP_PAGE_MERGE_BORDER], pagesData[JV.BAND_PROP_MERGE_BAND], offsetX, offsetY, adjustY, pdf_doc));
+                // cnt++;
+                // console.log(cnt);
             }
             svgPageArr.push("</svg>");
+            rst.push(svgPageArr);
         }
+        return rst;
     }
 }
 
-function buildCellSvg(cell, fonts, styles, controls, mergeBorder) {
+function getActualBorderStyle(cell, styles, mergeBorderStyle, pageBorderArea, borderStr) {
+    let rst = styles[cell[JV.PROP_STYLE]][borderStr];
+    if (mergeBorderStyle) {
+        if (parseFloat(cell[JV.PROP_AREA][borderStr]) === parseFloat(pageBorderArea[borderStr])) {
+            if (borderStr === JV.PROP_LEFT || borderStr === JV.PROP_RIGHT) {
+                if (parseFloat(cell[JV.PROP_AREA][JV.PROP_TOP]) >= parseFloat(pageBorderArea[JV.PROP_TOP]) &&
+                    parseFloat(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) <= parseFloat(pageBorderArea[JV.PROP_BOTTOM])) {
+                    rst = mergeBorderStyle[borderStr];
+                }
+            } else if (borderStr === JV.PROP_TOP || borderStr === JV.PROP_BOTTOM) {
+                if (parseFloat(cell[JV.PROP_AREA][JV.PROP_LEFT]) >= parseFloat(pageBorderArea[JV.PROP_LEFT]) &&
+                    parseFloat(cell[JV.PROP_AREA][JV.PROP_RIGHT]) <= parseFloat(pageBorderArea[JV.PROP_RIGHT])) {
+                    rst = mergeBorderStyle[borderStr];
+                }
+            }
+        }
+    }
+    return rst;
+}
+
+function buildCellSvg(cell, fonts, styles, controls, pageMergeBorder, rptMergeBorder, offsetX, offsetY, adjustY, pdf_doc) {
     let rst = [];
     let style = styles[cell[JV.PROP_STYLE]];
+    let mergeBandStyle = null;
+    if (rptMergeBorder) {
+        mergeBandStyle = styles[rptMergeBorder[JV.PROP_STYLE][JV.PROP_ID]];
+    }
+    let font = cell[JV.PROP_FONT];
+    if (typeof font === 'string') {
+        font = fonts[cell[JV.PROP_FONT]];
+    }
+    let left = parseInt(cell[JV.PROP_AREA][JV.PROP_LEFT]) + offsetX + 0.5,
+        right = parseInt(cell[JV.PROP_AREA][JV.PROP_RIGHT]) + offsetX + 0.5,
+        top = parseInt(cell[JV.PROP_AREA][JV.PROP_TOP]) + offsetY + adjustY,
+        bottom = parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) + offsetY + adjustY
+    ;
     if (style) {
-        if (style[JV.PROP_LEFT] && parseFloat(style[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) > 0) {
-            rst.push("<line x1='" + cell[JV.PROP_AREA][JV.PROP_LEFT] + "' y1='" + cell[JV.PROP_AREA][JV.PROP_TOP] +
-                "' x2='" + cell[JV.PROP_AREA][JV.PROP_LEFT] + "' y2='" + cell[JV.PROP_AREA][JV.PROP_BOTTOM] +
-                "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
+        let leftBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_LEFT);
+        // if (style[JV.PROP_LEFT] && parseFloat(style[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) > 0) {
+        if (leftBS && parseFloat(leftBS[JV.PROP_LINE_WEIGHT]) > 0) {
+            rst.push("<line x1='" + left + "' y1='" + top +
+                "' x2='" + left + "' y2='" + bottom +
+                "' style='stroke:rgb(0,0,0);stroke-width:" + leftBS[JV.PROP_LINE_WEIGHT] +"'/>")
         }
-        if (style[JV.PROP_RIGHT] && parseFloat(style[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) > 0) {
-            rst.push("<line x1='" + cell[JV.PROP_AREA][JV.PROP_RIGHT] + "' y1='" + cell[JV.PROP_AREA][JV.PROP_TOP] +
-                "' x2='" + cell[JV.PROP_AREA][JV.PROP_RIGHT] + "' y2='" + cell[JV.PROP_AREA][JV.PROP_BOTTOM] +
-                "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
+        let rightBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_RIGHT);
+        // if (style[JV.PROP_RIGHT] && parseFloat(style[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) > 0) {
+        if (rightBS && parseFloat(rightBS[JV.PROP_LINE_WEIGHT]) > 0) {
+            rst.push("<line x1='" + right + "' y1='" + top +
+                "' x2='" + right + "' y2='" + bottom +
+                "' style='stroke:rgb(0,0,0);stroke-width:" + rightBS[JV.PROP_LINE_WEIGHT] +"'/>")
         }
-        if (style[JV.PROP_TOP] && parseFloat(style[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) > 0) {
-            rst.push("<line x1='" + cell[JV.PROP_AREA][JV.PROP_LEFT] + "' y1='" + cell[JV.PROP_AREA][JV.PROP_TOP] +
-                "' x2='" + cell[JV.PROP_AREA][JV.PROP_RIGHT] + "' y2='" + cell[JV.PROP_AREA][JV.PROP_TOP] +
-                "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
+        let topBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_TOP);
+        // if (style[JV.PROP_TOP] && parseFloat(style[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) > 0) {
+        if (topBS && parseFloat(topBS[JV.PROP_LINE_WEIGHT]) > 0) {
+            rst.push("<line x1='" + left + "' y1='" + top +
+                "' x2='" + right + "' y2='" + top +
+                "' style='stroke:rgb(0,0,0);stroke-width:" + topBS[JV.PROP_LINE_WEIGHT] +"'/>")
         }
-        if (style[JV.PROP_BOTTOM] && parseFloat(style[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) > 0) {
-            rst.push("<line x1='" + cell[JV.PROP_AREA][JV.PROP_LEFT] + "' y1='" + cell[JV.PROP_AREA][JV.PROP_BOTTOM] +
-                "' x2='" + cell[JV.PROP_AREA][JV.PROP_RIGHT] + "' y2='" + cell[JV.PROP_AREA][JV.PROP_BOTTOM] +
-                "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
+        let bottomBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_BOTTOM);
+        // if (style[JV.PROP_BOTTOM] && parseFloat(style[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) > 0) {
+        if (bottomBS && parseFloat(bottomBS[JV.PROP_LINE_WEIGHT]) > 0) {
+            rst.push("<line x1='" + left + "' y1='" + bottom +
+                "' x2='" + right + "' y2='" + bottom +
+                "' style='stroke:rgb(0,0,0);stroke-width:" + bottomBS[JV.PROP_LINE_WEIGHT] +"'/>")
         }
     }
-    let font = cell[JV.PROP_FONT];
-    if (typeof font === 'string') {
-        font = fonts[cell[JV.PROP_FONT]];
-    }
-    let fontsize = parseInt(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]]);
-    let left = parseInt(cell[JV.PROP_AREA][JV.PROP_LEFT]),
-        right = parseInt(cell[JV.PROP_AREA][JV.PROP_RIGHT]),
-        top = parseInt(cell[JV.PROP_AREA][JV.PROP_TOP]),
-        bottom = parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]),
+    buildText(rst, cell, font, controls[cell[JV.PROP_CONTROL]], offsetX, offsetY, adjustY, pdf_doc);
+
+    return rst.join("");
+}
+
+function buildText(destRst, cell, font, control, offsetX, offsetY, adjustY, pdf_doc) {
+    let orgFontHeight = parseInt(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]]);
+    let fontWeight = (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T')?"bold":"normal";
+    let fontStyle = (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] === 'T')?"italic":"normal";
+    let left = parseInt(cell[JV.PROP_AREA][JV.PROP_LEFT]) + offsetX + 0.5,
+        right = parseInt(cell[JV.PROP_AREA][JV.PROP_RIGHT]) + offsetX + 0.5,
+        top = parseInt(cell[JV.PROP_AREA][JV.PROP_TOP]) + offsetY + adjustY,
+        bottom = parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) + offsetY + adjustY,
         x = left, y = top,
         text_anchor = "start"
     ;
-    let control = controls[cell[JV.PROP_CONTROL]];
+    let value = cell[JV.PROP_VALUE];
+    if (!(value)) {
+        value = "";
+    }
+    let values = null;
+    if (typeof value === "string") {
+        values = value.split("|");
+    } else {
+        values = [value];
+    }
+    let stepHeight = (parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) - parseInt(cell[JV.PROP_AREA][JV.PROP_TOP])) / values.length;
     if (control) {
         if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "left") {
             text_anchor = "start";
@@ -72,16 +138,47 @@ function buildCellSvg(cell, fonts, styles, controls, mergeBorder) {
             text_anchor = "middle";
             x = Math.round((left + right) / 2);
         }
-        if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "top") {
-            y = top + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
-        } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "bottom") {
-            y = bottom - fontsize - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
-        } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "center") {
-            y = Math.round((top + bottom + fontsize) / 2 );
+    }
+    for (let vidx = 0; vidx < values.length; vidx++) {
+        //check whether need to adjust the font size
+        let dftFontHeight = orgFontHeight;
+        let dftFontBold = font[JV.FONT_PROPS[3]];
+        let dftFontItalic = font[JV.FONT_PROPS[4]];
+        if (dftFontBold && dftFontBold === 'T') {
+            pdf_doc.font(__dirname+'/pdf_base_files/hwxsb.ttf');
+        }else if(dftFontItalic && dftFontItalic === 'T'){
+            pdf_doc.font(__dirname+'/pdf_base_files/Smart-italic.ttf');
+        }else {
+            pdf_doc.font(__dirname+'/pdf_base_files/Smart.ttf');
+        }
+        pdf_doc.fontSize(dftFontHeight);
+        while ((right - left) <= pdf_doc.widthOfString(values[vidx])) {
+            if (dftFontHeight > 6) {
+                dftFontHeight--;
+                pdf_doc.fontSize(dftFontHeight);
+            } else {
+                break;
+            }
+        }
+        dftFontHeight = (dftFontHeight * 3 / 4); //SVG的字体与canvas的字体大小的切换, 不用考虑取整
+        if (control) {
+            if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "top") {
+                y = Math.round((top + vidx * stepHeight) + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP]);
+            } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "bottom") {
+                y = Math.round((top + (vidx + 1) * stepHeight) - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM]);
+            } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "center") {
+                y = Math.round(((top + vidx * stepHeight) + (top + (vidx + 1) * stepHeight) + dftFontHeight) / 2 );
+            }
+        }
+        if (font[JV.PROP_NAME] === "宋体") {
+            y--;
         }
+        destRst.push("<text style='fill:black;font-family:" + font[JV.PROP_NAME] +
+            ";font-weight:" + fontWeight +
+            ";font-style:" + fontStyle +
+            ";font-size:" + dftFontHeight + "pt' x='" +
+            x +"' y='" + y + "' text-anchor='" + text_anchor + "' xml:space='preserve'>" + values[vidx] + "</text>");
     }
-    rst.push("<text style='fill:black;font-size:" + fontsize + "pt' x='" + x +"' y='" + y + "'>" + cell[JV.PROP_VALUE] + "</text>");
-    return rst.join();
 }
 
 function getPixelSize(pagesData) {

+ 37 - 13
test/unit/reports/rpt_cfg.js

@@ -3,8 +3,8 @@ module.exports = {
         {
             "ID" : "ReportTitle_Main",
             "CfgDispName" : "主标题",
-            "Name" : "smartSimSun",
-            "FontHeight" : "27",
+            "Name" : "宋体",
+            "FontHeight" : "32",
             "FontColor" : "BLACK",
             "FontBold" : "T",
             "FontItalic" : "F",
@@ -15,8 +15,20 @@ module.exports = {
         {
             "ID" : "ReportTitle_Vice_1",
             "CfgDispName" : "副标题",
-            "Name" : "smartSimSun",
-            "FontHeight" : "20",
+            "Name" : "宋体",
+            "FontHeight" : "22",
+            "FontColor" : "BLACK",
+            "FontBold" : "T",
+            "FontItalic" : "F",
+            "FontUnderline" : "F",
+            "FontStrikeOut" : "F",
+            "FontAngle" : "0"
+        },
+        {
+            "ID" : "ReportTitle_Vice_2",
+            "CfgDispName" : "副标题2",
+            "Name" : "宋体",
+            "FontHeight" : "18",
             "FontColor" : "BLACK",
             "FontBold" : "T",
             "FontItalic" : "F",
@@ -27,7 +39,7 @@ module.exports = {
         {
             "ID" : "HeaderColumn",
             "CfgDispName" : "栏头",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -39,7 +51,7 @@ module.exports = {
         {
             "ID" : "Header",
             "CfgDispName" : "表头",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -51,7 +63,7 @@ module.exports = {
         {
             "ID" : "FooterColumn",
             "CfgDispName" : "栏尾",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -63,7 +75,7 @@ module.exports = {
         {
             "ID" : "Footer",
             "CfgDispName" : "表尾",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -75,7 +87,7 @@ module.exports = {
         {
             "ID" : "GrandTotal",
             "CfgDispName" : "总合计",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -87,7 +99,7 @@ module.exports = {
         {
             "ID" : "SectionTotal",
             "CfgDispName" : "章合计",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -99,7 +111,19 @@ module.exports = {
         {
             "ID" : "Content",
             "CfgDispName" : "正文内容",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
+            "FontHeight" : "12",
+            "FontColor" : "BLACK",
+            "FontBold" : "F",
+            "FontItalic" : "F",
+            "FontUnderline" : "F",
+            "FontStrikeOut" : "F",
+            "FontAngle" : "0"
+        },
+        {
+            "ID" : "Content_Narrow",
+            "CfgDispName" : "正文内容-窄体",
+            "Name" : "Arial Narrow",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -110,7 +134,7 @@ module.exports = {
         },
         {
             "ID" : "Header_V1",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",
@@ -121,7 +145,7 @@ module.exports = {
         },
         {
             "ID" : "Header_V2",
-            "Name" : "smartSimSun",
+            "Name" : "宋体",
             "FontHeight" : "12",
             "FontColor" : "BLACK",
             "FontBold" : "F",

+ 100 - 0
test/unit/reports/test_svg_data.js

@@ -0,0 +1,100 @@
+/**
+ * Created by Tony on 2018/7/5.
+ */
+
+let test = require('tape');
+import JpcEx from "../../../modules/reports/rpt_component/jpc_ex";
+import JV from "../../../modules/reports/rpt_component/jpc_value_define";
+let config = require("../../../config/config.js");
+config.setupDb(process.env.NODE_ENV);
+let mongoose = require("mongoose");
+let fileUtils = require("../../../modules/common/fileUtils");
+let path = require('path');
+let dbm = require("../../../config/db/db_manager");
+let rpt_cfg = require('./rpt_cfg');
+dbm.connect(process.env.NODE_ENV);
+
+//统一引用models
+fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
+    require(path.resolve(modelPath));
+});
+
+let cfgCacheUtil = require("../../../config/cacheCfg");
+cfgCacheUtil.setupDftCache();
+
+let fsUtil = require("../../../public/fsUtil");
+
+let demoPrjId = - 1;
+let demoRptId = 232, pagesize = "A4";
+
+// demoPrjId = 720; //QA: DW3
+demoPrjId = 2260; //QA:
+//*/
+// let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了
+let userId_Leng = "5acac1e885bf55000bd055ba";
+let userId_Dft = userId_Leng;
+/*/
+ let userId_Dft = "595328da1934dc327cad08eb";
+ //*/
+
+let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
+let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
+
+import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
+import rpt_svg_util from "../../../modules/reports/util/rpt_svg_util";
+
+let fs = require('fs');
+//设置Date Format函数
+fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
+    eval(data);
+});
+
+test('测试 - 测试模板啦: ', function (t) {
+    rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
+        let rptDataUtil = new rptDataExtractor();
+        rptDataUtil.initialize(rptTpl._doc);
+        let filter = rptDataUtil.getDataRequestFilter();
+        //正常应该根据报表模板定义的数据类型来请求数据
+        rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
+            if (!err) {
+                try {
+                    let tplData = rptDataUtil.assembleData(rawDataObj);
+                    //it's time to build the report!!!
+                    let printCom = JpcEx.createNew();
+                    rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
+                    let defProperties = rpt_cfg;
+                    let dftOption = JV.PAGING_OPTION_NORMAL;
+                    printCom.initialize(rptTpl);
+                    printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
+                    let maxPages = printCom.totalPages;
+                    let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
+                    if (pageRst) {
+                        let svgRstStrArr = rpt_svg_util.exportSvgStr(pageRst, 0, 0);
+                        fsUtil.writeObjToFile(svgRstStrArr, "D:/GitHome/ConstructionCost/tmp/rptPageResult_SVG格式.jsp");
+                    } else {
+                        console.log("oh! no pages were created!");
+                    }
+                } catch (ex) {
+                    console.log(ex);
+                    t.pass('pass with exception!');
+                    t.end();
+                }
+
+                t.pass('pass succeeded!');
+                t.end();
+            } else {
+                console.log(msg);
+                t.pass('pass with error!');
+                t.end();
+            }
+        })
+    });
+});
+
+test('close the connection', function (t) {
+    setTimeout(function () {
+        mongoose.disconnect();
+        t.pass('closing db connection');
+        t.end();
+    }, 3000);
+});

+ 2 - 5
web/building_saas/report/html/rpt_print.html

@@ -37,12 +37,10 @@
 <script type="text/javascript" src="/web/building_saas/report/js/jpc_output.js"></script>
 <script type="text/javascript" src="/web/building_saas/report/js/rpt_print.js"></script>
 <SCRIPT type="text/javascript">
-    let canvasArr = [];
     function loading() {
         if (sessionStorage.currentPageData) {
             let pageData = JSON.parse(sessionStorage.currentPageData);
-//            let scaleFactor = parseInt(sessionStorage.scaleFactor);
-            let scaleFactor = 1;
+            let scaleFactor = parseInt(sessionStorage.scaleFactor);
             $(document).attr("title", pageData[JV.NODE_PAGE_INFO][JV.NODE_MAIN_INFO_RPT_NAME]);
             let orgHeight = 793, orgWidth = 1122;
             let pageHeight = orgHeight * scaleFactor, pageWidth = orgWidth * scaleFactor;
@@ -76,13 +74,12 @@
                     elementSvg.setAttribute('width', pageWidth);
                 });
             });
-//            $("body").css({"page": "page"});
             window.print();
-            //document.execCommand("print");
         } else {
             //alert("没有报表数据!");
         }
     }
+
     function closing() {
         //
     }

+ 0 - 2
web/building_saas/report/js/rpt_print.js

@@ -5,7 +5,6 @@
 let rptPrintHelper = {
     preview: function () {
         if (zTreeOprObj.currentRptPageRst) {
-            // window.location.href = '/rpt_print';
             sessionStorage.currentPageData = JSON.stringify(zTreeOprObj.currentRptPageRst);
             sessionStorage.pageSize = rptControlObj.getCurrentPageSize();
             sessionStorage.orientation = rptControlObj.getCurrentOrientation();
@@ -16,7 +15,6 @@ let rptPrintHelper = {
         }
     },
     buildSvgArr: function (pagesData, offsetX, offsetY) {
-        let me = this;
         let styles = pagesData[JV.NODE_STYLE_COLLECTION],
             fonts = pagesData[JV.NODE_FONT_COLLECTION],
             controls = pagesData[JV.NODE_CONTROL_COLLECTION]