rpt_tpl_virtual_common.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Created by Tony on 2018/9/4.
  3. */
  4. let virtualCommonOprObj = {
  5. getActPos: function (textNode, caclStr, typeStr, baseMea) {
  6. let rst = 0;
  7. if (caclStr === JV.CAL_TYPE[0]) {
  8. //percentage
  9. rst = Math.round(baseMea * textNode[JV.PROP_AREA][typeStr] / 100);
  10. } else {
  11. //abstract
  12. rst = Math.round(textNode[JV.PROP_AREA][typeStr] / 2.54 * 96);
  13. }
  14. return rst;
  15. },
  16. getActPosEx: function (textNode, caclObj, typeStr, baseMea) {
  17. let me = this;
  18. if (typeof caclObj === 'string') {
  19. return me.getActPos(textNode, caclObj, typeStr, baseMea);
  20. } else {
  21. return me.getActPos(textNode, caclObj[typeStr], typeStr, baseMea);
  22. }
  23. },
  24. pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) {
  25. let me = this, pos = me.getActPosEx(textNode, caclObj, typeStr, baseMea);
  26. if (posArr.indexOf(pos) < 0) posArr.push(pos);
  27. },
  28. getBandEx: function (bandName, rptTpl) {
  29. let me = this, rst;
  30. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  31. rst = me.getBand(bandName, band);
  32. if (rst !== null) {
  33. break;
  34. }
  35. }
  36. return rst;
  37. },
  38. getBand: function (bandName, parentBand) {
  39. let me = this, rst = null;
  40. if (parentBand[JV.PROP_NAME] === bandName) {
  41. rst = parentBand;
  42. } else {
  43. if (parentBand[JV.BAND_PROP_SUB_BANDS] && parentBand[JV.BAND_PROP_SUB_BANDS].length > 0) {
  44. for (let subBand of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  45. rst = me.getBand(bandName, subBand);
  46. if (rst !== null) {
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. return rst;
  53. },
  54. checkInSpan: function (spans, row, col) {
  55. let rst = false;
  56. for (let span of spans) {
  57. if (span.row <= row && row < (span.row + span.rowCount) && span.col <= col && col < (span.col + span.colCount)) {
  58. rst = true;
  59. break;
  60. }
  61. }
  62. return rst;
  63. },
  64. createTxtNode: function (text, parentNode, colWidthArr, rowHeightArr) {
  65. let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
  66. let rst = dataInfoMapTreeOprObj.getDummyTextNode(parentNode);
  67. rst[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
  68. if (text.col > 0) {
  69. rst[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
  70. } else {
  71. rst[JV.PROP_AREA][JV.PROP_LEFT] = 0;
  72. }
  73. rst[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2);
  74. if (text.row > 0) {
  75. rst[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2);
  76. } else {
  77. rst[JV.PROP_AREA][JV.PROP_TOP] = 0;
  78. }
  79. if (stringUtil.isEmptyString(text[`text`])) {
  80. rst[JV.PROP_NAME] = '';
  81. } else {
  82. rst[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`].toString(), '\n', '|'), '\r', '');
  83. }
  84. rst[JV.PROP_LABEL] = rst[JV.PROP_NAME];
  85. return rst;
  86. },
  87. collectSheetTxt: function (sheet, texts, colWidthArr, rowHeightArr) {
  88. let spans= sheet.getSpans();
  89. let private_build_pre_text = function (row, col, rowCount, colCount) {
  90. texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": sheet.getValue(row, col)});
  91. };
  92. for (let span of spans) {
  93. private_build_pre_text(span.row, span.col, span.rowCount, span.colCount);
  94. }
  95. for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
  96. rowHeightArr.push(sheet.getRowHeight(iRow));
  97. if (iRow > 0) {
  98. rowHeightArr[iRow] = rowHeightArr[iRow] + rowHeightArr[iRow - 1];
  99. }
  100. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  101. if (iRow === 0) {
  102. colWidthArr.push(sheet.getColumnWidth(jCol));
  103. if (jCol > 0) {
  104. colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1];
  105. }
  106. }
  107. if (!virtualCommonOprObj.checkInSpan(spans, iRow, jCol)) {
  108. private_build_pre_text(iRow, jCol, 1, 1);
  109. }
  110. }
  111. }
  112. texts.sort(function(t1, t2){
  113. if (t1.col === t2.col) {
  114. return t1.row - t2.row;
  115. } else {
  116. return t1.col - t2.col;
  117. }
  118. });
  119. }
  120. }