rpt_tpl_field_location.js 34 KB

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