123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- /**
- * Created by Tony on 2018/8/21.
- */
- let fieldLocationOprObj = {
- columnWorkBook: null,
- columnParentNode: null,
- contentParentNode: null,
- columnFieldCtrls: null,
- iniSpreadJs: function (columnParentNode, contentParentNode) {
- let me = this;
- if (me.columnWorkBook === null) {
- me.columnWorkBook = new GC.Spread.Sheets.Workbook($('#rptTplColumnWorkbook')[0], {sheetCount: 1});
- // me.columnWorkBook.setHei
- me.columnWorkBook.options.tabStripVisible = false;
- // me.columnWorkBook.options.scrollbarMaxAlign = true;
- me.columnWorkBook.options.allowCopyPasteExcelStyle = false;
- // me.columnWorkBook.options.allowExtendPasteRange = isExtendPaste? true : false;
- me.columnWorkBook.options.allowUserDragDrop = false;
- me.columnWorkBook.options.allowContextMenu = false;
- let sheet = me.columnWorkBook.getActiveSheet();
- sheet.options.allowCellOverflow = false;
- sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
- // sheet.showRowOutline(false);
- // sheet.setRowCount(10, GC.Spread.Sheets.SheetArea.viewport);
- sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onCellEnter);
- }
- me.columnParentNode = columnParentNode;
- me.contentParentNode = contentParentNode;
- },
- setupColumn: function (rptTpl, columnParentNode, contentParentNode) {
- let me = this, yPos = [], xPos = [];
- me.columnFieldCtrls = [];
- let bandName = columnParentNode[JV.PROP_BAND_NAME];
- let private_getBand = function(parentBand) {
- let rst = null;
- if (parentBand[JV.PROP_NAME] === bandName) {
- rst = parentBand;
- } else {
- if (parentBand[JV.BAND_PROP_SUB_BANDS] && parentBand[JV.BAND_PROP_SUB_BANDS].length > 0) {
- for (let subBand of parentBand[JV.BAND_PROP_SUB_BANDS]) {
- rst = private_getBand(subBand);
- if (rst !== null) {
- break;
- }
- }
- }
- }
- return rst;
- };
- let selectedBand;
- for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
- selectedBand = private_getBand(band);
- if (selectedBand !== null) {
- break;
- }
- }
- if (selectedBand !== null) {
- let sheet = me.columnWorkBook.getActiveSheet();
- sheet.suspendPaint();
- sheet.clearSelection();
- let spans =sheet.getSpans();
- for(let i = 0; i < spans.length; i++)
- {
- sheet.removeSpan(spans[i].row, spans[i].col, GC.Spread.Sheets.SheetArea.viewport);
- }
- // sheet.setRowCount(1);
- // sheet.setColumnCount(1);
- let bandH = Math.round(parseFloat(selectedBand[JV.BAND_PROP_HEIGHT]) / 2.54 * 96);
- let bandW = 700;
- let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
- if (pIdx >= 0) {
- 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 );
- if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
- 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 );
- }
- }
- /*/
- for (let itemNode of columnParentNode.items) {
- //预push一下横向坐标,看看会有多少列
- me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos);
- }
- if (xPos.length > 5) {
- if ((xPos.length - 5) < 5) {
- bandW *= (xPos.length - 5) * 0.1 + 1; //放大一下,纯属为了UI操作方便,看得清一些
- } else {
- bandW *= 1.5; //最大1.5倍
- }
- }
- xPos = [];
- //*/
- for (let itemNode of columnParentNode.items) {
- me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos);
- me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos);
- me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos);
- me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH, yPos);
- }
- sheet.setRowCount(yPos.length, GC.Spread.Sheets.SheetArea.viewport);
- sheet.setColumnCount(xPos.length - 1, GC.Spread.Sheets.SheetArea.viewport);
- for (let idx = 1; idx < xPos.length; idx++) {
- me.columnFieldCtrls.push(me.private_create_dft_ctrl());
- }
- // sheet.clear();
- let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
- let selectableFields = me.private_getSelectedFields(rptTpl);
- cellType.items(selectableFields);
- //设置 最后一行为 行数据选择combobox
- let iSelectedRow = sheet.getRowCount() - 1;
- sheet.setRowHeight(iSelectedRow, 20);
- sheet.getRange(iSelectedRow, -1, 1, -1).backColor("LightCyan");
- sheet.getRange(iSelectedRow, -1, 1, -1).locked(true);
- for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
- sheet.getCell(iSelectedRow, jCol).cellType(cellType);
- }
- xPos.sort(function(x1, x2){
- return (x1 - x2);
- });
- yPos.sort(function(y1, y2){
- return (y1 - y2);
- });
- for (let contentItemNode of contentParentNode.items) {
- let idxCol = xPos.indexOf(me.private_getActPosEx(contentItemNode, contentItemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
- sheet.getCell(iSelectedRow, idxCol).value(contentItemNode[JV.PROP_NAME]);
- me.private_merge_ctrl(rptTpl, idxCol, contentItemNode, null);
- }
- for (let idx = 1; idx < xPos.length; idx++) {
- sheet.setColumnWidth(idx - 1, xPos[idx] - xPos[idx - 1]);
- }
- for (let idx = 1; idx < yPos.length; idx++) {
- sheet.setRowHeight(idx - 1, yPos[idx] - yPos[idx - 1]);
- sheet.getRange(idx - 1, -1, 1, -1).backColor(undefined);
- }
- for (let itemNode of columnParentNode.items) {
- let idx1 = xPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
- let idx2 = xPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos));
- let idy1 = yPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos));
- let idy2 = yPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH, yPos));
- if (idx2 - idx1 > 1 || idy2 - idy1 > 1) {
- sheet.addSpan(idy1, idx1, idy2 - idy1, idx2 - idx1, GC.Spread.Sheets.SheetArea.viewport);
- }
- me.private_setupCell(sheet.getCell(idy1, idx1), rptTpl, itemNode);
- }
- sheet.resumePaint();
- }
- },
- onCellEnter: function (sender, args) {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet();
- if (args.row === sheet.getRowCount() - 1) {
- me.private_setup_control_options(true);
- me.private_update_ctrl_cfg(args.col);
- } else {
- me.private_setup_control_options(false);
- }
- },
- addRow: function () {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet();
- sheet.addRows(sheet.getRowCount() - 1, 1);
- },
- deleteRow: function () {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet(),
- selectedRanges = sheet.getSelections()
- ;
- if (selectedRanges.length > 0) {
- sheet.deleteRows(selectedRanges[0].row, 1);
- }
- },
- addCol: function (rptTpl) {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet();
- sheet.suspendPaint();
- sheet.addColumns(sheet.getColumnCount(), 1);
- let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
- let selectableFields = me.private_getSelectedFields(rptTpl);
- cellType.items(selectableFields);
- //设置 最后一行为 行数据选择combobox
- // sheet.getRange(sheet.getRowCount() - 1, -1, 1, -1).locked(true);
- let colIdx = sheet.getColumnCount() - 1;
- sheet.getCell(sheet.getRowCount() - 1, colIdx).cellType(cellType);
- for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
- me.private_setupCellDft(sheet.getCell(iRow, colIdx));
- }
- //
- me.columnFieldCtrls.push(me.private_create_dft_ctrl());
- sheet.resumePaint();
- },
- deleteCol: function () {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet(),
- selectedRanges = sheet.getSelections()
- ;
- if (selectedRanges.length > 0) {
- sheet.deleteColumns(selectedRanges[0].col, 1);
- }
- },
- mergeCells: function () {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- if (selectedRanges.length > 0) {
- if (selectedRanges[0].row + selectedRanges[0].rowCount < sheet.getRowCount()) {
- sheet.suspendPaint();
- sheet.addSpan(selectedRanges[0].row, selectedRanges[0].col, selectedRanges[0].rowCount, selectedRanges[0].colCount);
- sheet.resumePaint();
- } else {
- alert("指标列不能被合并!")
- }
- }
- },
- dismergeCells: function () {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet();
- let selectedRanges = sheet.getSelections();
- let spans =sheet.getSpans();
- if (selectedRanges.length > 0 && spans.length > 0) {
- let selectedSpans = [];
- for(let i = 0; i < spans.length; i++)
- {
- for (let j = 0; j < selectedRanges.length; j++) {
- if (spans[i].row >= selectedRanges[j].row && spans[i].col >= selectedRanges[j].col &&
- spans[i].row <= selectedRanges[j].row + selectedRanges[j].rowCount && spans[i].col <= selectedRanges[j].col + selectedRanges[j].colCount) {
- selectedSpans.push(spans[i]);
- }
- }
- }
- for (let span of selectedSpans) {
- sheet.removeSpan(span.row, span.col, GC.Spread.Sheets.SheetArea.viewport);
- }
- }
- },
- fitTheWidth: function (factor) {
- let me = this, rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
- let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
- let bandW = 700;
- if (pIdx >= 0) {
- 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 );
- if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
- 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 );
- }
- }
- bandW *= factor;
- let currentWidth = 0;
- let sheet = me.columnWorkBook.getActiveSheet();
- for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
- currentWidth += sheet.getColumnWidth(idx);
- }
- let actFactor = bandW / currentWidth;
- for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
- sheet.setColumnWidth(idx, Math.round(sheet.getColumnWidth(idx) * actFactor));
- }
- },
- changeCtrl: function (dom) {
- let me = fieldLocationOprObj,
- sheet = me.columnWorkBook.getActiveSheet(),
- fieldRowIdx = sheet.getRowCount() - 1
- ;
- //sheet.getSelectio
- let selectedRanges = sheet.getSelections();
- for(let i = 0; i < selectedRanges.length; i++){
- if (selectedRanges[i].row === fieldRowIdx) {
- let ctrl = me.columnFieldCtrls[selectedRanges[i].col]
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'F';
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'F';
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'F';
- ctrl.isNarrow = false;
- ctrl.isAutoHeight = false;
- if ($("#eleShrinkEx")[0].checked) {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'T';
- }
- if ($("#eleShowZeroEx")[0].checked) {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'T';
- }
- if ($("#eleAutoWrapEx")[0].checked) {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'T';
- }
- if ($("#eleIsNarrowEx")[0].checked) {
- ctrl.isNarrow = true;
- }
- if ($("#eleIsAutoHeightEx")[0].checked) {
- ctrl.isAutoHeight = true;
- }
- if ($("#hOptionLeft")[0].checked) {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[0];
- } else if ($("#hOptionCenter")[0].checked) {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[1];
- } else {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[2];
- }
- if ($("#vOptionUp")[0].checked) {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[0];
- } else if ($("#vOptionCenter")[0].checked) {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[1];
- } else {
- ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[2];
- }
- }
- }
- },
- private_update_ctrl_cfg: function (ctrlIdx) {
- let me = fieldLocationOprObj;
- if (ctrlIdx >= 0) {
- if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]])) {
- $("#eleShrinkEx")[0].checked = true;
- } else {
- $("#eleShrinkEx")[0].checked = false;
- }
- if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]])) {
- $("#eleShowZeroEx")[0].checked = true;
- } else {
- $("#eleShowZeroEx")[0].checked = false;
- }
- if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]])) {
- $("#eleAutoWrapEx")[0].checked = true;
- } else {
- $("#eleAutoWrapEx")[0].checked = false;
- }
- if (me.columnFieldCtrls[ctrlIdx].isNarrow) {
- $("#eleIsNarrowEx")[0].checked = true;
- } else {
- $("#eleIsNarrowEx")[0].checked = false;
- }
- if (me.columnFieldCtrls[ctrlIdx].isAutoHeight) {
- $("#eleIsAutoHeightEx")[0].checked = true;
- } else {
- $("#eleIsAutoHeightEx")[0].checked = false;
- }
- switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
- case JV.OUTPUT_ALIGN.H[0]:
- $("#hOptionLeft")[0].checked = `true`;
- break;
- case JV.OUTPUT_ALIGN.H[1]:
- $("#hOptionCenter")[0].checked = `true`;
- break;
- default:
- $("#hOptionRight")[0].checked = `true`;
- break;
- }
- switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
- case JV.OUTPUT_ALIGN.V[0]:
- $("#vOptionUp")[0].checked = `true`;
- break;
- case JV.OUTPUT_ALIGN.V[1]:
- $("#vOptionCenter")[0].checked = `true`;
- break;
- default:
- $("#vOptionDown")[0].checked = `true`;
- break;
- }
- }
- },
- private_create_dft_ctrl: function () {
- return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
- },
- private_merge_ctrl: function (rptTpl, srcIdx, fieldNode, directCtrl) {
- let me = this, ctrl = null;
- if (directCtrl) {
- ctrl = directCtrl;
- } else {
- if (typeof fieldNode[JV.PROP_CONTROL] === 'string') {
- let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(fieldNode[JV.PROP_CONTROL]);
- if (idx >= 0) {
- ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
- }
- } else {
- ctrl = fieldNode[JV.PROP_CONTROL];
- }
- for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
- if (font.ID === fieldNode[JV.PROP_FONT]) {
- if (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]].indexOf(`Narrow`) >= 0) {
- ctrl.isNarrow = true;
- } else {
- ctrl.isNarrow = false;
- }
- break;
- }
- }
- ctrl[JV.PROP_IS_AUTO_HEIGHT] = fieldNode[JV.PROP_IS_AUTO_HEIGHT];
- }
- if (ctrl) {
- me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]];
- me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]];
- me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]];
- me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]];
- me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]];
- me.columnFieldCtrls[srcIdx].isNarrow = ctrl.isNarrow;
- me.columnFieldCtrls[srcIdx][JV.PROP_IS_AUTO_HEIGHT] = ctrl[JV.PROP_IS_AUTO_HEIGHT];
- }
- },
- private_setup_control_options: function (enable) {
- if (enable) {
- $("#fieldControlDiv")[0].style.cursor = "";
- $("#hOptionLeft")[0].removeAttribute("disabled");
- $("#hOptionCenter")[0].removeAttribute("disabled");
- $("#hOptionRight")[0].removeAttribute("disabled");
- $("#vOptionUp")[0].removeAttribute("disabled");
- $("#vOptionCenter")[0].removeAttribute("disabled");
- $("#vOptionDown")[0].removeAttribute("disabled");
- $("#eleShrinkEx")[0].removeAttribute("disabled");
- $("#eleShowZeroEx")[0].removeAttribute("disabled");
- $("#eleAutoWrapEx")[0].removeAttribute("disabled");
- $("#eleIsNarrowEx")[0].removeAttribute("disabled");
- $("#eleIsAutoHeightEx")[0].removeAttribute("disabled");
- } else {
- $("#fieldControlDiv")[0].style.cursor = "not-allowed";
- $("#hOptionLeft")[0].disabled = "disabled" ;
- $("#hOptionCenter")[0].disabled = "disabled" ;
- $("#hOptionRight")[0].disabled = "disabled" ;
- $("#vOptionUp")[0].disabled = "disabled" ;
- $("#vOptionCenter")[0].disabled = "disabled" ;
- $("#vOptionDown")[0].disabled = "disabled" ;
- $("#eleShrinkEx")[0].disabled = "disabled" ;
- $("#eleShowZeroEx")[0].disabled = "disabled" ;
- $("#eleAutoWrapEx")[0].disabled = "disabled" ;
- $("#eleIsNarrowEx")[0].disabled = "disabled" ;
- $("#eleIsAutoHeightEx")[0].disabled = "disabled" ;
- }
- },
- private_getSelectedFields: function (rptTpl) {
- let rst = [];
- if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
- for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
- rst.push(field[JV.PROP_NAME]);
- }
- }
- if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
- for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
- rst.push(field[JV.PROP_NAME]);
- }
- }
- return rst;
- },
- private_setupCell: function (cell, rptTpl, textNode) {
- let me = this;
- me.private_setCellFont(cell, textNode);
- me.private_setCellControl(cell, textNode);
- me.private_setCellStyle(cell, textNode);
- let value = textNode[JV.PROP_NAME];
- if (textNode[JV.PROP_NAME].indexOf(`|`) >= 0) {
- value = textNode[JV.PROP_NAME].split('|').join('\n');
- }
- cell.wordWrap(true);
- cell.value(value);
- },
- private_setupCellDft: function (cell) {
- cell.font(`9pt 宋体`);
- cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
- cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
- cell.wordWrap(true);
- cell.value(``);
- },
- private_setCellControl: function (cell, textNode) {
- let ctrl = null;
- if (typeof textNode[JV.PROP_CONTROL] === 'string') {
- let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(textNode[JV.PROP_CONTROL]);
- ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
- } else {
- ctrl = textNode[JV.PROP_CONTROL];
- }
- if (ctrl) {
- switch (ctrl.Horizon) {
- case `center`:
- cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
- break;
- case `right`:
- cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
- break;
- default:
- cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
- break;
- }
- switch (ctrl.Vertical) {
- case `center`:
- cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
- break;
- case `bottom`:
- cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
- break;
- default:
- cell.vAlign(GC.Spread.Sheets.VerticalAlign.top);
- break;
- }
- }
- },
- private_setCellStyle: function (cell, textNode) {
- //默认是normal,暂时不管
- },
- private_setCellFont: function (cell, textNode) {
- for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
- if (font.ID === textNode[JV.PROP_FONT]) {
- 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]]);
- break;
- }
- }
- },
- private_getActPos: function (textNode, caclStr, typeStr, baseMea) {
- let rst = 0;
- if (caclStr === JV.CAL_TYPE[0]) {
- //percentage
- rst = Math.round(baseMea * textNode[JV.PROP_AREA][typeStr] / 100);
- } else {
- //abstract
- rst = Math.round(textNode[JV.PROP_AREA][typeStr] / 2.54 * 96);
- }
- return rst;
- },
- private_getActPosEx: function (textNode, caclObj, typeStr, baseMea) {
- let me = this;
- if (typeof caclObj === 'string') {
- return me.private_getActPos(textNode, caclObj, typeStr, baseMea);
- } else {
- return me.private_getActPos(textNode, caclObj[typeStr], typeStr, baseMea);
- }
- },
- private_pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) {
- let me = this, pos = me.private_getActPosEx(textNode, caclObj, typeStr, baseMea);
- if (posArr.indexOf(pos) < 0) posArr.push(pos);
- },
- private_create_content_node: function (colWidthArr, cellValue, colIdx, rptTpl) {
- let me = this;
- let rst = {"Name": cellValue, "Title": '', "FieldID": -1, "font": "Content", "control": "Column", "style" : "Default_Normal", "isAutoHeight" : false,
- "area" : {"Left" : 0, "Right" : 100, "Top" : 0, "Bottom" : 100, "H_CalculationType" : "percentage", "V_CalculationType" : "percentage"}
- };
- //1. 设置FieldID
- let hasChkField = false;
- if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
- for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
- if (field[JV.PROP_NAME] === cellValue) {
- rst.FieldID = field[JV.PROP_ID];
- rst["Title"] = "ID: " + field[JV.PROP_ID];
- hasChkField = true;
- break;
- }
- }
- }
- if (!hasChkField && rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
- for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
- if (field[JV.PROP_NAME] === cellValue) {
- rst.FieldID = field[JV.PROP_ID];
- rst["Title"] = "ID: " + field[JV.PROP_ID];
- hasChkField = true;
- break;
- }
- }
- }
- //2. 字体
- if (me.columnFieldCtrls[colIdx].isNarrow) {
- rst[JV.PROP_FONT] = "Content_Narrow";
- }
- //3. 自动行高
- if (me.columnFieldCtrls[colIdx][JV.PROP_IS_AUTO_HEIGHT]) {
- rst[JV.PROP_IS_AUTO_HEIGHT] = true;
- }
- //4. 左右位置%
- let width = colWidthArr[colWidthArr.length - 1];
- if (colIdx > 0) {
- rst[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[colIdx - 1] / width * 100).toFixed(2);
- }
- rst[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[colIdx] / width * 100).toFixed(2);
- if (me.columnFieldCtrls[colIdx]["Vertical"] === "center") {
- switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
- case "left":
- rst["control"] = "Column_Left";
- break;
- case "center":
- rst["control"] = "Column";
- break;
- default:
- rst["control"] = "Column_Right";
- break;
- }
- } else if (me.columnFieldCtrls[colIdx]["Vertical"] === "bottom") {
- switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
- case "left":
- rst["control"] = "Content_Left";
- break;
- case "center":
- rst["control"] = "Content_Center";
- break;
- default:
- rst["control"] = "Content_Right";
- break;
- }
- }
- //return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
- return rst;
- },
- applyBack: function () {
- let me = this;
- let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
- if (rptTpl && me.columnParentNode && me.contentParentNode) {
- let sheet = me.columnWorkBook.getActiveSheet();
- if (sheet.getRowCount() > 1 && sheet.getColumnCount() > 0) {
- let spans= sheet.getSpans();
- let texts = [], colWidthArr = [], rowHeightArr = [];
- let private_build_pre_text = function (row, col, rowCount, colCount) {
- texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": sheet.getValue(row, col)});
- };
- let private_chk_in_span = function (row, col) {
- let rst = false;
- for (let span of spans) {
- if (span.row <= row && row < (span.row + span.rowCount) && span.col <= col && col < (span.col + span.colCount)) {
- rst = true;
- break;
- }
- }
- return rst;
- };
- for (let span of spans) {
- private_build_pre_text(span.row, span.col, span.rowCount, span.colCount);
- }
- for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
- rowHeightArr.push(sheet.getRowHeight(iRow));
- if (iRow > 0) {
- rowHeightArr[iRow] = rowHeightArr[iRow] + rowHeightArr[iRow - 1];
- }
- for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
- if (iRow === 0) {
- colWidthArr.push(sheet.getColumnWidth(jCol));
- if (jCol > 0) {
- colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1];
- }
- }
- if (!private_chk_in_span(iRow, jCol)) {
- private_build_pre_text(iRow, jCol, 1, 1);
- }
- }
- }
- texts.sort(function(t1, t2){
- if (t1.col === t2.col) {
- return t1.row - t2.row;
- } else {
- return t1.col - t2.col;
- }
- });
- let nodes = [];
- let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
- //表栏重置
- //0. 先清除原先所有的column text
- dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.columnParentNode);
- //1. 需要重新设置columnBand的高度
- //2. 重新生成text节点
- for (let text of texts) {
- let node = dataInfoMapTreeOprObj.getDummyTextNode(me.columnParentNode);
- node[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
- if (text.col > 0) {
- node[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
- } else {
- node[JV.PROP_AREA][JV.PROP_LEFT] = 0;
- }
- node[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2);
- if (text.row > 0) {
- node[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2);
- } else {
- node[JV.PROP_AREA][JV.PROP_TOP] = 0;
- }
- node[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`], '\n', '|'), '\r', '');
- node[JV.PROP_LABEL] = node[JV.PROP_NAME];
- nodes.push(node);
- }
- dataInfoMapTreeOprObj.treeObj.addNodes(me.columnParentNode, -1, nodes, true);
- //内容重置
- //0. 先清除原先所有的content node
- dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.contentParentNode);
- //1. 重新生成节点
- let contentNodes = [];
- let contenRowIdx = sheet.getRowCount() - 1;
- let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
- for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
- let cellValue = sheet.getValue(contenRowIdx, iCol);
- if (!(stringUtil.isEmptyString(cellValue))) {
- contentNodes.push(me.private_create_content_node(colWidthArr, cellValue, iCol, rptTpl));
- }
- }
- dataInfoMapTreeOprObj.treeObj.addNodes(me.contentParentNode, -1, contentNodes, true);
- }
- }
- }
- };
|