rpt_tpl_vis_jumbo.js 58 KB

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