rpt_tpl_vis_common.js 36 KB

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