rpt_tpl_vis_common.js 36 KB

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