rpt_print.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * Created by Tony on 2018/4/24.
  3. */
  4. let rptPrintHelper = {
  5. preview: function () {
  6. if (zTreeOprObj.currentRptPageRst) {
  7. // window.location.href = '/rpt_print';
  8. sessionStorage.currentPageData = JSON.stringify(zTreeOprObj.currentRptPageRst);
  9. sessionStorage.pageSize = rptControlObj.getCurrentPageSize();
  10. sessionStorage.orientation = rptControlObj.getCurrentOrientation();
  11. sessionStorage.scaleFactor = 1;
  12. window.open('/rpt_print');
  13. } else {
  14. sessionStorage.currentPageData = null;
  15. }
  16. },
  17. print: function () {
  18. //
  19. },
  20. buildSvgArr: function (pagesData, offsetX, offsetY) {
  21. let styles = pagesData[JV.NODE_STYLE_COLLECTION],
  22. fonts = pagesData[JV.NODE_FONT_COLLECTION],
  23. controls = pagesData[JV.NODE_CONTROL_COLLECTION]
  24. ;
  25. let rst = [];
  26. for (let page of pagesData.items) {
  27. let svgPageArr = [], pixelSize = getPixelSize(pagesData);
  28. svgPageArr.push("<svg width='" + pixelSize[0] + "' height='" + pixelSize[1] + "'>");
  29. for (let cell of page.cells) {
  30. svgPageArr.push(buildCellSvg(cell, fonts, styles, controls, page[JV.PROP_PAGE_MERGE_BORDER], pagesData[JV.BAND_PROP_MERGE_BAND], offsetX, offsetY));
  31. }
  32. svgPageArr.push("</svg>");
  33. rst.push(svgPageArr);
  34. }
  35. return rst;
  36. }
  37. };
  38. function buildCellSvg(cell, fonts, styles, controls, pageMergeBorder, rptMergeBorder, offsetX, offsetY) {
  39. let rst = [];
  40. let style = styles[cell[JV.PROP_STYLE]];
  41. let mergeBandStyle = null;
  42. if (rptMergeBorder) {
  43. mergeBandStyle = styles[rptMergeBorder[JV.PROP_STYLE]];
  44. }
  45. let left = parseInt(cell[JV.PROP_AREA][JV.PROP_LEFT]) + offsetX + 0.5,
  46. right = parseInt(cell[JV.PROP_AREA][JV.PROP_RIGHT]) + offsetX + 0.5,
  47. top = parseInt(cell[JV.PROP_AREA][JV.PROP_TOP]) + offsetY + 0.5,
  48. bottom = parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) + offsetY + 0.5,
  49. x = left, y = top,
  50. text_anchor = "start"
  51. ;
  52. if (style) {
  53. if (style[JV.PROP_LEFT] && parseFloat(style[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) > 0) {
  54. rst.push("<line x1='" + left + "' y1='" + top +
  55. "' x2='" + left + "' y2='" + bottom +
  56. "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
  57. }
  58. if (style[JV.PROP_RIGHT] && parseFloat(style[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) > 0) {
  59. rst.push("<line x1='" + right + "' y1='" + top +
  60. "' x2='" + right + "' y2='" + bottom +
  61. "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
  62. }
  63. if (style[JV.PROP_TOP] && parseFloat(style[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) > 0) {
  64. rst.push("<line x1='" + left + "' y1='" + top +
  65. "' x2='" + right + "' y2='" + top +
  66. "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
  67. }
  68. if (style[JV.PROP_BOTTOM] && parseFloat(style[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) > 0) {
  69. rst.push("<line x1='" + left + "' y1='" + bottom +
  70. "' x2='" + right + "' y2='" + bottom +
  71. "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
  72. }
  73. }
  74. let font = cell[JV.PROP_FONT];
  75. if (typeof font === 'string') {
  76. font = fonts[cell[JV.PROP_FONT]];
  77. }
  78. let fontsize = Math.round(parseInt(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]]) * 3 / 4);
  79. let fontWeight = (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T')?"bold":"normal";
  80. let control = controls[cell[JV.PROP_CONTROL]];
  81. if (control) {
  82. if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "left") {
  83. text_anchor = "start";
  84. x = left + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
  85. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "right") {
  86. text_anchor = "end";
  87. x = right - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
  88. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "center") {
  89. text_anchor = "middle";
  90. x = Math.round((left + right) / 2);
  91. }
  92. if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "top") {
  93. y = top + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
  94. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "bottom") {
  95. y = bottom - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
  96. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "center") {
  97. y = Math.round((top + bottom + fontsize) / 2 );
  98. }
  99. }
  100. rst.push("<text style='fill:black;font-family:" + font[JV.PROP_NAME] +
  101. ";font-weight:" + fontWeight +
  102. ";font-size:" + fontsize + "pt' x='" +
  103. x +"' y='" + y + "' text-anchor='" + text_anchor + "'>" + cell[JV.PROP_VALUE] + "</text>");
  104. return rst.join("");
  105. }
  106. function getPixelSize(pagesData) {
  107. let rst = [793,1122];
  108. let SCREEN_DPI = [96,96];
  109. if (pagesData[JV.NODE_PAGE_INFO] && pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE]) {
  110. rst[0] = Math.round(SCREEN_DPI[0] * pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][0]);
  111. rst[1] = Math.round(SCREEN_DPI[1] * pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][1]);
  112. }
  113. return rst;
  114. }