Browse Source

print preview

TonyKang 7 years ago
parent
commit
85e449a70f

+ 56 - 3
web/building_saas/report/html/rpt_print.html

@@ -2,9 +2,62 @@
 <html lang="en">
 <head>
     <meta charset="UTF-8">
-    <title>PrintPreview</title>
+    <title></title>
 </head>
-<body>
-
+<style type="text/css">
+    .pageBreakOrg {
+        page-break-before: auto;
+        page-break-after: always;
+    }
+    .pageBreak {
+        page-break-before: auto;
+        page-break-after: auto;
+    }
+</style><script type="text/javascript" src="/web/building_saas/report/js/jpc_output_value_define.js"></script>
+<body onload="loading()" onbeforeunload="closing()">
 </body>
+<script src="/lib/jquery/jquery-3.2.1.min.js"></script>
+<script type="text/javascript" src="/web/building_saas/report/js/jpc_output.js"></script>
+<SCRIPT type="text/javascript">
+    let canvasArr = [];
+    function loading() {
+        if (sessionStorage.currentPageData) {
+            let pageData = JSON.parse(sessionStorage.currentPageData);
+            $(document).attr("title", pageData[JV.NODE_PAGE_INFO][JV.NODE_MAIN_INFO_RPT_NAME]);
+            let pageHeight = 793, pageWidth = 1122;
+            if (sessionStorage.pageSize === 'A3') {
+                pageHeight = 1122;
+                pageWidth = 793 * 2;
+            } else if (sessionStorage.pageSize === '自定义') {
+                //自定义
+            }
+            if (sessionStorage.orientation === "纵向") {
+                let tmpInt = pageHeight;
+                pageHeight = pageWidth;
+                pageWidth = tmpInt;
+            }
+            for (let i = 0; i < pageData.items.length; i++) {
+                let div = $('<div class="pageBreak"><canvas width="' + pageWidth + '" height="' + pageHeight + '"></canvas></div>');
+                $("body").append(div);
+            }
+            $(document.body).find("div").each(function(index,element){
+                $(element).find("canvas").each(function(cIdx,elementCanvas){
+                    canvasArr.push(elementCanvas);
+                });
+            });
+            for (let i = 0; i < canvasArr.length; i++) {
+                JpcCanvasOutput.offsetX = -10;
+                JpcCanvasOutput.offsetY = -20;
+                JpcCanvasOutput.drawToCanvas(pageData, canvasArr[i], i+1);
+            }
+            window.print();
+            //document.execCommand("print");
+        } else {
+            //alert("没有报表数据!");
+        }
+    }
+    function closing() {
+        //
+    }
+</SCRIPT>
 </html>

+ 1 - 0
web/building_saas/report/js/jpc_output_value_define.js

@@ -5,6 +5,7 @@
 let JV = {
     NODE_MAIN_INFO: "主信息",
     NODE_PAGE_INFO: "打印页面_信息",
+    NODE_MAIN_INFO_RPT_NAME: "报表名称",
     NODE_PAGE_SIZE: "纸张宽高",
     NODE_MARGINS: "页边距",
 

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

@@ -5,9 +5,13 @@
 let rptPrintHelper = {
     preview: function () {
         if (zTreeOprObj.currentRptPageRst) {
-            window.location.href = '/rpt_print';
+            // window.location.href = '/rpt_print';
+            sessionStorage.currentPageData = JSON.stringify(zTreeOprObj.currentRptPageRst);
+            sessionStorage.pageSize = rptControlObj.getCurrentPageSize();
+            sessionStorage.orientation = rptControlObj.getCurrentOrientation();
+            window.open('/rpt_print');
         } else {
-            //
+            sessionStorage.currentPageData = null;
         }
     },
     print: function () {