rpt_tpl_vis_jumbo.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /**
  2. * Created by Tony on 2018/9/10.
  3. */
  4. let visualJumbo = {
  5. tplWorkBook: null,
  6. bandMappingObj: null,
  7. iniSpreadJs: function () {
  8. let me = this;
  9. if (me.tplWorkBook !== null) {
  10. me.tplWorkBook.destroy();
  11. me.tplWorkBook = null;
  12. }
  13. me.tplWorkBook = new GC.Spread.Sheets.Workbook($('#ele_visual_div_main3')[0], {sheetCount: 1});
  14. me.tplWorkBook.options.tabStripVisible = false;
  15. me.tplWorkBook.options.allowCopyPasteExcelStyle = false;
  16. me.tplWorkBook.options.allowUserDragDrop = false;
  17. me.tplWorkBook.options.allowContextMenu = false;
  18. let sheet = me.tplWorkBook.getActiveSheet();
  19. sheet.options.allowCellOverflow = false;
  20. sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  21. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellEnter);
  22. },
  23. setupTpl: function () {
  24. let me = this;
  25. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  26. if (rptTpl && me.tplWorkBook) {
  27. let sheet = me.tplWorkBook.getActiveSheet();
  28. let border = new GC.Spread.Sheets.LineBorder;
  29. border.color = "Black";
  30. border.style = GC.Spread.Sheets.LineStyle.thin;
  31. sheet.suspendPaint();
  32. sheet.setRowCount(0);
  33. sheet.setColumnCount(0);
  34. //1. put the pos into array
  35. let xPos = [0], yPos = [0];
  36. let pageH, pageW;
  37. let bandMappingObj = {};
  38. me.bandMappingObj = bandMappingObj;
  39. let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
  40. pageW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  41. pageH = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM])) /2.54*96 );
  42. if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
  43. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
  44. pageW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  45. pageH = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM])) /2.54*96 );
  46. }
  47. xPos.push(pageW);
  48. // pageH = Math.round(pageH / 2);
  49. yPos.push(pageH);
  50. visualCommonOprObj.addBandPos(rptTpl, pageW, pageH, xPos, yPos, bandMappingObj);
  51. visualCommonOprObj.addTplTxtFldPos(rptTpl, dataInfoMapTreeOprObj.treeObj, xPos, yPos, bandMappingObj);
  52. //2. 设置spreadjs
  53. xPos.sort(function(x1, x2){ return (x1 - x2); });
  54. yPos.sort(function(y1, y2){ return (y1 - y2); });
  55. sheet.setRowCount(yPos.length - 1);
  56. sheet.setColumnCount(xPos.length - 1);
  57. for (let idx = 1; idx < xPos.length; idx++) {
  58. sheet.setColumnWidth(idx - 1, xPos[idx] - xPos[idx - 1]);
  59. }
  60. for (let idx = 1; idx < yPos.length; idx++) {
  61. sheet.setRowHeight(idx - 1, yPos[idx] - yPos[idx - 1]);
  62. sheet.getRange(idx - 1, -1, 1, -1).backColor(undefined);
  63. }
  64. visualCommonOprObj.brushSheet(bandMappingObj, sheet, xPos, yPos);
  65. visualCommonOprObj.setupTplTxtFld(rptTpl, dataInfoMapTreeOprObj.treeObj, sheet, xPos, yPos, bandMappingObj)
  66. for (let idx = 1; idx < yPos.length; idx++) {
  67. let bkc = sheet.getCell(idx - 1, 0).backColor();
  68. if (bkc === 'White') {
  69. sheet.setRowHeight(idx - 1, 30);
  70. }
  71. }
  72. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  73. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  74. let cell = sheet.getCell(iRow, iCol);
  75. if (cell.backColor() === 'LightGray' || cell.backColor() === 'LightCyan') {
  76. visualCommonOprObj.setupBorder(sheet.getCell(iRow, iCol), border);
  77. } else if (cell.backColor() === 'White') {
  78. sheet.addSpan(iRow, 0, 1, sheet.getColumnCount());
  79. break;
  80. }
  81. }
  82. }
  83. sheet.clearSelection();
  84. sheet.resumePaint();
  85. }
  86. },
  87. onCellEnter: function (sender, args) {
  88. let me = visualJumbo,
  89. sheet = me.tplWorkBook.getActiveSheet();
  90. me.setupCfg(sheet, args.row, args.col);
  91. },
  92. setupCfg: function (sheet, row, col) {
  93. let me = visualJumbo,
  94. cell = sheet.getCell(row, col);
  95. if (cell.backColor() !== 'White') {
  96. //0. 设置UI
  97. $(`#visElementFonts`)[0].removeAttribute("disabled");
  98. $(`#visRdIsText`)[0].removeAttribute("disabled");
  99. $(`#visRdIsField`)[0].removeAttribute("disabled");
  100. $(`#eleIsAutoHeightVis`)[0].removeAttribute("disabled");
  101. $(`#font_other_properties_div`)[0].style.display = "none";
  102. me.private_ShowBandName(cell);
  103. //1. font
  104. let fontAttr = me.bandMappingObj.fontAttr[row + "_" + col + "_font"];
  105. if (fontAttr) {
  106. me.private_setup_font(fontAttr);
  107. }
  108. //2. alignment
  109. switch (cell.hAlign()) {
  110. case GC.Spread.Sheets.HorizontalAlign.center:
  111. $(`#hAlign_left`)[0].className = "btn btn-sm btn-outline-secondary";
  112. $(`#hAlign_center`)[0].className = "btn btn-sm btn-outline-secondary active";
  113. $(`#hAlign_right`)[0].className = "btn btn-sm btn-outline-secondary";
  114. break;
  115. case GC.Spread.Sheets.HorizontalAlign.right:
  116. $(`#hAlign_left`)[0].className = "btn btn-sm btn-outline-secondary";
  117. $(`#hAlign_center`)[0].className = "btn btn-sm btn-outline-secondary";
  118. $(`#hAlign_right`)[0].className = "btn btn-sm btn-outline-secondary active";
  119. break;
  120. case GC.Spread.Sheets.HorizontalAlign.left:
  121. default:
  122. $(`#hAlign_left`)[0].className = "btn btn-sm btn-outline-secondary active";
  123. $(`#hAlign_center`)[0].className = "btn btn-sm btn-outline-secondary";
  124. $(`#hAlign_right`)[0].className = "btn btn-sm btn-outline-secondary";
  125. break;
  126. }
  127. switch (cell.vAlign()) {
  128. case GC.Spread.Sheets.VerticalAlign.bottom:
  129. $(`#vAlign_center`)[0].className = "btn btn-sm btn-outline-secondary";
  130. $(`#vAlign_bottom`)[0].className = "btn btn-sm btn-outline-secondary active";
  131. break;
  132. case GC.Spread.Sheets.VerticalAlign.center:
  133. default:
  134. $(`#vAlign_center`)[0].className = "btn btn-sm btn-outline-secondary active";
  135. $(`#vAlign_bottom`)[0].className = "btn btn-sm btn-outline-secondary";
  136. break;
  137. }
  138. //3. other control
  139. if (cell.shrinkToFit()) {
  140. $(`#vis_shrink`)[0].className = "btn btn-sm btn-outline-secondary active";
  141. } else {
  142. $(`#vis_shrink`)[0].className = "btn btn-sm btn-outline-secondary";
  143. }
  144. if (cell.wordWrap()) {
  145. $(`#vis_wrap`)[0].className = "btn btn-sm btn-outline-secondary active";
  146. } else {
  147. $(`#vis_wrap`)[0].className = "btn btn-sm btn-outline-secondary";
  148. }
  149. let border = cell.borderLeft();
  150. if (border && border.style === GC.Spread.Sheets.LineStyle.thin) {
  151. $(`#vis_outter_border`)[0].className = "btn btn-sm btn-outline-secondary active";
  152. $(`#vis_no_border`)[0].className = "btn btn-sm btn-outline-secondary";
  153. } else {
  154. $(`#vis_outter_border`)[0].className = "btn btn-sm btn-outline-secondary";
  155. $(`#vis_no_border`)[0].className = "btn btn-sm btn-outline-secondary active";
  156. }
  157. //4. txt/field
  158. let val = cell.value();
  159. if (cell.cellType() && cell.cellType().typeName === '7') {
  160. $(`#visRdIsField`)[0].checked = true;
  161. $(`#lblIsAutoHeightVis`)[0].style.display = "";
  162. if (!stringUtil.isEmptyString(val) && val.indexOf(`{`) === 0) {
  163. $(`#eleIsAutoHeightVis`)[0].checked = true;
  164. } else {
  165. $(`#eleIsAutoHeightVis`)[0].checked = false;
  166. }
  167. } else if (stringUtil.isEmptyString(val) && (!border || border.style === GC.Spread.Sheets.LineStyle.empty)) {
  168. $(`#visRdIsBlank`)[0].checked = true;
  169. $(`#lblIsAutoHeightVis`)[0].style.display = "none";
  170. } else {
  171. $(`#visRdIsText`)[0].checked = true;
  172. $(`#lblIsAutoHeightVis`)[0].style.display = "none";
  173. }
  174. } else {
  175. $("#visElementFonts")[0].disabled = "disabled" ;
  176. $("#visRdIsText")[0].disabled = "disabled" ;
  177. $("#visRdIsField")[0].disabled = "disabled" ;
  178. $("#eleIsAutoHeightVis")[0].disabled = "disabled" ;
  179. $("#id_vis_setup_lbl")[0].innerHTML = '...';
  180. }
  181. },
  182. restoreTpl: function () {
  183. let me = visualJumbo;
  184. if (me.tplWorkBook) {
  185. me.setupTpl();
  186. }
  187. },
  188. private_ShowBandName: function (cell) {
  189. let me = visualJumbo;
  190. if (me.bandMappingObj) {
  191. let color = cell.backColor();
  192. if (color && color !== 'White') {
  193. for (let bItem of me.bandMappingObj.items) {
  194. if (bItem[JV.PROP_COLOR] === color) {
  195. $("#id_vis_setup_lbl")[0].innerHTML = bItem[JV.PROP_BAND_NAME];
  196. break;
  197. }
  198. }
  199. } else {
  200. $("#id_vis_setup_lbl")[0].innerHTML = '...';
  201. }
  202. }
  203. },
  204. private_AddCols: function (sheet, col) {
  205. sheet.suspendPaint();
  206. sheet.addColumns(col, 1);
  207. sheet.resumePaint();
  208. },
  209. insertColumn: function () {
  210. let me = visualJumbo,
  211. sheet = me.tplWorkBook.getActiveSheet();
  212. let selectedRanges = sheet.getSelections();
  213. if (selectedRanges.length > 0) {
  214. me.private_AddCols(sheet, selectedRanges[0].col);
  215. }
  216. },
  217. addColumn: function () {
  218. let me = visualJumbo,
  219. sheet = me.tplWorkBook.getActiveSheet();
  220. me.private_AddCols(sheet, sheet.getColumnCount());
  221. },
  222. splitColumn: function (newColAmt) {
  223. let me = visualJumbo,
  224. sheet = me.tplWorkBook.getActiveSheet();
  225. let selectedRanges = sheet.getSelections();
  226. if (selectedRanges.length > 0) {
  227. if (selectedRanges[0].colCount <= newColAmt) {
  228. let width = 0;
  229. for (let iCol = 0; iCol < selectedRanges[0].colCount; iCol++) {
  230. width += sheet.getColumnWidth(selectedRanges[0].col + iCol);
  231. }
  232. let avgW = Math.round(width / newColAmt),
  233. lastW = width - avgW * (newColAmt - 1);
  234. sheet.suspendPaint();
  235. sheet.addColumns(selectedRanges[0].col + selectedRanges[0].colCount, newColAmt - selectedRanges[0].colCount);
  236. sheet.setColumnWidth(selectedRanges[0].col, lastW);
  237. for (let iCol = 1; iCol < newColAmt; iCol++) {
  238. sheet.setColumnWidth(selectedRanges[0].col + iCol, avgW);
  239. }
  240. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  241. let cell = sheet.getCell(iRow, selectedRanges[0].col);
  242. for (let iCol = selectedRanges[0].colCount; iCol < newColAmt; iCol++) {
  243. visualCommonOprObj.copyPropertiesForSplittedCell(cell, sheet.getCell(iRow, iCol + selectedRanges[0].col));
  244. }
  245. }
  246. sheet.resumePaint();
  247. } else {
  248. alert(`您选择的列数量比要拆分的数量还大!`);
  249. }
  250. }
  251. },
  252. deleteColumn: function () {
  253. let me = visualJumbo,
  254. sheet = me.tplWorkBook.getActiveSheet();
  255. let selectedRanges = sheet.getSelections();
  256. let cc = sheet.getColumnCount();
  257. if (cc > 1) {
  258. if (selectedRanges.length > 0) {
  259. sheet.deleteColumns(selectedRanges[0].col, 1);
  260. }
  261. } else {
  262. alert('不能删除列!');
  263. }
  264. },
  265. addRow: function () {
  266. let me = visualJumbo,
  267. sheet = me.tplWorkBook.getActiveSheet();
  268. let selectedRanges = sheet.getSelections();
  269. if (selectedRanges.length > 0) {
  270. let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  271. let color = cell.backColor();
  272. if (color !== 'White') {
  273. let nextIdx = sheet.getRowCount();
  274. for (let idx = selectedRanges[0].row + 1; idx < sheet.getRowCount(); idx++) {
  275. if (sheet.getCell(idx, selectedRanges[0].col).backColor() !== color) {
  276. nextIdx = idx;
  277. break;
  278. }
  279. }
  280. sheet.suspendPaint();
  281. sheet.addRows(nextIdx, 1);
  282. sheet.getRange(nextIdx, -1, 1, -1).backColor(color);
  283. sheet.resumePaint();
  284. }
  285. }
  286. },
  287. splitRows: function (newRowAmt) {
  288. let me = visualJumbo,
  289. sheet = me.tplWorkBook.getActiveSheet();
  290. let selectedRanges = sheet.getSelections();
  291. if (selectedRanges.length > 0) {
  292. let firstCell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  293. let isSameBand = true;
  294. for (let iRow = 1; iRow < selectedRanges[0].rowCount; i++) {
  295. if (sheet.getCell(iRow + selectedRanges[0].row, 0).backColor() !== firstCell.backColor()) {
  296. isSameBand = false;
  297. break;
  298. }
  299. }
  300. if (isSameBand) {
  301. if (firstCell.backColor() !== 'White') {
  302. if (selectedRanges[0].rowCount <= newRowAmt) {
  303. let height = 0;
  304. for (let iRow = 0; iRow < selectedRanges[0].rowCount; iRow++) {
  305. height += sheet.getRowHeight(selectedRanges[0].row + iRow);
  306. }
  307. let avgH = Math.round(height / newRowAmt),
  308. lastH = height - avgH * (newRowAmt - 1);
  309. sheet.addRows(selectedRanges[0].row + selectedRanges[0].rowCount, newRowAmt - selectedRanges[0].rowCount);
  310. sheet.setRowHeight(selectedRanges[0].row, lastH);
  311. for (let iRow = 1; iRow < newRowAmt; iRow++) {
  312. sheet.setRowHeight(selectedRanges[0].row + iRow, avgH);
  313. }
  314. for (let iRow = selectedRanges[0].rowCount; iRow < newRowAmt; iRow++) {
  315. let cell = sheet.getCell(selectedRanges[0].row, 0);
  316. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  317. visualCommonOprObj.copyPropertiesForSplittedCell(cell, sheet.getCell(iRow + selectedRanges[0].row, iCol));
  318. }
  319. }
  320. } else {
  321. alert(`您选择的行数量比要拆分的数量还大!`);
  322. }
  323. }
  324. } else {
  325. alert(`不能拆分跨界行!`);
  326. }
  327. }
  328. },
  329. deleteRow: function () {
  330. let me = visualJumbo,
  331. sheet = me.tplWorkBook.getActiveSheet();
  332. let selectedRanges = sheet.getSelections();
  333. if (selectedRanges.length > 0) {
  334. let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  335. let color = cell.backColor();
  336. if (color !== 'White') {
  337. let amt = 0;
  338. for (let idx = 0; idx < sheet.getRowCount(); idx++) {
  339. if (sheet.getCell(idx, selectedRanges[0].col).backColor() === color) {
  340. amt++
  341. }
  342. }
  343. if (amt > 1) {
  344. sheet.suspendPaint();
  345. sheet.deleteRows(selectedRanges[0].row, 1);
  346. sheet.resumePaint();
  347. }
  348. }
  349. }
  350. },
  351. fitTheWidth: function (factor) {
  352. let me = this, rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  353. let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
  354. let bandW = 700;
  355. if (pIdx >= 0) {
  356. bandW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  357. if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
  358. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
  359. bandW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  360. }
  361. }
  362. bandW *= factor;
  363. let currentWidth = 0;
  364. let sheet = me.tplWorkBook.getActiveSheet();
  365. for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
  366. currentWidth += sheet.getColumnWidth(idx);
  367. }
  368. let actFactor = bandW / currentWidth;
  369. for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
  370. sheet.setColumnWidth(idx, Math.round(sheet.getColumnWidth(idx) * actFactor));
  371. }
  372. },
  373. mergeCells: function () {
  374. let me = visualJumbo,
  375. sheet = me.tplWorkBook.getActiveSheet();
  376. let selectedRanges = sheet.getSelections();
  377. if (selectedRanges.length > 0) {
  378. let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  379. let color = cell.backColor();
  380. let isDifferent = false;
  381. for (let idx = 1; idx < selectedRanges[0].rowCount; idx++) {
  382. if (sheet.getCell(selectedRanges[0].row + idx, 0).backColor() !== color) {
  383. isDifferent = true;
  384. break;
  385. }
  386. }
  387. if (!isDifferent) {
  388. sheet.suspendPaint();
  389. sheet.addSpan(selectedRanges[0].row, selectedRanges[0].col, selectedRanges[0].rowCount, selectedRanges[0].colCount);
  390. sheet.resumePaint();
  391. } else {
  392. alert(`不能合并跨界单元格!`)
  393. }
  394. }
  395. },
  396. disMergeCells: function () {
  397. let me = visualJumbo,
  398. sheet = me.tplWorkBook.getActiveSheet();
  399. let selectedRanges = sheet.getSelections();
  400. let spans = sheet.getSpans();
  401. if (selectedRanges.length > 0 && spans.length > 0) {
  402. let selectedSpans = [];
  403. for(let i = 0; i < spans.length; i++)
  404. {
  405. for (let j = 0; j < selectedRanges.length; j++) {
  406. if (spans[i].row >= selectedRanges[j].row && spans[i].col >= selectedRanges[j].col &&
  407. spans[i].row < selectedRanges[j].row + selectedRanges[j].rowCount && spans[i].col < selectedRanges[j].col + selectedRanges[j].colCount) {
  408. selectedSpans.push(spans[i]);
  409. }
  410. }
  411. }
  412. for (let span of selectedSpans) {
  413. sheet.removeSpan(span.row, span.col, GC.Spread.Sheets.SheetArea.viewport);
  414. }
  415. }
  416. },
  417. changeFontSet: function (dom) {
  418. let me = visualJumbo, fontAttr = dom.value,
  419. sheet = me.tplWorkBook.getActiveSheet();
  420. let selectedRanges = sheet.getSelections();
  421. if (selectedRanges.length > 0) {
  422. let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  423. if (fontAttr === "自定义") {
  424. fontAttr = {};
  425. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = "宋体";
  426. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]] = 12;
  427. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_COLOR]] = "BLACK";
  428. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] = "F"; //bold
  429. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] = "F"; //italic
  430. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] = "F"; //underline
  431. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_STRIKEOUT]] = "F"; //strikeout
  432. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_ANGLE]] = 0; //angle
  433. }
  434. me.bandMappingObj.fontAttr[selectedRanges[0].row + "_" + selectedRanges[0].col + "_font"] = fontAttr;
  435. me.private_setup_font(fontAttr);
  436. if (typeof fontAttr === 'string') {
  437. let idx = rpt_tpl_cfg_helper.reportCfg.fontArr.indexOf(fontAttr);
  438. fontAttr = rpt_tpl_cfg_helper.reportCfg.fonts[idx];
  439. }
  440. me.private_setup_cell_font(cell, fontAttr);
  441. }
  442. },
  443. setupCellFont: function () {
  444. let me = visualJumbo, sheet = me.tplWorkBook.getActiveSheet();
  445. let selectedRanges = sheet.getSelections();
  446. if (selectedRanges.length > 0) {
  447. let fontAttr = $(`#visElementFonts`)[0].value;
  448. if (fontAttr === "自定义") {
  449. fontAttr = {};
  450. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = $(`#visElementFontNames`)[0].value;
  451. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]] = $(`#visEleFontSize`)[0].value;
  452. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] = ($("#vis_font_bold")[0].className === "btn btn-sm btn-outline-secondary")?'F':'T'; //bold
  453. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] = ($("#vis_font_italic")[0].className === "btn btn-sm btn-outline-secondary")?'F':'T'; //italic
  454. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] = ($("#vis_font_underline")[0].className === "btn btn-sm btn-outline-secondary")?'F':'T'; //underline
  455. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_STRIKEOUT]] = "F"; //strikeout
  456. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_COLOR]] = "BLACK";
  457. fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_ANGLE]] = 0; //angle
  458. me.bandMappingObj.fontAttr[selectedRanges[0].row + "_" + selectedRanges[0].col + "_font"] = fontAttr;
  459. } else {
  460. let idx = rpt_tpl_cfg_helper.reportCfg.fontArr.indexOf(fontAttr);
  461. fontAttr = rpt_tpl_cfg_helper.reportCfg.fonts[idx];
  462. me.bandMappingObj.fontAttr[selectedRanges[0].row + "_" + selectedRanges[0].col + "_font"] = fontAttr;
  463. }
  464. let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  465. sheet.suspendPaint();
  466. me.private_setup_cell_font(cell, fontAttr);
  467. sheet.resumePaint();
  468. }
  469. },
  470. setupCellAlignment: function () {
  471. let me = visualJumbo, sheet = me.tplWorkBook.getActiveSheet();
  472. let selectedRanges = sheet.getSelections();
  473. if (selectedRanges.length > 0) {
  474. // let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  475. sheet.suspendPaint();
  476. for (let iRow = 0; iRow < selectedRanges[0].rowCount; iRow++) {
  477. for (let iCol = 0; iCol < selectedRanges[0].colCount; iCol++) {
  478. let cell = sheet.getCell(selectedRanges[0].row + iRow, selectedRanges[0].col + iCol);
  479. //1. horizon alignment
  480. if ($(`#hAlign_center`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  481. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  482. } else if ($(`#hAlign_left`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  483. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  484. } else if ($(`#hAlign_right`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  485. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  486. }
  487. //2. vertical alignment
  488. if ($(`#vAlign_center`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  489. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  490. } else if ($(`#vAlign_bottom`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  491. cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  492. }
  493. //3. shrink
  494. if ($(`#vis_shrink`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  495. cell.shrinkToFit(true);
  496. } else {
  497. cell.shrinkToFit(false);
  498. }
  499. //4. wrap
  500. if ($(`#vis_wrap`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  501. cell.wordWrap(true);
  502. } else {
  503. cell.wordWrap(false);
  504. }
  505. }
  506. }
  507. sheet.resumePaint();
  508. }
  509. },
  510. setupCellBorder: function () {
  511. let me = visualJumbo, sheet = me.tplWorkBook.getActiveSheet();
  512. let selectedRanges = sheet.getSelections();
  513. if (selectedRanges.length > 0) {
  514. // let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  515. sheet.suspendPaint();
  516. let border = new GC.Spread.Sheets.LineBorder;
  517. border.color = "Black";
  518. if ($(`#vis_outter_border`)[0].className === `btn btn-sm btn-outline-secondary active`) {
  519. border.style = GC.Spread.Sheets.LineStyle.thin;
  520. } else {
  521. border.style = GC.Spread.Sheets.LineStyle.empty;
  522. }
  523. let cellRange = new GC.Spread.Sheets.CellRange(sheet, selectedRanges[0].row, selectedRanges[0].col, selectedRanges[0].rowCount, selectedRanges[0].colCount);
  524. cellRange.setBorder(border, {all: true});
  525. sheet.resumePaint();
  526. }
  527. },
  528. private_setup_cell_font: function (cell, fontAttr) {
  529. let fontStr = "";
  530. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]])) {
  531. fontStr = 'bold ' + fontStr;
  532. }
  533. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]])) {
  534. fontStr = 'italic ' + fontStr;
  535. }
  536. 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]];
  537. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]])) {
  538. cell.textDecoration(GC.Spread.Sheets.TextDecorationType.underline);
  539. } else {
  540. cell.textDecoration(GC.Spread.Sheets.TextDecorationType.none);
  541. }
  542. cell.font(fontStr);
  543. },
  544. private_setup_font: function(fontAttr) {
  545. if (typeof fontAttr === "string" && fontAttr !== "自定义") {
  546. $("#visElementFontNames")[0].disabled = "disabled" ;
  547. $("#visEleFontSize")[0].disabled = "disabled" ;
  548. let idx = rpt_tpl_cfg_helper.reportCfg.fontArr.indexOf(fontAttr);
  549. let font = rpt_tpl_cfg_helper.reportCfg.fonts[idx];
  550. $("#visElementFonts")[0].selectedIndex = idx;
  551. $("#visElementFontNames")[0].value = font.Name;
  552. $("#visEleFontSize")[0].value = parseInt(font.FontHeight);
  553. $("#font_other_properties_div")[0].style.display = "none";
  554. $("#vis_font_bold")[0].className = "btn btn-sm btn-outline-secondary";
  555. $("#vis_font_italic")[0].className = "btn btn-sm btn-outline-secondary";
  556. $("#vis_font_underline")[0].className = "btn btn-sm btn-outline-secondary";
  557. } else {
  558. $("#visElementFontNames")[0].removeAttribute("disabled");
  559. $("#visEleFontSize")[0].removeAttribute("disabled");
  560. $("#font_other_properties_div")[0].style.display = "";
  561. $("#visElementFonts")[0].value = "自定义";
  562. $("#visElementFontNames")[0].value = fontAttr.Name;
  563. $("#visEleFontSize")[0].value = parseInt(fontAttr.FontHeight);
  564. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]])) {
  565. $("#vis_font_bold")[0].className = "btn btn-sm btn-outline-secondary active";
  566. }
  567. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]])) {
  568. $("#vis_font_italic")[0].className = "btn btn-sm btn-outline-secondary active";
  569. }
  570. if (stringUtil.convertStrToBoolean(fontAttr[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]])) {
  571. $("#vis_font_underline")[0].className = "btn btn-sm btn-outline-secondary active";
  572. }
  573. }
  574. },
  575. fontBoldChange: function (dom) {
  576. let me = this;
  577. me.private_reverse_class(dom);
  578. me.setupCellFont();
  579. },
  580. fontItalicChange: function (dom) {
  581. let me = this;
  582. me.private_reverse_class(dom);
  583. me.setupCellFont();
  584. },
  585. fontUnderlineChange: function (dom) {
  586. let me = this;
  587. me.private_reverse_class(dom);
  588. me.setupCellFont();
  589. },
  590. changeShrink: function (dom) {
  591. let me = this;
  592. me.private_reverse_class(dom);
  593. me.setupCellAlignment();
  594. },
  595. changeWrap: function (dom) {
  596. let me = this;
  597. me.private_reverse_class(dom);
  598. me.setupCellAlignment();
  599. },
  600. changeIsAutoHeight: function (dom) {
  601. let me = visualJumbo, sheet = me.tplWorkBook.getActiveSheet();
  602. let selectedRanges = sheet.getSelections();
  603. if (selectedRanges.length > 0) {
  604. let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  605. if (cell.cellType() && cell.cellType().typeName === '7') {
  606. sheet.suspendPaint();
  607. let val = cell.value();
  608. if (dom.checked) {
  609. if (val.indexOf(`{`) < 0) {
  610. cell.value(`{` + val + `}`);
  611. }
  612. } else {
  613. if (val.indexOf(`{`) === 0) {
  614. cell.value(val.replace('{', '').replace('}',''));
  615. }
  616. }
  617. sheet.resumePaint();
  618. }
  619. }
  620. },
  621. private_reverse_class: function (dom) {
  622. if (dom.className === "btn btn-sm btn-outline-secondary") {
  623. dom.className = "btn btn-sm btn-outline-secondary active";
  624. } else {
  625. dom.className = "btn btn-sm btn-outline-secondary";
  626. }
  627. },
  628. changeHAlign: function (dom) {
  629. let me = this;
  630. if (dom.className === "btn btn-sm btn-outline-secondary") {
  631. dom.className = "btn btn-sm btn-outline-secondary active"
  632. let hKeys = [`hAlign_left`, `hAlign_center`, `hAlign_right`];
  633. let domIdx = hKeys.indexOf(dom.id);
  634. if (domIdx >= 0) {
  635. for (let idx = 0; idx < hKeys.length; idx++) {
  636. if (idx !== domIdx) {
  637. $(`#` + hKeys[idx])[0].className = "btn btn-sm btn-outline-secondary";
  638. }
  639. }
  640. }
  641. me.setupCellAlignment();
  642. }
  643. },
  644. changeVAlign: function (dom) {
  645. let me = this;
  646. if (dom.className === "btn btn-sm btn-outline-secondary") {
  647. dom.className = "btn btn-sm btn-outline-secondary active"
  648. let hKeys = [`vAlign_top`, `vAlign_center`, `vAlign_bottom`];
  649. let domIdx = hKeys.indexOf(dom.id);
  650. if (domIdx >= 0) {
  651. for (let idx = 0; idx < hKeys.length; idx++) {
  652. if (idx !== domIdx) {
  653. $(`#` + hKeys[idx])[0].className = "btn btn-sm btn-outline-secondary";
  654. }
  655. }
  656. }
  657. me.setupCellAlignment();
  658. }
  659. },
  660. changeBorder: function (dom) {
  661. let me = this;
  662. if (dom.className === "btn btn-sm btn-outline-secondary") {
  663. dom.className = "btn btn-sm btn-outline-secondary active"
  664. let hKeys = [`vis_outter_border`, `vis_no_border`];
  665. let domIdx = hKeys.indexOf(dom.id);
  666. if (domIdx >= 0) {
  667. for (let idx = 0; idx < hKeys.length; idx++) {
  668. if (idx !== domIdx) {
  669. $(`#` + hKeys[idx])[0].className = "btn btn-sm btn-outline-secondary";
  670. }
  671. }
  672. }
  673. me.setupCellBorder();
  674. }
  675. },
  676. changeCellType: function (newType) {
  677. let me = visualJumbo, sheet = me.tplWorkBook.getActiveSheet();
  678. let selectedRanges = sheet.getSelections();
  679. if (selectedRanges.length > 0) {
  680. let cell = sheet.getCell(selectedRanges[0].row, selectedRanges[0].col);
  681. switch (newType) {
  682. case `field`:
  683. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  684. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  685. // let selectableFields = me.getSelectedFields(rptTpl);
  686. let selectableFields = visualCommonOprObj.getAllSelectedFields(rptTpl);
  687. cellType.items(selectableFields);
  688. cell.cellType(cellType);
  689. break;
  690. case `text`:
  691. default:
  692. cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
  693. cell.value(``);
  694. break;
  695. }
  696. }
  697. },
  698. applyBack: function () {
  699. let me = visualJumbo, sheet = me.tplWorkBook.getActiveSheet();
  700. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  701. let xPos = [0], yPos = [0];
  702. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  703. xPos.push(sheet.getRowHeight(iRow) + xPos[xPos.length - 1]);
  704. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  705. yPos.push(sheet.getColumnWidth(iCol) + yPos[yPos.length - 1]);
  706. }
  707. }
  708. if (rptTpl[JV.NODE_FLOW_INFO]) {
  709. //流水式
  710. me.applyBack_Flow(rptTpl, sheet, xPos, yPos);
  711. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  712. //账单式
  713. me.applyBack_Bill(rptTpl, sheet, xPos, yPos);
  714. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  715. //交叉式
  716. //目前暂缓
  717. me.applyBack_Cross(rptTpl, sheet, xPos, yPos);
  718. }
  719. },
  720. applyBack_Flow: function (rptTpl, sheet, xPos, yPos) {
  721. let me = this;
  722. let startRow = -1, handledBands = [];
  723. //先清除所有相关text/field节点,然后再重新生成
  724. me.private_clear_flow_txt_fld_nodes();
  725. let textFldArr = [], colWidthArr = [], rowHeightArr = [];
  726. //1. 锚定column / content(& grouping)
  727. let columnBand = visualCommonOprObj.getBandEx(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_COLUMN][JV.PROP_BAND_NAME], rptTpl);
  728. handledBands.push(columnBand[JV.PROP_NAME]);
  729. me.private_setup_bandHeight(columnBand[JV.PROP_NAME], columnBand, sheet);
  730. startRow = me.collectSheetTxtFldByArea(sheet, me.bandMappingObj[columnBand[JV.PROP_NAME]][JV.PROP_COLOR] , textFldArr, colWidthArr, rowHeightArr);
  731. let columnNodes = [];
  732. for (let text of textFldArr) {
  733. let node = me.createTxtNode(text, sheet, startRow, colWidthArr, rowHeightArr);
  734. columnNodes.push(node);
  735. }
  736. let cotentBand = visualCommonOprObj.getBandEx(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_BAND_NAME], rptTpl);
  737. handledBands.push(cotentBand[JV.PROP_NAME]);
  738. me.private_setup_flow_content_height(rptTpl, cotentBand[JV.PROP_NAME], sheet);
  739. textFldArr = [];
  740. colWidthArr = [];
  741. rowHeightArr = [];
  742. startRow = me.collectSheetTxtFldByArea(sheet, me.bandMappingObj[cotentBand[JV.PROP_NAME]][JV.PROP_COLOR] , textFldArr, colWidthArr, rowHeightArr);
  743. let contentNodes = [];
  744. for (let field of textFldArr) {
  745. let node = me.private_create_field_param_node(sheet, field, startRow, colWidthArr, rowHeightArr, rptTpl);
  746. contentNodes.push(node);
  747. }
  748. //2. 锚定 统计类型
  749. let pageTotalBand = visualCommonOprObj.getBandEx(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM][JV.PROP_BAND_NAME], rptTpl);
  750. let pageSummaryNodes = [[], []];
  751. if (pageTotalBand) {
  752. handledBands.push(pageTotalBand[JV.PROP_NAME]);
  753. me.private_build_txt_fld_nodes(pageTotalBand, sheet, rptTpl, pageSummaryNodes);
  754. }
  755. let segTotalBand = visualCommonOprObj.getBandEx(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM][JV.PROP_BAND_NAME], rptTpl);
  756. let segSummaryNodes = [[], []];
  757. if (segTotalBand) {
  758. handledBands.push(segTotalBand[JV.PROP_NAME]);
  759. me.private_build_txt_fld_nodes(segTotalBand, sheet, rptTpl, segSummaryNodes);
  760. }
  761. //3. 其他就归类到离散去了
  762. let discreteNodesArr = [];
  763. if (me.bandMappingObj && me.bandMappingObj.items && me.bandMappingObj.items.length > 0) {
  764. for (let sBandMap of me.bandMappingObj.items) {
  765. if (handledBands.indexOf(sBandMap[JV.PROP_BAND_NAME]) < 0 && sBandMap[JV.PROP_COLOR] !== 'White') {
  766. let sArr = {Name: "子项", BandName: sBandMap[JV.PROP_BAND_NAME], items: [[],[]], isParent: true};
  767. let sBand = visualCommonOprObj.getBandEx(sBandMap[JV.PROP_BAND_NAME], rptTpl);
  768. if (sBand) {
  769. me.private_build_txt_fld_nodes(sBand, sheet, rptTpl, sArr.items);
  770. }
  771. if (sArr.items[0].length > 0 || sArr.items[1].length > 0) {
  772. discreteNodesArr.push(sArr);
  773. }
  774. }
  775. }
  776. }
  777. //4. 最后生成节点
  778. me.private_create_tpl_flow_nodes(columnNodes, contentNodes, pageSummaryNodes, segSummaryNodes, null, discreteNodesArr);
  779. displayMessage("应用提交成功!", "green", 5000, "id_vis_setup_lbl");
  780. },
  781. private_build_txt_fld_nodes: function (band, sheet, rptTpl, destNodes) {
  782. let me = this;
  783. me.private_setup_bandHeight(band[JV.PROP_NAME], band, sheet);
  784. let textFldArr = [], colWidthArr = [], rowHeightArr = [];
  785. let startRow = me.collectSheetTxtFldByArea(sheet, me.bandMappingObj[band[JV.PROP_NAME]][JV.PROP_COLOR] , textFldArr, colWidthArr, rowHeightArr);
  786. for (let txtFld of textFldArr) {
  787. if (txtFld.isField) {
  788. let fldNode = me.private_create_field_param_node(sheet, txtFld, startRow, colWidthArr, rowHeightArr, rptTpl);
  789. destNodes[0].push(fldNode);
  790. } else {
  791. let txtNode = me.createTxtNode(txtFld, sheet, startRow, colWidthArr, rowHeightArr);
  792. destNodes[1].push(txtNode);
  793. }
  794. }
  795. },
  796. private_create_tpl_flow_nodes: function (columnNodes, contentNodes, pageSummaryNodes, segSummaryNodes, groupSummaryNodes, discreteNodesArr) {
  797. let nodes = dataInfoMapTreeOprObj.treeObj.getNodes();
  798. for (let node of nodes) {
  799. if (node[JV.PROP_NAME].indexOf('_列') >= 0) {
  800. //列
  801. dataInfoMapTreeOprObj.treeObj.addNodes(node, -1, columnNodes, true);
  802. } else if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  803. //数据
  804. dataInfoMapTreeOprObj.treeObj.addNodes(node, -1, contentNodes, true);
  805. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0) {
  806. //页统计
  807. if (pageSummaryNodes[0].length > 0) {
  808. dataInfoMapTreeOprObj.treeObj.addNodes(node.items[0], -1, pageSummaryNodes[0], true);
  809. }
  810. if (pageSummaryNodes[1].length > 0) {
  811. dataInfoMapTreeOprObj.treeObj.addNodes(node.items[1], -1, pageSummaryNodes[1], true);
  812. }
  813. } else if (node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  814. //章统计
  815. if (segSummaryNodes[0].length > 0) {
  816. dataInfoMapTreeOprObj.treeObj.addNodes(node.items[0], -1, segSummaryNodes[0], true);
  817. }
  818. if (segSummaryNodes[1].length > 0) {
  819. dataInfoMapTreeOprObj.treeObj.addNodes(node.items[1], -1, segSummaryNodes[1], true);
  820. }
  821. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  822. //分组统计
  823. // for (let subNode of node.items) {
  824. // dataInfoMapTreeOprObj.treeObj.removeChildNodes(subNode);
  825. // }
  826. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  827. //离散信息
  828. if (discreteNodesArr) {
  829. for (let dNode of discreteNodesArr) {
  830. let discreteNode = {"Name": "子项", "BandName": dNode[JV.PROP_BAND_NAME], "items": [{"Name": "离散字段集", "items": [], "isParent": true},{"Name": "离散文本集", "items": [], "isParent": true}], "isParent": true};
  831. if (dNode.items[0].length > 0) {
  832. // dataInfoMapTreeOprObj.treeObj.addNodes(node.items[0], -1, segSummaryNodes[0], true);
  833. discreteNode.items[0].items = dNode.items[0];
  834. }
  835. if (dNode.items[1].length > 0) {
  836. // dataInfoMapTreeOprObj.treeObj.addNodes(node.items[1], -1, segSummaryNodes[1], true);
  837. discreteNode.items[1].items = dNode.items[1];
  838. }
  839. dataInfoMapTreeOprObj.treeObj.addNodes(node, -1, discreteNode, true);
  840. }
  841. }
  842. }
  843. }
  844. },
  845. private_create_field_param_node: function (sheet, field, startRow, colWidthArr, rowHeightArr, rptTpl) {
  846. let me = this;
  847. let isAutoHeight = false;
  848. if (field.text && field.text.indexOf(`{`) === 0) {
  849. isAutoHeight = true;
  850. field.text = field.text.replace('{', '').replace('}','');
  851. }
  852. let rst = {"Name": field.text, "Title": '', "FieldID": -1, "font": "Content", "control": "Column", "style" : "Default_Normal", "isAutoHeight" : false,
  853. "area" : {"Left" : 0, "Right" : 100, "Top" : 0, "Bottom" : 100, "H_CalculationType" : "percentage", "V_CalculationType" : "percentage"}
  854. };
  855. //1. 设置FieldID
  856. let hasChkField = false;
  857. let native_chk_field_param = function (fpArr) {
  858. for (let rptField of fpArr) {
  859. if (rptField[JV.PROP_NAME] === field.text) {
  860. rst.FieldID = rptField[JV.PROP_ID];
  861. rst["Title"] = "ID: " + rptField[JV.PROP_ID];
  862. hasChkField = true;
  863. break;
  864. }
  865. }
  866. };
  867. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  868. native_chk_field_param(rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]);
  869. }
  870. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS].length > 0) {
  871. native_chk_field_param(rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]);
  872. }
  873. if (!hasChkField && rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  874. native_chk_field_param(rptTpl[JV.NODE_NO_MAPPING_FIELDS]);
  875. }
  876. if (!hasChkField && rptTpl[JV.NODE_DISCRETE_PARAMS] !== undefined && rptTpl[JV.NODE_DISCRETE_PARAMS].length > 0) {
  877. native_chk_field_param(rptTpl[JV.NODE_DISCRETE_PARAMS]);
  878. if (hasChkField) {
  879. rst.ParamID = rst.FieldID;
  880. delete rst.FieldID;
  881. }
  882. }
  883. let cell = sheet.getCell(field.row, field.col);
  884. //2. 字体
  885. rst[JV.PROP_FONT] = me.private_getFontByCellProperties(cell);
  886. rst[JV.PROP_STYLE] = me.private_getBorderByCellProperties(cell);
  887. rst[JV.PROP_CONTROL] = me.private_getCtrlByCellProperties(cell);
  888. //3. 自动行高
  889. rst[JV.PROP_IS_AUTO_HEIGHT] = isAutoHeight;
  890. //4. 左右位置%
  891. me.setupHeightWidth(rst, field, startRow, colWidthArr, rowHeightArr);
  892. return rst;
  893. },
  894. private_clear_flow_txt_fld_nodes: function () {
  895. let nodes = dataInfoMapTreeOprObj.treeObj.getNodes();
  896. for (let node of nodes) {
  897. if (node[JV.PROP_NAME].indexOf('_列') >= 0 || node[JV.PROP_NAME].indexOf('数据') >= 0) {
  898. //1. 列 / 数据
  899. dataInfoMapTreeOprObj.treeObj.removeChildNodes(node);
  900. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0 || node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  901. //3. 页统计 / 章统计
  902. for (let subNode of node.items) {
  903. dataInfoMapTreeOprObj.treeObj.removeChildNodes(subNode);
  904. }
  905. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  906. //5. 分组统计
  907. for (let subNode of node.items) {
  908. dataInfoMapTreeOprObj.treeObj.removeChildNodes(subNode);
  909. }
  910. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  911. //6. 离散信息
  912. dataInfoMapTreeOprObj.treeObj.removeChildNodes(node);
  913. }
  914. }
  915. },
  916. applyBack_Bill: function (rptTpl, sheet, xPos, yPos) {
  917. let me = this;
  918. let pageWith = xPos[xPos.length - 1];
  919. //先清除所有相关text/field节点,然后再重新生成
  920. me.private_clear_bill_txt_fld_nodes();
  921. //1. 锚定content
  922. let cotentBand = visualCommonOprObj.getBandEx(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_BAND_NAME], rptTpl);
  923. //2. 其他就归类到离散去了
  924. },
  925. private_clear_bill_txt_fld_nodes: function () {
  926. let nodes = dataInfoMapTreeOprObj.treeObj.getNodes();
  927. for (let node of nodes) {
  928. dataInfoMapTreeOprObj.treeObj.removeChildNodes(node);
  929. }
  930. },
  931. applyBack_Cross: function (rptTpl, sheet, xPos, yPos) {
  932. let me = this;
  933. let pageWith = xPos[xPos.length - 1];
  934. //先清除所有相关text/field节点,然后再重新生成
  935. me.private_clear_cross_txt_fld_nodes();
  936. //1. 锚定...
  937. },
  938. private_clear_cross_txt_fld_nodes: function () {
  939. let nodes = dataInfoMapTreeOprObj.treeObj.getNodes();
  940. for (let node of nodes) {
  941. //
  942. }
  943. },
  944. private_setup_flow_content_height: function (rptTpl, bandName, sheet) {
  945. let me = visualJumbo;
  946. if (me.bandMappingObj[bandName]) {
  947. let bandColor = me.bandMappingObj[bandName][JV.PROP_COLOR];
  948. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  949. if (sheet.getCell(iRow, 0).backColor() === bandColor) {
  950. rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_CMN_HEIGHT] = (sheet.getRowHeight(iRow) / unitFactor).toFixed(2);
  951. }
  952. }
  953. }
  954. },
  955. private_setup_bandHeight: function (bandName, band, sheet) {
  956. let me = visualJumbo;
  957. if (band && me.bandMappingObj[bandName]) {
  958. let bandColor = me.bandMappingObj[bandName][JV.PROP_COLOR];
  959. let isFirst = true, firstRowIdx = -1, lastRowIdx = -1;
  960. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  961. if (sheet.getCell(iRow, 0).backColor() === bandColor) {
  962. lastRowIdx = iRow;
  963. if (isFirst) {
  964. firstRowIdx = iRow;
  965. isFirst = false;
  966. }
  967. }
  968. }
  969. if (firstRowIdx >= 0) {
  970. let bH = 0;
  971. for (let idx = firstRowIdx; idx <= lastRowIdx; idx++) {
  972. bH += sheet.getRowHeight(idx);
  973. }
  974. band[JV.BAND_PROP_HEIGHT] = (bH / unitFactor).toFixed(2);
  975. }
  976. }
  977. },
  978. collectSheetTxtFldByArea: function (sheet, backColor, textArr, colWidthArr, rowHeightArr) {
  979. let me = this, allSpans = sheet.getSpans();
  980. let startRow = -1, endRow = -1;
  981. let isFirst = true;
  982. for (let idx = 0; idx < sheet.getRowCount(); idx++) {
  983. if (sheet.getCell(idx, 0).backColor() === backColor) {
  984. if (isFirst) {
  985. startRow = idx;
  986. isFirst = false;
  987. }
  988. endRow = idx;
  989. }
  990. }
  991. let spans = [];
  992. for (let span of allSpans) {
  993. if (span.row >= startRow && span.row <= endRow) {
  994. spans.push(span);
  995. }
  996. }
  997. for (let span of spans) {
  998. me.private_build_pre_text(sheet, textArr, span.row, span.col, span.rowCount, span.colCount);
  999. }
  1000. for (let iRow = startRow; iRow <= endRow; iRow++) {
  1001. rowHeightArr.push(sheet.getRowHeight(iRow));
  1002. if (iRow > startRow) {
  1003. rowHeightArr[iRow - startRow] = rowHeightArr[iRow - startRow] + rowHeightArr[iRow - startRow - 1];
  1004. }
  1005. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  1006. if (iRow === startRow) {
  1007. colWidthArr.push(sheet.getColumnWidth(jCol));
  1008. if (jCol > 0) {
  1009. colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1];
  1010. }
  1011. }
  1012. if (!visualCommonOprObj.checkInSpan(spans, iRow, jCol)) {
  1013. me.private_build_pre_text(sheet, textArr, iRow, jCol, 1, 1);
  1014. }
  1015. }
  1016. }
  1017. return startRow;
  1018. },
  1019. private_build_pre_text: function (sheet, textArr, row, col, rowCount, colCount) {
  1020. let cell = sheet.getCell(row, col);
  1021. let textValue = sheet.getValue(row, col);
  1022. let isField = false, isBlank = false;
  1023. if (textValue && cell.cellType() && cell.cellType().typeName === '7') {
  1024. isField = true;
  1025. } else {
  1026. isBlank = stringUtil.isEmptyString(textValue);
  1027. }
  1028. if (!isBlank) {
  1029. textArr.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": textValue, "isField": isField});
  1030. }
  1031. },
  1032. createTxtNode: function (text, sheet, startRow, colWidthArr, rowHeightArr) {
  1033. let me = this, rst = dataInfoMapTreeOprObj.getDummyTextNode(null);
  1034. me.setupHeightWidth(rst, text, startRow, colWidthArr, rowHeightArr);
  1035. if (stringUtil.isEmptyString(text[`text`])) {
  1036. rst[JV.PROP_NAME] = '';
  1037. } else {
  1038. rst[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`].toString(), '\n', '|'), '\r', '');
  1039. }
  1040. rst[JV.PROP_LABEL] = rst[JV.PROP_NAME];
  1041. //then setup font/border/control
  1042. let cell = sheet.getCell(text.row, text.col);
  1043. rst[JV.PROP_FONT] = me.private_getFontByCellProperties(cell);
  1044. rst[JV.PROP_STYLE] = me.private_getBorderByCellProperties(cell);
  1045. rst[JV.PROP_CONTROL] = me.private_getCtrlByCellProperties(cell);
  1046. return rst;
  1047. },
  1048. setupHeightWidth: function (dest, text, startRow, colWidthArr, rowHeightArr) {
  1049. let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
  1050. dest[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
  1051. if (text.col > 0) {
  1052. dest[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
  1053. } else {
  1054. dest[JV.PROP_AREA][JV.PROP_LEFT] = 0;
  1055. }
  1056. dest[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row - startRow + text.rowCount - 1] / height * 100).toFixed(2);
  1057. if (text.row > startRow) {
  1058. dest[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - startRow - 1] / height * 100).toFixed(2);
  1059. } else {
  1060. dest[JV.PROP_AREA][JV.PROP_TOP] = 0;
  1061. }
  1062. },
  1063. createDiscreteFieldNode: function (field, colWidthArr, rowHeightArr) {
  1064. //
  1065. },
  1066. private_getFontByCellProperties: function (cell) {
  1067. let me = this, rst = 'Content';
  1068. if (me.bandMappingObj.fontAttr[cell.row + "_" + cell.col + "_font"]) {
  1069. rst = me.bandMappingObj.fontAttr[cell.row + "_" + cell.col + "_font"];
  1070. }
  1071. return rst;
  1072. },
  1073. private_getBorderByCellProperties: function (cell) {
  1074. let rst = 'Default_None';
  1075. let border = cell.borderLeft();
  1076. if (border && border.style === GC.Spread.Sheets.LineStyle.thin) {
  1077. rst = 'Default_Normal'
  1078. }
  1079. return rst;
  1080. },
  1081. private_getCtrlByCellProperties: function (cell) {
  1082. let rst = 'Default';
  1083. let border = cell.borderLeft();
  1084. if (cell.vAlign() === GC.Spread.Sheets.VerticalAlign.center) {
  1085. if (border && border.style === GC.Spread.Sheets.LineStyle.thin) {
  1086. switch (cell.hAlign()) {
  1087. case GC.Spread.Sheets.HorizontalAlign.center:
  1088. rst = `Column`;
  1089. break;
  1090. case GC.Spread.Sheets.HorizontalAlign.right:
  1091. rst = `Column_Right`;
  1092. break;
  1093. case GC.Spread.Sheets.HorizontalAlign.left:
  1094. default:
  1095. rst = `Column_Left`;
  1096. break;
  1097. }
  1098. } else {
  1099. switch (cell.hAlign()) {
  1100. case GC.Spread.Sheets.HorizontalAlign.center:
  1101. rst = `Title`;
  1102. break;
  1103. case GC.Spread.Sheets.HorizontalAlign.right:
  1104. rst = `Header_Right`;
  1105. break;
  1106. case GC.Spread.Sheets.HorizontalAlign.left:
  1107. default:
  1108. rst = `Header`;
  1109. break;
  1110. }
  1111. }
  1112. } else {
  1113. switch (cell.hAlign()) {
  1114. case GC.Spread.Sheets.HorizontalAlign.center:
  1115. rst = `Content_Center`;
  1116. break;
  1117. case GC.Spread.Sheets.HorizontalAlign.right:
  1118. rst = `Content_Right`;
  1119. break;
  1120. case GC.Spread.Sheets.HorizontalAlign.left:
  1121. default:
  1122. rst = `Content_Left`;
  1123. break;
  1124. }
  1125. }
  1126. return rst;
  1127. }
  1128. };