123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- /**
- * Created by Tony on 2018/9/4.
- */
- let virtualCommonOprObj = {
- 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;
- },
- getActPosEx: function (textNode, caclObj, typeStr, baseMea) {
- let me = this;
- if (typeof caclObj === 'string') {
- return me.getActPos(textNode, caclObj, typeStr, baseMea);
- } else {
- return me.getActPos(textNode, caclObj[typeStr], typeStr, baseMea);
- }
- },
- pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) {
- let me = this, pos = me.getActPosEx(textNode, caclObj, typeStr, baseMea);
- if (posArr.indexOf(pos) < 0) posArr.push(pos);
- },
- getBandEx: function (bandName, rptTpl) {
- let me = this, rst;
- for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
- rst = me.getBand(bandName, band);
- if (rst !== null) {
- break;
- }
- }
- return rst;
- },
- getBand: function (bandName, parentBand) {
- let me = this, 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 = me.getBand(bandName, subBand);
- if (rst !== null) {
- break;
- }
- }
- }
- }
- return rst;
- },
- checkInSpan: function (spans, 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;
- },
- setupHeightWidth: function (dest, text, colWidthArr, rowHeightArr) {
- let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
- dest[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
- if (text.col > 0) {
- dest[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
- } else {
- dest[JV.PROP_AREA][JV.PROP_LEFT] = 0;
- }
- dest[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2);
- if (text.row > 0) {
- dest[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2);
- } else {
- dest[JV.PROP_AREA][JV.PROP_TOP] = 0;
- }
- },
- createTxtNode: function (text, parentNode, colWidthArr, rowHeightArr) {
- let me = this, rst = dataInfoMapTreeOprObj.getDummyTextNode(parentNode);
- me.setupHeightWidth(rst, text, colWidthArr, rowHeightArr);
- if (stringUtil.isEmptyString(text[`text`])) {
- rst[JV.PROP_NAME] = '';
- } else {
- rst[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`].toString(), '\n', '|'), '\r', '');
- }
- rst[JV.PROP_LABEL] = rst[JV.PROP_NAME];
- return rst;
- },
- collectSheetTxt: function (sheet, texts, reserveRows, colWidthArr, rowHeightArr) {
- let spans= sheet.getSpans();
- let private_build_pre_text = function (row, col, rowCount, colCount) {
- let cell = sheet.getCell(row, col);
- let textValue = sheet.getValue(row, col);
- if (textValue && cell.cellType().typeName === '7') {
- textValue = `{` + textValue + `}`;
- }
- texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": textValue});
- };
- for (let span of spans) {
- private_build_pre_text(span.row, span.col, span.rowCount, span.colCount);
- }
- for (let iRow = 0; iRow < sheet.getRowCount() - reserveRows; 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 (!virtualCommonOprObj.checkInSpan(spans, 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;
- }
- });
- },
- addSpan: function (itemNode, sheet, bandW, bandH, xPos, yPos, sheetAreaType) {
- let me = this;
- let idx1 = xPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
- let idx2 = xPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos));
- let idy1 = yPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos));
- let idy2 = yPos.indexOf(me.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, sheetAreaType);
- }
- let cell = sheet.getCell(idy1, idx1, sheetAreaType);
- if (sheetAreaType === GC.Spread.Sheets.SheetArea.viewport) {
- if (itemNode.FieldID) {
- me.changeCellType(cell, 'field');
- } else {
- me.changeCellType(cell, 'text');
- }
- }
- me.setupCell(cell, itemNode);
- },
- changeBandHeight: function (bandName, newHeight) {
- let nodes = bandTreeOprObj.treeObj.getNodes()[0][JV.BAND_PROP_SUB_BANDS];
- let private_set_band_height = function(bNode) {
- let rst = false;
- if (bNode[JV.PROP_NAME] === bandName) {
- bNode[JV.BAND_PROP_HEIGHT] = newHeight;
- rst = true;
- } else if (bNode[JV.BAND_PROP_SUB_BANDS] && bNode[JV.BAND_PROP_SUB_BANDS].length > 0){
- for (let subNode of bNode[JV.BAND_PROP_SUB_BANDS]) {
- rst = private_set_band_height(subNode);
- if (rst) break;
- }
- }
- return rst;
- };
- for (let bandNode of nodes) {
- if (private_set_band_height(bandNode)) break;
- }
- },
- changeCellType: function (cell, newType) {
- switch (newType) {
- case `field`:
- let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
- let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
- let selectableFields = virtualCommonOprObj.getSelectedFields(rptTpl);
- cellType.items(selectableFields);
- cell.cellType(cellType);
- cell.backColor("LightCyan");
- break;
- case `text`:
- default:
- cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
- cell.value(``);
- cell.backColor(undefined);
- break;
- }
- },
- setupCell: function (cell, itemNode) {
- let me = this;
- me.private_setCellFont(cell, itemNode);
- me.private_setCellControl(cell, itemNode);
- me.private_setCellStyle(cell, itemNode);
- let value = itemNode[JV.PROP_NAME];
- if (itemNode[JV.PROP_NAME].indexOf(`|`) >= 0) {
- value = itemNode[JV.PROP_NAME].split('|').join('\n');
- }
- cell.wordWrap(true);
- cell.value(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;
- }
- }
- },
- 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;
- },
- setupCellDft: function (cell) {
- cell.font(`9pt 宋体`);
- cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
- cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
- cell.wordWrap(true);
- cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
- cell.value(``);
- }
- };
|