rpt_tpl_vis_common.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /**
  2. * Created by Tony on 2018/9/4.
  3. */
  4. const BG_COLORS = ['#BFEFFF', '#C1FFC1', '#F5F5DC', '#B9D3EE', '#C1FFC1', '#EEE0E5', '#B4EEB4', '#CAE1FF', '#EED2EE', '#AEEEEE', '#76EEC6', '#CD8C95'],
  5. unitFactor = 1.0 * 96 / 2.54;
  6. let visualCommonOprObj = {
  7. getActPos: function (textNode, caclStr, typeStr, baseMea) {
  8. let rst = 0;
  9. if (caclStr === JV.CAL_TYPE[0]) {
  10. //percentage
  11. rst = Math.round(baseMea * textNode[JV.PROP_AREA][typeStr] / 100);
  12. } else {
  13. //abstract
  14. rst = Math.round(textNode[JV.PROP_AREA][typeStr] / 2.54 * 96);
  15. }
  16. return rst;
  17. },
  18. getActPosEx: function (textNode, caclObj, typeStr, baseMea) {
  19. let me = this;
  20. if (typeof caclObj === 'string') {
  21. return me.getActPos(textNode, caclObj, typeStr, baseMea);
  22. } else {
  23. return me.getActPos(textNode, caclObj[typeStr], typeStr, baseMea);
  24. }
  25. },
  26. pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) {
  27. let me = this, pos = me.getActPosEx(textNode, caclObj, typeStr, baseMea);
  28. if (posArr.indexOf(pos) < 0) posArr.push(pos);
  29. },
  30. getBandEx: function (bandName, rptTpl) {
  31. let me = this, rst;
  32. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  33. rst = me.getBand(bandName, band);
  34. if (rst !== null) {
  35. break;
  36. }
  37. }
  38. return rst;
  39. },
  40. getBand: function (bandName, parentBand) {
  41. let me = this, rst = null;
  42. if (parentBand[JV.PROP_NAME] === bandName) {
  43. rst = parentBand;
  44. } else {
  45. if (parentBand[JV.BAND_PROP_SUB_BANDS] && parentBand[JV.BAND_PROP_SUB_BANDS].length > 0) {
  46. for (let subBand of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  47. rst = me.getBand(bandName, subBand);
  48. if (rst !== null) {
  49. break;
  50. }
  51. }
  52. }
  53. }
  54. return rst;
  55. },
  56. checkInSpan: function (spans, row, col) {
  57. let rst = false;
  58. for (let span of spans) {
  59. if (span.row <= row && row < (span.row + span.rowCount) && span.col <= col && col < (span.col + span.colCount)) {
  60. rst = true;
  61. break;
  62. }
  63. }
  64. return rst;
  65. },
  66. setupHeightWidth: function (dest, text, colWidthArr, rowHeightArr) {
  67. let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
  68. dest[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
  69. if (text.col > 0) {
  70. dest[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
  71. } else {
  72. dest[JV.PROP_AREA][JV.PROP_LEFT] = 0;
  73. }
  74. dest[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2);
  75. if (text.row > 0) {
  76. dest[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2);
  77. } else {
  78. dest[JV.PROP_AREA][JV.PROP_TOP] = 0;
  79. }
  80. },
  81. createTxtNode: function (text, parentNode, colWidthArr, rowHeightArr) {
  82. let me = this, rst = dataInfoMapTreeOprObj.getDummyTextNode(parentNode);
  83. me.setupHeightWidth(rst, text, colWidthArr, rowHeightArr);
  84. if (stringUtil.isEmptyString(text[`text`])) {
  85. rst[JV.PROP_NAME] = '';
  86. } else {
  87. rst[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`].toString(), '\n', '|'), '\r', '');
  88. }
  89. rst[JV.PROP_LABEL] = rst[JV.PROP_NAME];
  90. return rst;
  91. },
  92. collectSheetTxt: function (sheet, texts, reserveRows, colWidthArr, rowHeightArr) {
  93. let me = this, spans= sheet.getSpans();
  94. let private_build_pre_text = function (row, col, rowCount, colCount) {
  95. let cell = sheet.getCell(row, col);
  96. let textValue = sheet.getValue(row, col);
  97. if (textValue && cell.cellType().typeName === '7') {
  98. textValue = `{` + textValue + `}`;
  99. }
  100. texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": textValue});
  101. };
  102. for (let span of spans) {
  103. private_build_pre_text(span.row, span.col, span.rowCount, span.colCount);
  104. }
  105. for (let iRow = 0; iRow < sheet.getRowCount() - reserveRows; iRow++) {
  106. rowHeightArr.push(sheet.getRowHeight(iRow));
  107. if (iRow > 0) {
  108. rowHeightArr[iRow] = rowHeightArr[iRow] + rowHeightArr[iRow - 1];
  109. }
  110. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  111. if (iRow === 0) {
  112. colWidthArr.push(sheet.getColumnWidth(jCol));
  113. if (jCol > 0) {
  114. colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1];
  115. }
  116. }
  117. if (!me.checkInSpan(spans, iRow, jCol)) {
  118. private_build_pre_text(iRow, jCol, 1, 1);
  119. }
  120. }
  121. }
  122. texts.sort(function(t1, t2){
  123. if (t1.col === t2.col) {
  124. return t1.row - t2.row;
  125. } else {
  126. return t1.col - t2.col;
  127. }
  128. });
  129. },
  130. addSpan: function (itemNode, sheet, bandW, bandH, xPos, yPos, sheetAreaType) {
  131. let me = this;
  132. let idx1 = xPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW));
  133. let idx2 = xPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW));
  134. let idy1 = yPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH));
  135. let idy2 = yPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH));
  136. if (idx2 - idx1 > 1 || idy2 - idy1 > 1) {
  137. sheet.addSpan(idy1, idx1, idy2 - idy1, idx2 - idx1, sheetAreaType);
  138. }
  139. let cell = sheet.getCell(idy1, idx1, sheetAreaType);
  140. if (sheetAreaType === GC.Spread.Sheets.SheetArea.viewport) {
  141. if (itemNode.FieldID) {
  142. me.changeCellType(cell, 'field');
  143. } else {
  144. me.changeCellType(cell, 'text');
  145. }
  146. }
  147. me.setupCell(cell, itemNode);
  148. },
  149. changeBandHeight: function (bandName, newHeight) {
  150. let nodes = bandTreeOprObj.treeObj.getNodes()[0][JV.BAND_PROP_SUB_BANDS];
  151. let private_set_band_height = function(bNode) {
  152. let rst = false;
  153. if (bNode[JV.PROP_NAME] === bandName) {
  154. bNode[JV.BAND_PROP_HEIGHT] = newHeight;
  155. rst = true;
  156. } else if (bNode[JV.BAND_PROP_SUB_BANDS] && bNode[JV.BAND_PROP_SUB_BANDS].length > 0){
  157. for (let subNode of bNode[JV.BAND_PROP_SUB_BANDS]) {
  158. rst = private_set_band_height(subNode);
  159. if (rst) break;
  160. }
  161. }
  162. return rst;
  163. };
  164. for (let bandNode of nodes) {
  165. if (private_set_band_height(bandNode)) break;
  166. }
  167. },
  168. changeCellType: function (cell, newType, newColor) {
  169. let me = this;
  170. switch (newType) {
  171. case `field`:
  172. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  173. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  174. // let selectableFields = me.getSelectedFields(rptTpl);
  175. let selectableFields = me.getAllSelectedFields(rptTpl);
  176. cellType.items(selectableFields);
  177. cell.cellType(cellType);
  178. if (newColor) {
  179. cell.backColor(newColor);
  180. } else {
  181. cell.backColor("LightCyan");
  182. }
  183. break;
  184. case `text`:
  185. default:
  186. cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
  187. cell.value(``);
  188. if (newColor) {
  189. cell.backColor(newColor);
  190. } else {
  191. cell.backColor(undefined);
  192. }
  193. break;
  194. }
  195. },
  196. setupCell: function (cell, itemNode) {
  197. let me = this;
  198. me.private_setCellFont(cell, itemNode);
  199. me.private_setCellControl(cell, itemNode);
  200. // let border = new GC.Spread.Sheets.LineBorder;
  201. // border.color = "Black";
  202. // border.style = GC.Spread.Sheets.LineStyle.thin;
  203. // me.private_setCellStyle(cell, itemNode, border);
  204. let value = itemNode[JV.PROP_NAME];
  205. if (itemNode[JV.PROP_NAME].indexOf(`|`) >= 0) {
  206. value = itemNode[JV.PROP_NAME].split('|').join('\n');
  207. }
  208. cell.wordWrap(true);
  209. cell.value(value);
  210. },
  211. private_setCellControl: function (cell, textNode) {
  212. let ctrl = null;
  213. if (typeof textNode[JV.PROP_CONTROL] === 'string') {
  214. let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(textNode[JV.PROP_CONTROL]);
  215. ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
  216. } else {
  217. ctrl = textNode[JV.PROP_CONTROL];
  218. }
  219. if (ctrl) {
  220. switch (ctrl.Horizon) {
  221. case `center`:
  222. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  223. break;
  224. case `right`:
  225. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  226. break;
  227. default:
  228. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  229. break;
  230. }
  231. switch (ctrl.Vertical) {
  232. case `center`:
  233. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  234. break;
  235. case `bottom`:
  236. cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  237. break;
  238. default:
  239. cell.vAlign(GC.Spread.Sheets.VerticalAlign.top);
  240. break;
  241. }
  242. }
  243. },
  244. private_setCellStyle: function (cell, textNode, border) {
  245. let style;
  246. if (typeof textNode[JV.PROP_STYLE] === 'string') {
  247. let idx = rpt_tpl_cfg_helper.reportCfg.borderArr.indexOf(textNode[JV.PROP_STYLE]);
  248. style = rpt_tpl_cfg_helper.reportCfg.styles[idx];
  249. } else {
  250. style = textNode[JV.PROP_STYLE];
  251. }
  252. if (style) {
  253. for (let borderStyle of style[JV.PROP_BORDER_STYLE]) {
  254. if (parseFloat(borderStyle[JV.PROP_LINE_WEIGHT]) > 0) {
  255. switch (borderStyle[JV.PROP_POSITION]) {
  256. case JV.PROP_LEFT:
  257. cell.borderLeft(border);
  258. break;
  259. case JV.PROP_RIGHT:
  260. cell.borderRight(border);
  261. break;
  262. case JV.PROP_TOP:
  263. cell.borderTop(border);
  264. break;
  265. case JV.PROP_BOTTOM:
  266. cell.borderBottom(border);
  267. break;
  268. default:
  269. break;
  270. }
  271. }
  272. }
  273. }
  274. },
  275. private_setCellFont: function (cell, textNode) {
  276. for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
  277. if (font.ID === textNode[JV.PROP_FONT]) {
  278. cell.font(Math.round(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]] * 3 / 4) + 'pt ' + font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]]);
  279. break;
  280. }
  281. }
  282. },
  283. getSelectedFields: function (rptTpl) {
  284. let rst = [];
  285. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  286. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  287. rst.push(field[JV.PROP_NAME]);
  288. }
  289. }
  290. if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  291. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  292. rst.push(field[JV.PROP_NAME]);
  293. }
  294. }
  295. return rst;
  296. },
  297. getAllSelectedFields: function (rptTpl) {
  298. let rst = [];
  299. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  300. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  301. rst.push(field[JV.PROP_NAME]);
  302. }
  303. }
  304. if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  305. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  306. rst.push(field[JV.PROP_NAME]);
  307. }
  308. }
  309. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS].length > 0) {
  310. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]) {
  311. rst.push(field[JV.PROP_NAME]);
  312. }
  313. }
  314. if (rptTpl[JV.NODE_DISCRETE_PARAMS] !== undefined && rptTpl[JV.NODE_DISCRETE_PARAMS].length > 0) {
  315. for (let field of rptTpl[JV.NODE_DISCRETE_PARAMS]) {
  316. rst.push(field[JV.PROP_NAME]);
  317. }
  318. }
  319. return rst;
  320. },
  321. setupCellDft: function (cell) {
  322. cell.font(`9pt 宋体`);
  323. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  324. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  325. cell.wordWrap(true);
  326. cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
  327. cell.value(``);
  328. },
  329. addBandPos: function (rptTpl, pageW, pageH, xPos, yPos, bandMappingObj) {
  330. let left = 0, right = pageW, top = 0, bottom = pageH;
  331. let orgArea = [left, top, right, bottom];
  332. let colorIdx = 0;
  333. bandMappingObj.items = [];
  334. let private_setup_pos = function (band) {
  335. left = orgArea[JV.IDX_LEFT];
  336. top = orgArea[JV.IDX_TOP];
  337. right = orgArea[JV.IDX_RIGHT];
  338. bottom = orgArea[JV.IDX_BOTTOM];
  339. if (xPos.indexOf(left) < 0) xPos.push(left);
  340. if (xPos.indexOf(right) < 0) xPos.push(right);
  341. if (yPos.indexOf(top) < 0) yPos.push(top);
  342. if (yPos.indexOf(bottom) < 0) yPos.push(bottom);
  343. switch (band[JV.BAND_PROP_ALIGNMENT]) {
  344. case JV.LAYOUT_TOP:
  345. case JV.LAYOUT[JV.LAYOUT_TOP]:
  346. bottom = Math.round(top + unitFactor * band[JV.BAND_PROP_HEIGHT]);
  347. orgArea[JV.IDX_TOP] = bottom;
  348. break;
  349. case JV.LAYOUT_BOTTOM:
  350. case JV.LAYOUT[JV.LAYOUT_BOTTOM]:
  351. top = Math.round(bottom - unitFactor * band[JV.BAND_PROP_HEIGHT]);
  352. orgArea[JV.IDX_BOTTOM] = top;
  353. break;
  354. case JV.LAYOUT_LEFT:
  355. case JV.LAYOUT[JV.LAYOUT_LEFT]:
  356. right = Math.round(left + unitFactor * band[JV.BAND_PROP_WIDTH]);
  357. orgArea[JV.IDX_LEFT] = right;
  358. break;
  359. case JV.LAYOUT_RIGHT:
  360. case JV.LAYOUT[JV.LAYOUT_RIGHT]:
  361. left = Math.round(right - unitFactor * band[JV.BAND_PROP_WIDTH]);
  362. orgArea[JV.IDX_RIGHT] = left;
  363. break;
  364. }
  365. let item = {};
  366. bandMappingObj[band[JV.PROP_NAME]] = item;
  367. item[JV.PROP_BAND_NAME] = band[JV.PROP_NAME];
  368. item[JV.PROP_AREA] = {};
  369. item[JV.PROP_AREA][JV.PROP_LEFT] = left;
  370. item[JV.PROP_AREA][JV.PROP_RIGHT] = right;
  371. item[JV.PROP_AREA][JV.PROP_TOP] = top;
  372. item[JV.PROP_AREA][JV.PROP_BOTTOM] = bottom;
  373. item[JV.PROP_COLOR] = BG_COLORS[colorIdx];
  374. // item[JV.PROP_COLOR] = 'Blue';
  375. bandMappingObj.items.push(item);
  376. colorIdx++;
  377. if (xPos.indexOf(left) < 0) xPos.push(left);
  378. if (xPos.indexOf(right) < 0) xPos.push(right);
  379. if (yPos.indexOf(top) < 0) yPos.push(top);
  380. if (yPos.indexOf(bottom) < 0) yPos.push(bottom);
  381. if (colorIdx >= BG_COLORS.length) colorIdx = 0;
  382. if (band[JV.BAND_PROP_SUB_BANDS] && band[JV.BAND_PROP_SUB_BANDS].length > 0) {
  383. item[JV.PROP_COLOR] = 'White';
  384. // item[JV.PROP_COLOR] = null;
  385. for (let subBand of band[JV.BAND_PROP_SUB_BANDS]) {
  386. private_setup_pos(subBand);
  387. }
  388. }
  389. };
  390. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  391. private_setup_pos(band);
  392. }
  393. },
  394. pushAbsPos: function (bandMap, itemNode, xPos, yPos) {
  395. let me = this;
  396. if (bandMap) {
  397. let bandW = bandMap[JV.PROP_AREA][JV.PROP_RIGHT] - bandMap[JV.PROP_AREA][JV.PROP_LEFT],
  398. bandH = bandMap[JV.PROP_AREA][JV.PROP_BOTTOM] - bandMap[JV.PROP_AREA][JV.PROP_TOP];
  399. let pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  400. if (xPos.indexOf(pos) < 0) xPos.push(pos);
  401. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  402. if (xPos.indexOf(pos) < 0) xPos.push(pos);
  403. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  404. if (yPos.indexOf(pos) < 0) yPos.push(pos);
  405. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  406. if (yPos.indexOf(pos) < 0) yPos.push(pos);
  407. }
  408. },
  409. addTplTxtFldPos: function (rptTpl, tree, xPos, yPos, bandMappingObj) {
  410. let me = this, nodes = tree.getNodes();
  411. if (rptTpl[JV.NODE_FLOW_INFO]) {
  412. //流水式
  413. let contentBandMap, contentRowH, orgContentTop, lastContentBottom;
  414. for (let node of nodes) {
  415. if (node[JV.PROP_NAME].indexOf('_列') >= 0) {
  416. //1. 列
  417. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  418. me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  419. bandMap[JV.PROP_COLOR] = 'LightGray';
  420. } else if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  421. //2. 数据
  422. contentBandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  423. contentRowH = Math.round(unitFactor * rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_CMN_HEIGHT]);
  424. orgContentTop = contentBandMap[JV.PROP_AREA][JV.PROP_TOP];
  425. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  426. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  427. lastContentBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  428. if (node.items.length === 0) {
  429. if (yPos.indexOf(contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH) < 0) {
  430. yPos.push(contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH);
  431. }
  432. } else {
  433. me.addNormalTxtFldPos(contentBandMap, node, xPos, yPos);
  434. }
  435. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  436. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  437. contentBandMap[JV.PROP_COLOR] = 'LightCyan';
  438. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0) {
  439. //3. 页统计
  440. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  441. for (let itemNode of node.items) {
  442. me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  443. }
  444. } else if (node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  445. //4. 章统计
  446. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  447. for (let itemNode of node.items) {
  448. me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  449. }
  450. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  451. //5. 分组统计
  452. if (contentBandMap && contentRowH && node.items && node.items.length > 0) {
  453. for (let itemNode of node.items) {
  454. if (itemNode[JV.PROP_NAME] === `分组行`) {
  455. if (itemNode.items) {
  456. for (let subItemNode of itemNode.items) {
  457. //行
  458. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  459. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  460. lastContentBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  461. for (let txtFldNode of subItemNode.items) {
  462. //分组字段集 与 文本集
  463. me.addNormalTxtFldPos(contentBandMap, txtFldNode, xPos, yPos);
  464. }
  465. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  466. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  467. }
  468. }
  469. }
  470. }
  471. }
  472. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  473. //6. 离散信息
  474. me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  475. }
  476. }
  477. if (contentBandMap) {
  478. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = orgContentTop;
  479. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = lastContentBottom;
  480. }
  481. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  482. //账单式
  483. for (let node of nodes) {
  484. if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  485. //1. 数据
  486. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  487. me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  488. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  489. //2. 离散信息
  490. me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  491. }
  492. }
  493. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  494. //交叉式
  495. //目前暂缓
  496. }
  497. },
  498. setupTplTxtFld: function (rptTpl, tree, sheet, xPos, yPos, bandMappingObj) {
  499. let me = this, nodes = tree.getNodes();
  500. bandMappingObj.fontAttr = {};
  501. if (rptTpl[JV.NODE_FLOW_INFO]) {
  502. //流水式
  503. let contentBandMap, contentRowH;
  504. for (let node of nodes) {
  505. if (node[JV.PROP_NAME].indexOf('_列') >= 0) {
  506. //1. 列
  507. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  508. // me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  509. me.addSpanWholeArea(bandMappingObj, bandMap, node, sheet, xPos, yPos);
  510. } else if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  511. //2. 数据
  512. contentBandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  513. contentRowH = Math.round(unitFactor * rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_CMN_HEIGHT]);
  514. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  515. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  516. // me.addNormalTxtFldPos(contentBandMap, node, xPos, yPos);
  517. me.addSpanWholeArea(bandMappingObj, contentBandMap, node, sheet, xPos, yPos);
  518. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  519. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  520. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0) {
  521. //3. 页统计
  522. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  523. for (let itemNode of node.items) {
  524. // me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  525. me.addSpanWholeArea(bandMappingObj, bandMap, itemNode, sheet, xPos, yPos);
  526. }
  527. } else if (node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  528. //4. 章统计
  529. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  530. for (let itemNode of node.items) {
  531. // me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  532. me.addSpanWholeArea(bandMappingObj, bandMap, itemNode, sheet, xPos, yPos);
  533. }
  534. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  535. //5. 分组统计
  536. if (contentBandMap && contentRowH && node.items && node.items.length > 0) {
  537. for (let itemNode of node.items) {
  538. if (itemNode[JV.PROP_NAME] === `分组行`) {
  539. if (itemNode.items) {
  540. for (let subItemNode of itemNode.items) {
  541. //行
  542. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  543. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  544. for (let txtFldNode of subItemNode.items) {
  545. //分组字段集 与 文本集
  546. // me.addNormalTxtFldPos(contentBandMap, txtFldNode, xPos, yPos);
  547. me.addSpanWholeArea(bandMappingObj, contentBandMap, txtFldNode, sheet, xPos, yPos);
  548. }
  549. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  550. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  551. }
  552. }
  553. }
  554. }
  555. }
  556. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  557. //6. 离散信息
  558. // me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  559. me.addDiscreteSpan(node, xPos, yPos, bandMappingObj, sheet);
  560. }
  561. }
  562. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  563. //账单式
  564. for (let node of nodes) {
  565. if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  566. //1. 数据
  567. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  568. me.addSpanWholeArea(bandMappingObj, bandMap, node, sheet, xPos, yPos);
  569. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  570. //2. 离散信息
  571. me.addDiscreteSpan(node, xPos, yPos, bandMappingObj, sheet);
  572. }
  573. }
  574. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  575. //交叉式
  576. //目前暂缓
  577. }
  578. },
  579. brushSheet: function (bandMappingObj, sheet, xPos, yPos) {
  580. for (let bandMap of bandMappingObj.items) {
  581. let idxTop = yPos.indexOf(bandMap[JV.PROP_AREA][JV.PROP_TOP]);
  582. let idxBottom = yPos.indexOf(bandMap[JV.PROP_AREA][JV.PROP_BOTTOM]);
  583. if (idxTop >= 0 && idxBottom > idxTop) {
  584. sheet.getRange(idxTop, -1, idxBottom - idxTop, -1).backColor(bandMap[JV.PROP_COLOR]);
  585. let range = sheet.getRange(idxTop, -1, idxBottom - idxTop, -1);
  586. if (bandMap[JV.PROP_COLOR] === 'White') {
  587. range.watermark("[Not Editable]");
  588. } else {
  589. range.watermark(undefined);
  590. }
  591. }
  592. }
  593. },
  594. addDiscreteTxtFldPos: function (discreteItemNode, xPos, yPos, bandMappingObj) {
  595. let me = this;
  596. if (discreteItemNode.items) {
  597. for (let itemNode of discreteItemNode.items) {
  598. //子项
  599. let bandMap = bandMappingObj[itemNode[JV.PROP_BAND_NAME]];
  600. if (bandMap) {
  601. for (let subItemNode of itemNode.items) {
  602. for (let txtFldDtlNode of subItemNode.items) {
  603. me.pushAbsPos(bandMap, txtFldDtlNode, xPos, yPos);
  604. }
  605. }
  606. }
  607. }
  608. }
  609. },
  610. addNormalTxtFldPos: function (bandMap, parentNode, xPos, yPos) {
  611. let me = this;
  612. if (bandMap && parentNode.items && parentNode.items.length > 0) {
  613. for (let itemNode of parentNode.items) {
  614. me.pushAbsPos(bandMap, itemNode, xPos, yPos);
  615. }
  616. }
  617. },
  618. addSpanWholeArea: function (bandMappingObj, bandMap, parentNode, sheet, xPos, yPos) {
  619. let me = this;
  620. if (bandMap && parentNode.items && parentNode.items.length > 0) {
  621. let bandW = bandMap[JV.PROP_AREA][JV.PROP_RIGHT] - bandMap[JV.PROP_AREA][JV.PROP_LEFT],
  622. bandH = bandMap[JV.PROP_AREA][JV.PROP_BOTTOM] - bandMap[JV.PROP_AREA][JV.PROP_TOP];
  623. for (let itemNode of parentNode.items) {
  624. // me.pushAbsPos(bandMap, itemNode, xPos, yPos);
  625. let pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  626. let idxLeft = xPos.indexOf(pos);
  627. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  628. let idxRight = xPos.indexOf(pos);
  629. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  630. let idxTop = yPos.indexOf(pos);
  631. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  632. let idxBottom = yPos.indexOf(pos);
  633. if (idxRight - idxLeft > 1 || idxBottom - idxTop > 1) {
  634. sheet.addSpan(idxTop, idxLeft, idxBottom - idxTop, idxRight - idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  635. }
  636. let cell = sheet.getCell(idxTop, idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  637. if (itemNode.FieldID || itemNode.ParamID) {
  638. me.changeCellType(cell, 'field', bandMap[JV.PROP_COLOR]);
  639. } else {
  640. me.changeCellType(cell, 'text', bandMap[JV.PROP_COLOR]);
  641. }
  642. bandMappingObj.fontAttr[idxTop + "_" + idxLeft + "_font"] = itemNode[JV.PROP_FONT];
  643. me.setupCell(cell, itemNode);
  644. if ((itemNode.FieldID || itemNode.ParamID) && itemNode[JV.PROP_IS_AUTO_HEIGHT]) {
  645. let value = cell.value();
  646. cell.value(`{` + value + `}`);
  647. }
  648. //*
  649. let border = new GC.Spread.Sheets.LineBorder;
  650. border.color = "Black";
  651. border.style = GC.Spread.Sheets.LineStyle.thin;
  652. for (let iRow = 0; iRow < idxBottom - idxTop; iRow++) {
  653. for (let iCol = 0; iCol < idxRight - idxLeft; iCol++) {
  654. let cl = sheet.getCell(iRow + idxTop, iCol + idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  655. me.private_setCellStyle(cl, itemNode, border);
  656. }
  657. }
  658. //*/
  659. }
  660. }
  661. },
  662. addDiscreteSpan: function (discreteItemNode, xPos, yPos, bandMappingObj, sheet) {
  663. let me = this;
  664. if (discreteItemNode.items) {
  665. for (let itemNode of discreteItemNode.items) {
  666. //子项
  667. let bandMap = bandMappingObj[itemNode[JV.PROP_BAND_NAME]];
  668. if (bandMap) {
  669. for (let subItemNode of itemNode.items) {
  670. me.addSpanWholeArea(bandMappingObj, bandMap, subItemNode, sheet, xPos, yPos);
  671. }
  672. }
  673. }
  674. }
  675. },
  676. setupBorder: function (cell, border) {
  677. cell.borderLeft(border);
  678. cell.borderRight(border);
  679. cell.borderTop(border);
  680. cell.borderBottom(border);
  681. },
  682. copyPropertiesForSplittedCell: function (srcCell, destCell) {
  683. //1. font
  684. destCell.font(srcCell.font());
  685. //2. bk color
  686. destCell.backColor(srcCell.backColor());
  687. //3. border
  688. destCell.borderLeft(srcCell.borderLeft());
  689. destCell.borderRight(srcCell.borderRight());
  690. destCell.borderTop(srcCell.borderTop());
  691. destCell.borderBottom(srcCell.borderBottom());
  692. }
  693. };