rpt_tpl_vis_common.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /**
  2. * Created by Tony on 2018/9/4.
  3. */
  4. const BG_COLORS = ['#BFEFFF', '#C1FFC1', '#F5F5DC', '#B9D3EE', '#F0FFFF', '#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. let fontAttr;
  277. if (typeof textNode[JV.PROP_FONT] === 'string') {
  278. for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
  279. if (font.ID === textNode[JV.PROP_FONT]) {
  280. fontAttr = font;
  281. // 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]]);
  282. break;
  283. }
  284. }
  285. } else {
  286. fontAttr = textNode[JV.PROP_FONT];
  287. }
  288. let fontStr = "";
  289. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]])) {
  290. fontStr = 'bold ' + fontStr;
  291. }
  292. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]])) {
  293. fontStr = 'italic ' + fontStr;
  294. }
  295. fontStr = fontStr + Math.round(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]] * 3 / 4) + 'pt ' + fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]];
  296. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]])) {
  297. cell.textDecoration(GC.Spread.Sheets.TextDecorationType.underline);
  298. } else {
  299. cell.textDecoration(GC.Spread.Sheets.TextDecorationType.none);
  300. }
  301. cell.font(fontStr);
  302. },
  303. getSelectedFields: function (rptTpl) {
  304. let rst = [];
  305. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  306. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  307. rst.push(field[JV.PROP_NAME]);
  308. }
  309. }
  310. if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  311. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  312. rst.push(field[JV.PROP_NAME]);
  313. }
  314. }
  315. return rst;
  316. },
  317. getAllSelectedFields: function (rptTpl) {
  318. let rst = [];
  319. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  320. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  321. rst.push(field[JV.PROP_NAME]);
  322. }
  323. }
  324. if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  325. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  326. rst.push(field[JV.PROP_NAME]);
  327. }
  328. }
  329. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS].length > 0) {
  330. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]) {
  331. rst.push(field[JV.PROP_NAME]);
  332. }
  333. }
  334. if (rptTpl[JV.NODE_DISCRETE_PARAMS] !== undefined && rptTpl[JV.NODE_DISCRETE_PARAMS].length > 0) {
  335. for (let field of rptTpl[JV.NODE_DISCRETE_PARAMS]) {
  336. rst.push(field[JV.PROP_NAME]);
  337. }
  338. }
  339. return rst;
  340. },
  341. setupCellDft: function (cell) {
  342. cell.font(`9pt 宋体`);
  343. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  344. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  345. cell.wordWrap(true);
  346. cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
  347. cell.value(``);
  348. },
  349. addBandPos: function (rptTpl, pageW, pageH, xPos, yPos, bandMappingObj) {
  350. let left = 0, right = pageW, top = 0, bottom = pageH;
  351. let orgArea = [left, top, right, bottom];
  352. let colorIdx = 0;
  353. bandMappingObj.items = [];
  354. let private_setup_pos = function (band) {
  355. left = orgArea[JV.IDX_LEFT];
  356. top = orgArea[JV.IDX_TOP];
  357. right = orgArea[JV.IDX_RIGHT];
  358. bottom = orgArea[JV.IDX_BOTTOM];
  359. if (xPos.indexOf(left) < 0) xPos.push(left);
  360. if (xPos.indexOf(right) < 0) xPos.push(right);
  361. if (yPos.indexOf(top) < 0) yPos.push(top);
  362. if (yPos.indexOf(bottom) < 0) yPos.push(bottom);
  363. switch (band[JV.BAND_PROP_ALIGNMENT]) {
  364. case JV.LAYOUT_TOP:
  365. case JV.LAYOUT[JV.LAYOUT_TOP]:
  366. bottom = Math.round(top + unitFactor * band[JV.BAND_PROP_HEIGHT]);
  367. orgArea[JV.IDX_TOP] = bottom;
  368. break;
  369. case JV.LAYOUT_BOTTOM:
  370. case JV.LAYOUT[JV.LAYOUT_BOTTOM]:
  371. top = Math.round(bottom - unitFactor * band[JV.BAND_PROP_HEIGHT]);
  372. orgArea[JV.IDX_BOTTOM] = top;
  373. break;
  374. case JV.LAYOUT_LEFT:
  375. case JV.LAYOUT[JV.LAYOUT_LEFT]:
  376. right = Math.round(left + unitFactor * band[JV.BAND_PROP_WIDTH]);
  377. orgArea[JV.IDX_LEFT] = right;
  378. break;
  379. case JV.LAYOUT_RIGHT:
  380. case JV.LAYOUT[JV.LAYOUT_RIGHT]:
  381. left = Math.round(right - unitFactor * band[JV.BAND_PROP_WIDTH]);
  382. orgArea[JV.IDX_RIGHT] = left;
  383. break;
  384. }
  385. let item = {};
  386. bandMappingObj[band[JV.PROP_NAME]] = item;
  387. item[JV.PROP_BAND_NAME] = band[JV.PROP_NAME];
  388. item[JV.PROP_AREA] = {};
  389. item[JV.PROP_AREA][JV.PROP_LEFT] = left;
  390. item[JV.PROP_AREA][JV.PROP_RIGHT] = right;
  391. item[JV.PROP_AREA][JV.PROP_TOP] = top;
  392. item[JV.PROP_AREA][JV.PROP_BOTTOM] = bottom;
  393. item[JV.PROP_COLOR] = BG_COLORS[colorIdx];
  394. // item[JV.PROP_COLOR] = 'Blue';
  395. bandMappingObj.items.push(item);
  396. colorIdx++;
  397. if (xPos.indexOf(left) < 0) xPos.push(left);
  398. if (xPos.indexOf(right) < 0) xPos.push(right);
  399. if (yPos.indexOf(top) < 0) yPos.push(top);
  400. if (yPos.indexOf(bottom) < 0) yPos.push(bottom);
  401. if (colorIdx >= BG_COLORS.length) colorIdx = 0;
  402. if (band[JV.BAND_PROP_SUB_BANDS] && band[JV.BAND_PROP_SUB_BANDS].length > 0) {
  403. item[JV.PROP_COLOR] = 'White';
  404. // item[JV.PROP_COLOR] = null;
  405. for (let subBand of band[JV.BAND_PROP_SUB_BANDS]) {
  406. private_setup_pos(subBand);
  407. }
  408. }
  409. };
  410. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  411. private_setup_pos(band);
  412. }
  413. },
  414. pushAbsPos: function (bandMap, itemNode, xPos, yPos) {
  415. let me = this;
  416. if (bandMap) {
  417. let bandW = bandMap[JV.PROP_AREA][JV.PROP_RIGHT] - bandMap[JV.PROP_AREA][JV.PROP_LEFT],
  418. bandH = bandMap[JV.PROP_AREA][JV.PROP_BOTTOM] - bandMap[JV.PROP_AREA][JV.PROP_TOP];
  419. let pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  420. if (xPos.indexOf(pos) < 0) xPos.push(pos);
  421. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  422. if (xPos.indexOf(pos) < 0) xPos.push(pos);
  423. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  424. if (yPos.indexOf(pos) < 0) yPos.push(pos);
  425. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  426. if (yPos.indexOf(pos) < 0) yPos.push(pos);
  427. }
  428. },
  429. addTplTxtFldPos: function (rptTpl, tree, xPos, yPos, bandMappingObj) {
  430. let me = this, nodes = tree.getNodes();
  431. if (rptTpl[JV.NODE_FLOW_INFO]) {
  432. //流水式
  433. let contentBandMap, contentRowH, orgContentTop, lastContentBottom;
  434. for (let node of nodes) {
  435. if (node[JV.PROP_NAME].indexOf('_列') >= 0) {
  436. //1. 列
  437. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  438. me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  439. bandMap[JV.PROP_COLOR] = 'LightGray';
  440. } else if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  441. //2. 数据
  442. contentBandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  443. contentRowH = Math.round(unitFactor * rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_CMN_HEIGHT]);
  444. orgContentTop = contentBandMap[JV.PROP_AREA][JV.PROP_TOP];
  445. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  446. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  447. lastContentBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  448. if (node.items.length === 0) {
  449. if (yPos.indexOf(contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH) < 0) {
  450. yPos.push(contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH);
  451. }
  452. } else {
  453. me.addNormalTxtFldPos(contentBandMap, node, xPos, yPos);
  454. }
  455. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  456. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  457. contentBandMap[JV.PROP_COLOR] = 'LightCyan';
  458. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0) {
  459. //3. 页统计
  460. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  461. for (let itemNode of node.items) {
  462. me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  463. }
  464. } else if (node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  465. //4. 章统计
  466. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  467. for (let itemNode of node.items) {
  468. me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  469. }
  470. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  471. //5. 分组统计
  472. if (contentBandMap && contentRowH && node.items && node.items.length > 0) {
  473. for (let itemNode of node.items) {
  474. if (itemNode[JV.PROP_NAME] === `分组行`) {
  475. if (itemNode.items) {
  476. for (let subItemNode of itemNode.items) {
  477. //行
  478. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  479. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  480. lastContentBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  481. for (let txtFldNode of subItemNode.items) {
  482. //分组字段集 与 文本集
  483. me.addNormalTxtFldPos(contentBandMap, txtFldNode, xPos, yPos);
  484. }
  485. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  486. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  487. }
  488. }
  489. }
  490. }
  491. }
  492. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  493. //6. 离散信息
  494. me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  495. }
  496. }
  497. if (contentBandMap) {
  498. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = orgContentTop;
  499. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = lastContentBottom;
  500. }
  501. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  502. //账单式
  503. for (let node of nodes) {
  504. if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  505. //1. 数据
  506. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  507. me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  508. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  509. //2. 离散信息
  510. me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  511. }
  512. }
  513. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  514. //交叉式
  515. //目前暂缓
  516. }
  517. },
  518. setupTplTxtFld: function (rptTpl, tree, sheet, xPos, yPos, bandMappingObj) {
  519. let me = this, nodes = tree.getNodes();
  520. bandMappingObj.fontAttr = {};
  521. bandMappingObj.fieldPreSufAttr = {};
  522. if (rptTpl[JV.NODE_FLOW_INFO]) {
  523. //流水式
  524. let contentBandMap, contentRowH;
  525. for (let node of nodes) {
  526. if (node[JV.PROP_NAME].indexOf('_列') >= 0) {
  527. //1. 列
  528. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  529. // me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  530. me.addSpanWholeArea(bandMappingObj, bandMap, node, sheet, xPos, yPos);
  531. } else if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  532. //2. 数据
  533. contentBandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  534. contentRowH = Math.round(unitFactor * rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_CMN_HEIGHT]);
  535. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  536. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  537. // me.addNormalTxtFldPos(contentBandMap, node, xPos, yPos);
  538. me.addSpanWholeArea(bandMappingObj, contentBandMap, node, sheet, xPos, yPos);
  539. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  540. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  541. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0) {
  542. //3. 页统计
  543. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  544. for (let itemNode of node.items) {
  545. // me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  546. me.addSpanWholeArea(bandMappingObj, bandMap, itemNode, sheet, xPos, yPos);
  547. }
  548. } else if (node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  549. //4. 章统计
  550. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  551. for (let itemNode of node.items) {
  552. // me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  553. me.addSpanWholeArea(bandMappingObj, bandMap, itemNode, sheet, xPos, yPos);
  554. }
  555. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  556. //5. 分组统计
  557. if (contentBandMap && contentRowH && node.items && node.items.length > 0) {
  558. for (let itemNode of node.items) {
  559. if (itemNode[JV.PROP_NAME] === `分组行`) {
  560. if (itemNode.items) {
  561. for (let subItemNode of itemNode.items) {
  562. //行
  563. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  564. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  565. for (let txtFldNode of subItemNode.items) {
  566. //分组字段集 与 文本集
  567. // me.addNormalTxtFldPos(contentBandMap, txtFldNode, xPos, yPos);
  568. me.addSpanWholeArea(bandMappingObj, contentBandMap, txtFldNode, sheet, xPos, yPos);
  569. }
  570. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  571. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  572. }
  573. }
  574. }
  575. }
  576. }
  577. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  578. //6. 离散信息
  579. // me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  580. me.addDiscreteSpan(node, xPos, yPos, bandMappingObj, sheet);
  581. }
  582. }
  583. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  584. //账单式
  585. for (let node of nodes) {
  586. if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  587. //1. 数据
  588. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  589. me.addSpanWholeArea(bandMappingObj, bandMap, node, sheet, xPos, yPos);
  590. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  591. //2. 离散信息
  592. me.addDiscreteSpan(node, xPos, yPos, bandMappingObj, sheet);
  593. }
  594. }
  595. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  596. //交叉式
  597. //目前暂缓
  598. }
  599. },
  600. brushSheet: function (bandMappingObj, sheet, xPos, yPos) {
  601. for (let bandMap of bandMappingObj.items) {
  602. let idxTop = yPos.indexOf(bandMap[JV.PROP_AREA][JV.PROP_TOP]);
  603. let idxBottom = yPos.indexOf(bandMap[JV.PROP_AREA][JV.PROP_BOTTOM]);
  604. if (idxTop >= 0 && idxBottom > idxTop) {
  605. sheet.getRange(idxTop, -1, idxBottom - idxTop, -1).backColor(bandMap[JV.PROP_COLOR]);
  606. let range = sheet.getRange(idxTop, -1, idxBottom - idxTop, -1);
  607. if (bandMap[JV.PROP_COLOR] === 'White') {
  608. range.watermark("[Not Editable]");
  609. } else {
  610. range.watermark(undefined);
  611. }
  612. }
  613. }
  614. },
  615. addDiscreteTxtFldPos: function (discreteItemNode, xPos, yPos, bandMappingObj) {
  616. let me = this;
  617. if (discreteItemNode.items) {
  618. for (let itemNode of discreteItemNode.items) {
  619. //子项
  620. let bandMap = bandMappingObj[itemNode[JV.PROP_BAND_NAME]];
  621. if (bandMap) {
  622. for (let subItemNode of itemNode.items) {
  623. for (let txtFldDtlNode of subItemNode.items) {
  624. me.pushAbsPos(bandMap, txtFldDtlNode, xPos, yPos);
  625. }
  626. }
  627. }
  628. }
  629. }
  630. },
  631. addNormalTxtFldPos: function (bandMap, parentNode, xPos, yPos) {
  632. let me = this;
  633. if (bandMap && parentNode.items && parentNode.items.length > 0) {
  634. for (let itemNode of parentNode.items) {
  635. me.pushAbsPos(bandMap, itemNode, xPos, yPos);
  636. }
  637. }
  638. },
  639. addSpanWholeArea: function (bandMappingObj, bandMap, parentNode, sheet, xPos, yPos) {
  640. let me = this;
  641. if (bandMap && parentNode.items && parentNode.items.length > 0) {
  642. let bandW = bandMap[JV.PROP_AREA][JV.PROP_RIGHT] - bandMap[JV.PROP_AREA][JV.PROP_LEFT],
  643. bandH = bandMap[JV.PROP_AREA][JV.PROP_BOTTOM] - bandMap[JV.PROP_AREA][JV.PROP_TOP];
  644. for (let itemNode of parentNode.items) {
  645. // me.pushAbsPos(bandMap, itemNode, xPos, yPos);
  646. let pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  647. let idxLeft = xPos.indexOf(pos);
  648. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  649. let idxRight = xPos.indexOf(pos);
  650. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  651. let idxTop = yPos.indexOf(pos);
  652. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  653. let idxBottom = yPos.indexOf(pos);
  654. if (idxRight - idxLeft > 1 || idxBottom - idxTop > 1) {
  655. sheet.addSpan(idxTop, idxLeft, idxBottom - idxTop, idxRight - idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  656. }
  657. let cell = sheet.getCell(idxTop, idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  658. if (itemNode.FieldID || itemNode.ParamID) {
  659. me.changeCellType(cell, 'field', bandMap[JV.PROP_COLOR]);
  660. let fpsAttr = me.createDftFieldPreSuf();
  661. bandMappingObj.fieldPreSufAttr[idxTop + "_" + idxLeft + "_fieldPreSuf"] = fpsAttr;
  662. fpsAttr[JV.PROP_PREFIX] = itemNode[JV.PROP_PREFIX];
  663. fpsAttr[JV.PROP_SUFFIX] = itemNode[JV.PROP_SUFFIX];
  664. fpsAttr[JV.PROP_FORMAT] = itemNode[JV.PROP_FORMAT];
  665. fpsAttr[JV.PROP_DFT_VALUE] = itemNode[JV.PROP_DFT_VALUE];
  666. } else {
  667. me.changeCellType(cell, 'text', bandMap[JV.PROP_COLOR]);
  668. }
  669. bandMappingObj.fontAttr[idxTop + "_" + idxLeft + "_font"] = itemNode[JV.PROP_FONT];
  670. me.setupCell(cell, itemNode);
  671. if ((itemNode.FieldID || itemNode.ParamID) && itemNode[JV.PROP_IS_AUTO_HEIGHT]) {
  672. let value = cell.value();
  673. cell.value(`{` + value + `}`);
  674. }
  675. //*
  676. let border = new GC.Spread.Sheets.LineBorder;
  677. border.color = "Black";
  678. border.style = GC.Spread.Sheets.LineStyle.thin;
  679. for (let iRow = 0; iRow < idxBottom - idxTop; iRow++) {
  680. for (let iCol = 0; iCol < idxRight - idxLeft; iCol++) {
  681. let cl = sheet.getCell(iRow + idxTop, iCol + idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  682. me.private_setCellStyle(cl, itemNode, border);
  683. }
  684. }
  685. //*/
  686. }
  687. }
  688. },
  689. createDftFieldPreSuf: function () {
  690. let rst = {};
  691. rst[JV.PROP_PREFIX] = ``;
  692. rst[JV.PROP_SUFFIX] = ``;
  693. rst[JV.PROP_FORMAT] = ``;
  694. rst[JV.PROP_DFT_VALUE] = ``;
  695. return rst;
  696. },
  697. addDiscreteSpan: function (discreteItemNode, xPos, yPos, bandMappingObj, sheet) {
  698. let me = this;
  699. if (discreteItemNode.items) {
  700. for (let itemNode of discreteItemNode.items) {
  701. //子项
  702. let bandMap = bandMappingObj[itemNode[JV.PROP_BAND_NAME]];
  703. if (bandMap) {
  704. for (let subItemNode of itemNode.items) {
  705. me.addSpanWholeArea(bandMappingObj, bandMap, subItemNode, sheet, xPos, yPos);
  706. }
  707. }
  708. }
  709. }
  710. },
  711. setupBorder: function (cell, border) {
  712. cell.borderLeft(border);
  713. cell.borderRight(border);
  714. cell.borderTop(border);
  715. cell.borderBottom(border);
  716. },
  717. copyPropertiesForSplittedCell: function (srcCell, destCell) {
  718. //1. font
  719. destCell.font(srcCell.font());
  720. //2. bk color
  721. destCell.backColor(srcCell.backColor());
  722. //3. border
  723. destCell.borderLeft(srcCell.borderLeft());
  724. destCell.borderRight(srcCell.borderRight());
  725. destCell.borderTop(srcCell.borderTop());
  726. destCell.borderBottom(srcCell.borderBottom());
  727. }
  728. };