rpt_tpl_field_location.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /**
  2. * Created by Tony on 2018/8/21.
  3. */
  4. let fieldLocationOprObj = {
  5. columnWorkBook: null,
  6. columnParentNode: null,
  7. contentParentNode: null,
  8. columnFieldCtrls: null,
  9. iniSpreadJs: function (columnParentNode, contentParentNode) {
  10. let me = this;
  11. if (me.columnWorkBook === null) {
  12. me.columnWorkBook = new GC.Spread.Sheets.Workbook($('#rptTplColumnWorkbook')[0], {sheetCount: 1});
  13. // me.columnWorkBook.setHei
  14. me.columnWorkBook.options.tabStripVisible = false;
  15. // me.columnWorkBook.options.scrollbarMaxAlign = true;
  16. me.columnWorkBook.options.allowCopyPasteExcelStyle = false;
  17. // me.columnWorkBook.options.allowExtendPasteRange = isExtendPaste? true : false;
  18. me.columnWorkBook.options.allowUserDragDrop = false;
  19. me.columnWorkBook.options.allowContextMenu = false;
  20. let sheet = me.columnWorkBook.getActiveSheet();
  21. sheet.options.allowCellOverflow = false;
  22. sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  23. // sheet.showRowOutline(false);
  24. // sheet.setRowCount(10, GC.Spread.Sheets.SheetArea.viewport);
  25. sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onCellEnter);
  26. }
  27. me.columnParentNode = columnParentNode;
  28. me.contentParentNode = contentParentNode;
  29. },
  30. setupColumn: function (rptTpl, columnParentNode, contentParentNode) {
  31. let me = this, yPos = [], xPos = [];
  32. me.columnFieldCtrls = [];
  33. let bandName = columnParentNode[JV.PROP_BAND_NAME];
  34. let private_getBand = function(parentBand) {
  35. let rst = null;
  36. if (parentBand[JV.PROP_NAME] === bandName) {
  37. rst = parentBand;
  38. } else {
  39. if (parentBand[JV.BAND_PROP_SUB_BANDS] && parentBand[JV.BAND_PROP_SUB_BANDS].length > 0) {
  40. for (let subBand of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  41. rst = private_getBand(subBand);
  42. if (rst !== null) {
  43. break;
  44. }
  45. }
  46. }
  47. }
  48. return rst;
  49. };
  50. let selectedBand;
  51. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  52. selectedBand = private_getBand(band);
  53. if (selectedBand !== null) {
  54. break;
  55. }
  56. }
  57. if (selectedBand !== null) {
  58. let sheet = me.columnWorkBook.getActiveSheet();
  59. sheet.suspendPaint();
  60. sheet.clearSelection();
  61. let spans =sheet.getSpans();
  62. for(let i = 0; i < spans.length; i++)
  63. {
  64. sheet.removeSpan(spans[i].row, spans[i].col, GC.Spread.Sheets.SheetArea.viewport);
  65. }
  66. // sheet.setRowCount(1);
  67. // sheet.setColumnCount(1);
  68. let bandH = Math.round(parseFloat(selectedBand[JV.BAND_PROP_HEIGHT]) / 2.54 * 96);
  69. let bandW = 700;
  70. let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
  71. if (pIdx >= 0) {
  72. 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 );
  73. if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
  74. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
  75. 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 );
  76. }
  77. }
  78. /*/
  79. for (let itemNode of columnParentNode.items) {
  80. //预push一下横向坐标,看看会有多少列
  81. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos);
  82. }
  83. if (xPos.length > 5) {
  84. if ((xPos.length - 5) < 5) {
  85. bandW *= (xPos.length - 5) * 0.1 + 1; //放大一下,纯属为了UI操作方便,看得清一些
  86. } else {
  87. bandW *= 1.5; //最大1.5倍
  88. }
  89. }
  90. xPos = [];
  91. //*/
  92. for (let itemNode of columnParentNode.items) {
  93. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos);
  94. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos);
  95. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos);
  96. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH, yPos);
  97. }
  98. sheet.setRowCount(yPos.length, GC.Spread.Sheets.SheetArea.viewport);
  99. sheet.setColumnCount(xPos.length - 1, GC.Spread.Sheets.SheetArea.viewport);
  100. for (let idx = 1; idx < xPos.length; idx++) {
  101. me.columnFieldCtrls.push(me.private_create_dft_ctrl());
  102. }
  103. // sheet.clear();
  104. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  105. let selectableFields = me.private_getSelectedFields(rptTpl);
  106. cellType.items(selectableFields);
  107. //设置 最后一行为 行数据选择combobox
  108. let iSelectedRow = sheet.getRowCount() - 1;
  109. sheet.setRowHeight(iSelectedRow, 20);
  110. sheet.getRange(iSelectedRow, -1, 1, -1).backColor("LightCyan");
  111. sheet.getRange(iSelectedRow, -1, 1, -1).locked(true);
  112. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  113. sheet.getCell(iSelectedRow, jCol).cellType(cellType);
  114. }
  115. xPos.sort(function(x1, x2){
  116. return (x1 - x2);
  117. });
  118. yPos.sort(function(y1, y2){
  119. return (y1 - y2);
  120. });
  121. for (let contentItemNode of contentParentNode.items) {
  122. let idxCol = xPos.indexOf(me.private_getActPosEx(contentItemNode, contentItemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
  123. sheet.getCell(iSelectedRow, idxCol).value(contentItemNode[JV.PROP_NAME]);
  124. me.private_merge_ctrl(rptTpl, idxCol, contentItemNode, null);
  125. }
  126. for (let idx = 1; idx < xPos.length; idx++) {
  127. sheet.setColumnWidth(idx - 1, xPos[idx] - xPos[idx - 1]);
  128. }
  129. for (let idx = 1; idx < yPos.length; idx++) {
  130. sheet.setRowHeight(idx - 1, yPos[idx] - yPos[idx - 1]);
  131. sheet.getRange(idx - 1, -1, 1, -1).backColor(undefined);
  132. }
  133. for (let itemNode of columnParentNode.items) {
  134. let idx1 = xPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
  135. let idx2 = xPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos));
  136. let idy1 = yPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos));
  137. let idy2 = yPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH, yPos));
  138. if (idx2 - idx1 > 1 || idy2 - idy1 > 1) {
  139. sheet.addSpan(idy1, idx1, idy2 - idy1, idx2 - idx1, GC.Spread.Sheets.SheetArea.viewport);
  140. }
  141. me.private_setupCell(sheet.getCell(idy1, idx1), rptTpl, itemNode);
  142. }
  143. sheet.resumePaint();
  144. }
  145. },
  146. onCellEnter: function (sender, args) {
  147. let me = fieldLocationOprObj,
  148. sheet = me.columnWorkBook.getActiveSheet();
  149. if (args.row === sheet.getRowCount() - 1) {
  150. me.private_setup_control_options(true);
  151. me.private_update_ctrl_cfg(args.col);
  152. } else {
  153. me.private_setup_control_options(false);
  154. }
  155. },
  156. addRow: function () {
  157. let me = fieldLocationOprObj,
  158. sheet = me.columnWorkBook.getActiveSheet();
  159. sheet.addRows(sheet.getRowCount() - 1, 1);
  160. },
  161. deleteRow: function () {
  162. let me = fieldLocationOprObj,
  163. sheet = me.columnWorkBook.getActiveSheet(),
  164. selectedRanges = sheet.getSelections()
  165. ;
  166. if (selectedRanges.length > 0) {
  167. sheet.deleteRows(selectedRanges[0].row, 1);
  168. }
  169. },
  170. addCol: function (rptTpl) {
  171. let me = fieldLocationOprObj,
  172. sheet = me.columnWorkBook.getActiveSheet();
  173. sheet.suspendPaint();
  174. sheet.addColumns(sheet.getColumnCount(), 1);
  175. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  176. let selectableFields = me.private_getSelectedFields(rptTpl);
  177. cellType.items(selectableFields);
  178. //设置 最后一行为 行数据选择combobox
  179. // sheet.getRange(sheet.getRowCount() - 1, -1, 1, -1).locked(true);
  180. let colIdx = sheet.getColumnCount() - 1;
  181. sheet.getCell(sheet.getRowCount() - 1, colIdx).cellType(cellType);
  182. for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
  183. me.private_setupCellDft(sheet.getCell(iRow, colIdx));
  184. }
  185. //
  186. me.columnFieldCtrls.push(me.private_create_dft_ctrl());
  187. sheet.resumePaint();
  188. },
  189. deleteCol: function () {
  190. let me = fieldLocationOprObj,
  191. sheet = me.columnWorkBook.getActiveSheet(),
  192. selectedRanges = sheet.getSelections()
  193. ;
  194. if (selectedRanges.length > 0) {
  195. sheet.deleteColumns(selectedRanges[0].col, 1);
  196. }
  197. },
  198. mergeCells: function () {
  199. let me = fieldLocationOprObj,
  200. sheet = me.columnWorkBook.getActiveSheet();
  201. let selectedRanges = sheet.getSelections();
  202. if (selectedRanges.length > 0) {
  203. if (selectedRanges[0].row + selectedRanges[0].rowCount < sheet.getRowCount()) {
  204. sheet.suspendPaint();
  205. sheet.addSpan(selectedRanges[0].row, selectedRanges[0].col, selectedRanges[0].rowCount, selectedRanges[0].colCount);
  206. sheet.resumePaint();
  207. } else {
  208. alert("指标列不能被合并!")
  209. }
  210. }
  211. },
  212. dismergeCells: function () {
  213. let me = fieldLocationOprObj,
  214. sheet = me.columnWorkBook.getActiveSheet();
  215. let selectedRanges = sheet.getSelections();
  216. let spans =sheet.getSpans();
  217. if (selectedRanges.length > 0 && spans.length > 0) {
  218. let selectedSpans = [];
  219. for(let i = 0; i < spans.length; i++)
  220. {
  221. for (let j = 0; j < selectedRanges.length; j++) {
  222. if (spans[i].row >= selectedRanges[j].row && spans[i].col >= selectedRanges[j].col &&
  223. spans[i].row <= selectedRanges[j].row + selectedRanges[j].rowCount && spans[i].col <= selectedRanges[j].col + selectedRanges[j].colCount) {
  224. selectedSpans.push(spans[i]);
  225. }
  226. }
  227. }
  228. for (let span of selectedSpans) {
  229. sheet.removeSpan(span.row, span.col, GC.Spread.Sheets.SheetArea.viewport);
  230. }
  231. }
  232. },
  233. fitTheWidth: function (factor) {
  234. let me = this, rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  235. let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
  236. let bandW = 700;
  237. if (pIdx >= 0) {
  238. 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 );
  239. if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
  240. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
  241. 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 );
  242. }
  243. }
  244. bandW *= factor;
  245. let currentWidth = 0;
  246. let sheet = me.columnWorkBook.getActiveSheet();
  247. for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
  248. currentWidth += sheet.getColumnWidth(idx);
  249. }
  250. let actFactor = bandW / currentWidth;
  251. for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
  252. sheet.setColumnWidth(idx, Math.round(sheet.getColumnWidth(idx) * actFactor));
  253. }
  254. },
  255. changeCtrl: function (dom) {
  256. let me = fieldLocationOprObj,
  257. sheet = me.columnWorkBook.getActiveSheet(),
  258. fieldRowIdx = sheet.getRowCount() - 1
  259. ;
  260. //sheet.getSelectio
  261. let selectedRanges = sheet.getSelections();
  262. for(let i = 0; i < selectedRanges.length; i++){
  263. if (selectedRanges[i].row === fieldRowIdx) {
  264. let ctrl = me.columnFieldCtrls[selectedRanges[i].col]
  265. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'F';
  266. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'F';
  267. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'F';
  268. ctrl.isNarrow = false;
  269. ctrl.isAutoHeight = false;
  270. if ($("#eleShrinkEx")[0].checked) {
  271. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'T';
  272. }
  273. if ($("#eleShowZeroEx")[0].checked) {
  274. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'T';
  275. }
  276. if ($("#eleAutoWrapEx")[0].checked) {
  277. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'T';
  278. }
  279. if ($("#eleIsNarrowEx")[0].checked) {
  280. ctrl.isNarrow = true;
  281. }
  282. if ($("#eleIsAutoHeightEx")[0].checked) {
  283. ctrl.isAutoHeight = true;
  284. }
  285. if ($("#hOptionLeft")[0].checked) {
  286. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[0];
  287. } else if ($("#hOptionCenter")[0].checked) {
  288. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[1];
  289. } else {
  290. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[2];
  291. }
  292. if ($("#vOptionUp")[0].checked) {
  293. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[0];
  294. } else if ($("#vOptionCenter")[0].checked) {
  295. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[1];
  296. } else {
  297. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[2];
  298. }
  299. }
  300. }
  301. },
  302. private_update_ctrl_cfg: function (ctrlIdx) {
  303. let me = fieldLocationOprObj;
  304. if (ctrlIdx >= 0) {
  305. if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]])) {
  306. $("#eleShrinkEx")[0].checked = true;
  307. } else {
  308. $("#eleShrinkEx")[0].checked = false;
  309. }
  310. if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]])) {
  311. $("#eleShowZeroEx")[0].checked = true;
  312. } else {
  313. $("#eleShowZeroEx")[0].checked = false;
  314. }
  315. if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]])) {
  316. $("#eleAutoWrapEx")[0].checked = true;
  317. } else {
  318. $("#eleAutoWrapEx")[0].checked = false;
  319. }
  320. if (me.columnFieldCtrls[ctrlIdx].isNarrow) {
  321. $("#eleIsNarrowEx")[0].checked = true;
  322. } else {
  323. $("#eleIsNarrowEx")[0].checked = false;
  324. }
  325. if (me.columnFieldCtrls[ctrlIdx].isAutoHeight) {
  326. $("#eleIsAutoHeightEx")[0].checked = true;
  327. } else {
  328. $("#eleIsAutoHeightEx")[0].checked = false;
  329. }
  330. switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  331. case JV.OUTPUT_ALIGN.H[0]:
  332. $("#hOptionLeft")[0].checked = `true`;
  333. break;
  334. case JV.OUTPUT_ALIGN.H[1]:
  335. $("#hOptionCenter")[0].checked = `true`;
  336. break;
  337. default:
  338. $("#hOptionRight")[0].checked = `true`;
  339. break;
  340. }
  341. switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  342. case JV.OUTPUT_ALIGN.V[0]:
  343. $("#vOptionUp")[0].checked = `true`;
  344. break;
  345. case JV.OUTPUT_ALIGN.V[1]:
  346. $("#vOptionCenter")[0].checked = `true`;
  347. break;
  348. default:
  349. $("#vOptionDown")[0].checked = `true`;
  350. break;
  351. }
  352. }
  353. },
  354. private_create_dft_ctrl: function () {
  355. return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
  356. },
  357. private_merge_ctrl: function (rptTpl, srcIdx, fieldNode, directCtrl) {
  358. let me = this, ctrl = null;
  359. if (directCtrl) {
  360. ctrl = directCtrl;
  361. } else {
  362. if (typeof fieldNode[JV.PROP_CONTROL] === 'string') {
  363. let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(fieldNode[JV.PROP_CONTROL]);
  364. if (idx >= 0) {
  365. ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
  366. }
  367. } else {
  368. ctrl = fieldNode[JV.PROP_CONTROL];
  369. }
  370. for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
  371. if (font.ID === fieldNode[JV.PROP_FONT]) {
  372. if (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]].indexOf(`Narrow`) >= 0) {
  373. ctrl.isNarrow = true;
  374. } else {
  375. ctrl.isNarrow = false;
  376. }
  377. break;
  378. }
  379. }
  380. ctrl[JV.PROP_IS_AUTO_HEIGHT] = fieldNode[JV.PROP_IS_AUTO_HEIGHT];
  381. }
  382. if (ctrl) {
  383. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]];
  384. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]];
  385. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]];
  386. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]];
  387. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]];
  388. me.columnFieldCtrls[srcIdx].isNarrow = ctrl.isNarrow;
  389. me.columnFieldCtrls[srcIdx][JV.PROP_IS_AUTO_HEIGHT] = ctrl[JV.PROP_IS_AUTO_HEIGHT];
  390. }
  391. },
  392. private_setup_control_options: function (enable) {
  393. if (enable) {
  394. $("#fieldControlDiv")[0].style.cursor = "";
  395. $("#hOptionLeft")[0].removeAttribute("disabled");
  396. $("#hOptionCenter")[0].removeAttribute("disabled");
  397. $("#hOptionRight")[0].removeAttribute("disabled");
  398. $("#vOptionUp")[0].removeAttribute("disabled");
  399. $("#vOptionCenter")[0].removeAttribute("disabled");
  400. $("#vOptionDown")[0].removeAttribute("disabled");
  401. $("#eleShrinkEx")[0].removeAttribute("disabled");
  402. $("#eleShowZeroEx")[0].removeAttribute("disabled");
  403. $("#eleAutoWrapEx")[0].removeAttribute("disabled");
  404. $("#eleIsNarrowEx")[0].removeAttribute("disabled");
  405. $("#eleIsAutoHeightEx")[0].removeAttribute("disabled");
  406. } else {
  407. $("#fieldControlDiv")[0].style.cursor = "not-allowed";
  408. $("#hOptionLeft")[0].disabled = "disabled" ;
  409. $("#hOptionCenter")[0].disabled = "disabled" ;
  410. $("#hOptionRight")[0].disabled = "disabled" ;
  411. $("#vOptionUp")[0].disabled = "disabled" ;
  412. $("#vOptionCenter")[0].disabled = "disabled" ;
  413. $("#vOptionDown")[0].disabled = "disabled" ;
  414. $("#eleShrinkEx")[0].disabled = "disabled" ;
  415. $("#eleShowZeroEx")[0].disabled = "disabled" ;
  416. $("#eleAutoWrapEx")[0].disabled = "disabled" ;
  417. $("#eleIsNarrowEx")[0].disabled = "disabled" ;
  418. $("#eleIsAutoHeightEx")[0].disabled = "disabled" ;
  419. }
  420. },
  421. private_getSelectedFields: function (rptTpl) {
  422. let rst = [];
  423. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  424. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  425. rst.push(field[JV.PROP_NAME]);
  426. }
  427. }
  428. if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  429. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  430. rst.push(field[JV.PROP_NAME]);
  431. }
  432. }
  433. return rst;
  434. },
  435. private_setupCell: function (cell, rptTpl, textNode) {
  436. let me = this;
  437. me.private_setCellFont(cell, textNode);
  438. me.private_setCellControl(cell, textNode);
  439. me.private_setCellStyle(cell, textNode);
  440. let value = textNode[JV.PROP_NAME];
  441. if (textNode[JV.PROP_NAME].indexOf(`|`) >= 0) {
  442. value = textNode[JV.PROP_NAME].split('|').join('\n');
  443. }
  444. cell.wordWrap(true);
  445. cell.value(value);
  446. },
  447. private_setupCellDft: function (cell) {
  448. cell.font(`9pt 宋体`);
  449. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  450. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  451. cell.wordWrap(true);
  452. cell.value(``);
  453. },
  454. private_setCellControl: function (cell, textNode) {
  455. let ctrl = null;
  456. if (typeof textNode[JV.PROP_CONTROL] === 'string') {
  457. let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(textNode[JV.PROP_CONTROL]);
  458. ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
  459. } else {
  460. ctrl = textNode[JV.PROP_CONTROL];
  461. }
  462. if (ctrl) {
  463. switch (ctrl.Horizon) {
  464. case `center`:
  465. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  466. break;
  467. case `right`:
  468. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  469. break;
  470. default:
  471. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  472. break;
  473. }
  474. switch (ctrl.Vertical) {
  475. case `center`:
  476. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  477. break;
  478. case `bottom`:
  479. cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  480. break;
  481. default:
  482. cell.vAlign(GC.Spread.Sheets.VerticalAlign.top);
  483. break;
  484. }
  485. }
  486. },
  487. private_setCellStyle: function (cell, textNode) {
  488. //默认是normal,暂时不管
  489. },
  490. private_setCellFont: function (cell, textNode) {
  491. for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
  492. if (font.ID === textNode[JV.PROP_FONT]) {
  493. cell.font(Math.round(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]] * 3 / 4) + 'pt ' + font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]]);
  494. break;
  495. }
  496. }
  497. },
  498. private_getActPos: function (textNode, caclStr, typeStr, baseMea) {
  499. let rst = 0;
  500. if (caclStr === JV.CAL_TYPE[0]) {
  501. //percentage
  502. rst = Math.round(baseMea * textNode[JV.PROP_AREA][typeStr] / 100);
  503. } else {
  504. //abstract
  505. rst = Math.round(textNode[JV.PROP_AREA][typeStr] / 2.54 * 96);
  506. }
  507. return rst;
  508. },
  509. private_getActPosEx: function (textNode, caclObj, typeStr, baseMea) {
  510. let me = this;
  511. if (typeof caclObj === 'string') {
  512. return me.private_getActPos(textNode, caclObj, typeStr, baseMea);
  513. } else {
  514. return me.private_getActPos(textNode, caclObj[typeStr], typeStr, baseMea);
  515. }
  516. },
  517. private_pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) {
  518. let me = this, pos = me.private_getActPosEx(textNode, caclObj, typeStr, baseMea);
  519. if (posArr.indexOf(pos) < 0) posArr.push(pos);
  520. },
  521. private_create_content_node: function (colWidthArr, cellValue, colIdx, rptTpl) {
  522. let me = this;
  523. let rst = {"Name": cellValue, "Title": '', "FieldID": -1, "font": "Content", "control": "Column", "style" : "Default_Normal", "isAutoHeight" : false,
  524. "area" : {"Left" : 0, "Right" : 100, "Top" : 0, "Bottom" : 100, "H_CalculationType" : "percentage", "V_CalculationType" : "percentage"}
  525. };
  526. //1. 设置FieldID
  527. let hasChkField = false;
  528. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  529. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  530. if (field[JV.PROP_NAME] === cellValue) {
  531. rst.FieldID = field[JV.PROP_ID];
  532. rst["Title"] = "ID: " + field[JV.PROP_ID];
  533. hasChkField = true;
  534. break;
  535. }
  536. }
  537. }
  538. if (!hasChkField && rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  539. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  540. if (field[JV.PROP_NAME] === cellValue) {
  541. rst.FieldID = field[JV.PROP_ID];
  542. rst["Title"] = "ID: " + field[JV.PROP_ID];
  543. hasChkField = true;
  544. break;
  545. }
  546. }
  547. }
  548. //2. 字体
  549. if (me.columnFieldCtrls[colIdx].isNarrow) {
  550. rst[JV.PROP_FONT] = "Content_Narrow";
  551. }
  552. //3. 自动行高
  553. if (me.columnFieldCtrls[colIdx][JV.PROP_IS_AUTO_HEIGHT]) {
  554. rst[JV.PROP_IS_AUTO_HEIGHT] = true;
  555. }
  556. //4. 左右位置%
  557. let width = colWidthArr[colWidthArr.length - 1];
  558. if (colIdx > 0) {
  559. rst[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[colIdx - 1] / width * 100).toFixed(2);
  560. }
  561. rst[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[colIdx] / width * 100).toFixed(2);
  562. if (me.columnFieldCtrls[colIdx]["Vertical"] === "center") {
  563. switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
  564. case "left":
  565. rst["control"] = "Column_Left";
  566. break;
  567. case "center":
  568. rst["control"] = "Column";
  569. break;
  570. default:
  571. rst["control"] = "Column_Right";
  572. break;
  573. }
  574. } else if (me.columnFieldCtrls[colIdx]["Vertical"] === "bottom") {
  575. switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
  576. case "left":
  577. rst["control"] = "Content_Left";
  578. break;
  579. case "center":
  580. rst["control"] = "Content_Center";
  581. break;
  582. default:
  583. rst["control"] = "Content_Right";
  584. break;
  585. }
  586. }
  587. //return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
  588. return rst;
  589. },
  590. applyBack: function () {
  591. let me = this;
  592. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  593. if (rptTpl && me.columnParentNode && me.contentParentNode) {
  594. let sheet = me.columnWorkBook.getActiveSheet();
  595. if (sheet.getRowCount() > 1 && sheet.getColumnCount() > 0) {
  596. let spans= sheet.getSpans();
  597. let texts = [], colWidthArr = [], rowHeightArr = [];
  598. let private_build_pre_text = function (row, col, rowCount, colCount) {
  599. texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": sheet.getValue(row, col)});
  600. };
  601. let private_chk_in_span = function (row, col) {
  602. let rst = false;
  603. for (let span of spans) {
  604. if (span.row <= row && row < (span.row + span.rowCount) && span.col <= col && col < (span.col + span.colCount)) {
  605. rst = true;
  606. break;
  607. }
  608. }
  609. return rst;
  610. };
  611. for (let span of spans) {
  612. private_build_pre_text(span.row, span.col, span.rowCount, span.colCount);
  613. }
  614. for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
  615. rowHeightArr.push(sheet.getRowHeight(iRow));
  616. if (iRow > 0) {
  617. rowHeightArr[iRow] = rowHeightArr[iRow] + rowHeightArr[iRow - 1];
  618. }
  619. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  620. if (iRow === 0) {
  621. colWidthArr.push(sheet.getColumnWidth(jCol));
  622. if (jCol > 0) {
  623. colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1];
  624. }
  625. }
  626. if (!private_chk_in_span(iRow, jCol)) {
  627. private_build_pre_text(iRow, jCol, 1, 1);
  628. }
  629. }
  630. }
  631. texts.sort(function(t1, t2){
  632. if (t1.col === t2.col) {
  633. return t1.row - t2.row;
  634. } else {
  635. return t1.col - t2.col;
  636. }
  637. });
  638. let nodes = [];
  639. let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
  640. //表栏重置
  641. //0. 先清除原先所有的column text
  642. dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.columnParentNode);
  643. //1. 需要重新设置columnBand的高度
  644. //2. 重新生成text节点
  645. for (let text of texts) {
  646. let node = dataInfoMapTreeOprObj.getDummyTextNode(me.columnParentNode);
  647. node[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
  648. if (text.col > 0) {
  649. node[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
  650. } else {
  651. node[JV.PROP_AREA][JV.PROP_LEFT] = 0;
  652. }
  653. node[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2);
  654. if (text.row > 0) {
  655. node[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2);
  656. } else {
  657. node[JV.PROP_AREA][JV.PROP_TOP] = 0;
  658. }
  659. node[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`], '\n', '|'), '\r', '');
  660. node[JV.PROP_LABEL] = node[JV.PROP_NAME];
  661. nodes.push(node);
  662. }
  663. dataInfoMapTreeOprObj.treeObj.addNodes(me.columnParentNode, -1, nodes, true);
  664. //内容重置
  665. //0. 先清除原先所有的content node
  666. dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.contentParentNode);
  667. //1. 重新生成节点
  668. let contentNodes = [];
  669. let contenRowIdx = sheet.getRowCount() - 1;
  670. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  671. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  672. let cellValue = sheet.getValue(contenRowIdx, iCol);
  673. if (!(stringUtil.isEmptyString(cellValue))) {
  674. contentNodes.push(me.private_create_content_node(colWidthArr, cellValue, iCol, rptTpl));
  675. }
  676. }
  677. dataInfoMapTreeOprObj.treeObj.addNodes(me.contentParentNode, -1, contentNodes, true);
  678. }
  679. }
  680. }
  681. };