/** * Created by TonyJiang on 16/11/15. */ import * as React from "react"; import {transaction, observable, extendObservable} from "mobx"; import {DesignerHost} from "../DesignerHost"; import CommandModel from '../ui/ui-model/CommandModel'; import {SelectionService} from "./SelectionService"; import {DataTableCellItem} from "../../items/data-table/DataTableCellItem"; import {Sheet} from "../../../libs/gridview/src/model/sheet/index"; import CommandDataTable from "../ui/ui-model/CommandDataTable"; import {Operation} from "../../../libs/gridview/src/model/operation/index"; import {CellPoint} from "../../../libs/gridview/src/model/common/cell-point"; import {PropertyChangeEventArgs} from "../../items/PropertyChangeEventArgs"; import {Border, BorderItem} from "../../items/properties/classes/Border"; import {Border as GridViewBorder} from "../../../libs/gridview/src/model/sheet/border"; import {LineStyleEnum} from "../../configs/enums"; import {LINE_STYLE, BORDER_POSITION} from "../../../libs/gridview/src/model/common/index"; import {DataTableCellProperty} from "../../items/properties/define"; import {Unit, PointF} from "../../drawing/Unit"; import {ColumnHeaderItem} from "../../../libs/gridview/src/model/sheet/column-header-item"; import {RowHeaderItem} from "../../../libs/gridview/src/model/sheet/row-header-item"; import {CellRange} from "../../../libs/gridview/src/model/common/cell-range"; import {CommandModeEnum} from "../ui/ui-model/CommandDataTable"; import {CommandMenuEvent} from "../ui/ui-model/CommandDataTable"; import {Cell} from "../../../libs/gridview/src/model/sheet/cell"; import {SelectInfo} from "../../../libs/gridview/src/model/lib/select/item"; import {GridView} from "../../../libs/gridview/src/react-gridview"; import DataTableDesigner from "../designer/DataTableDesigner"; import {ReportItemBase} from "../../items/ReportItemBase"; import {SelectionTypes} from "./Enums"; import {OBJECT_TYPE} from "../../../libs/gridview/src/model/sheet/object-type"; import {ColumnHeader} from "../../../libs/gridview/src/model/sheet/column-header"; import {RowHeader} from "../../../libs/gridview/src/model/sheet/row-header"; import {DataTableItem, IDataTableItemConfig, IDataTableType} from "../../items/data-table/DataTableItem"; //我们的线条枚举和GridView线条枚举对应关系 const BorderToGridViewMap = { [LineStyleEnum.Solid]: LINE_STYLE.NORMAL, [LineStyleEnum.Double]: LINE_STYLE.NORMAL, [LineStyleEnum.Dashed]: LINE_STYLE.DOT, [LineStyleEnum.Dotted]: LINE_STYLE.DOT }; //GridView线条枚举对应我们的线条枚举关系 const BorderFromGridViewMap = { [LINE_STYLE.NORMAL]: LineStyleEnum.Solid, [LINE_STYLE.DOT]: LineStyleEnum.Dotted }; //GridView定义border中的key, 在column-header.ts中定义, 0 位置空字符串站位 const borderColumnKey = ["", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; const enum SelectRangeType{ NONE = 0, CELL, RANGE, COLUMN, ROW } //TODO 把operation和sheet都在这里管理, 提供修改sheet的api, 其他地方进行调用 export class DataTableEditService { private _host: DesignerHost; private _selectionService: SelectionService; // private _selectedCellItems:Array; private _selectedMergeCellItems: Array; private _currentOperation: Operation; private _currentRangeItem: CellRange; private _currentSelectRangeType: SelectRangeType; private _state: any; private _gridViewInstance: GridView; private _selectCellActionBatch: Array; //工具类函数 //TODO 重构时应该考虑和DataTableItem中的SheetHandler合并, 成功工具类 _handler = { //创建cellItem createCellItem: (cellPoint:CellPoint) => { const sheet = this.sheet; let cell:Cell = sheet.getCell(cellPoint); //如果当前单元格有merge信息, 找到第一个内容不为空的设置为当前样式, 如果都没有, 使用左上角单元格 if(cell.mergeRange){ if(this._selectedMergeCellItems.indexOf(cell.mergeRange) == -1){ var isBreak = false; sheet.getCells(cell.mergeRange).map( (mergeCell, cellId) => { if(!isBreak && mergeCell.text.length > 0){ cell = mergeCell; cellPoint = CellPoint.fromId(cellId); isBreak = true; } }); if(!isBreak){ cell = sheet.getCell(cell.mergeRange.leftTopPoint); } this._selectedMergeCellItems.push(cell.mergeRange); }else{ return ; } console.log('mergeCell1', cell); } const border = this._handler.createRangeBorder(this.operation.rangeItem); const cellItem = new DataTableCellItem(cell, border); cellItem.setReport(DesignerHost.instance().designReport.report); // 将创建的 cellItem 加入到 TableItem 中 this.item.items.push(cellItem); cellItem.on(DataTableCellItem.PropertyChangeEventName, this._eventHandler.onCellPropertyChangedByPropertyView.bind(this, cellPoint)); }, //根据坐标位置, 获取当前CellPoint getCellPointByLocation: (sheet: Sheet, config: IDataTableItemConfig, location:{x:number, y:number}):CellPoint => { const columnHeader: ColumnHeader = sheet.columnHeader; const rowHeader:RowHeader = sheet.rowHeader; var columnNo = 1; var rowNo = 1; columnHeader.items.map( (columnHeaderItem:ColumnHeaderItem, key) => { if(columnHeaderItem.left - config.rowHeaderWidth <= location.x && columnHeaderItem.right - config.rowHeaderWidth >= location.x){ columnNo = key; } }); rowHeader.items.map( (rowHeaderItem:RowHeaderItem, key) => { if(rowHeaderItem.top - config.columnHeaderHeight <= location.y && rowHeaderItem.bottom - config.columnHeaderHeight >= location.y){ rowNo = key; } }); return new CellPoint(columnNo, rowNo); }, //根据cellPoint获取坐标 getLocationBeCellPoint: (cellPoint: CellPoint) => { const columnHeader = this.sheet.columnHeader; const rowHeader = this.sheet.rowHeader; const x = (columnHeader.items.get(cellPoint.columnNo) as ColumnHeaderItem).left; const y = (rowHeader.items.get(cellPoint.rowNo) as RowHeaderItem).top; return {x, y}; }, createRangeBorder: (cellRange:CellRange) => { const border:Border = new Border(); const iterators = ['left', 'top', 'right', 'bottom']; const propertyDefaultValues = { 'weight': 1, 'lineStyle': LINE_STYLE.NORMAL, 'color': 'rgba(0,0,0,1)' }; const gridViewBorderMap= { 'left': [], 'top': [], 'right': [], 'bottom': [] }; //左侧border集合 for(var i = cellRange.minRowNo; i <= cellRange.maxRowNo; i++){ gridViewBorderMap.left.push(this.sheet.getBorder(new CellPoint(cellRange.minColumnNo, i), BORDER_POSITION.LEFT).toMinJS()); } //顶部border集合 for(var i = cellRange.minColumnNo; i<= cellRange.maxColumnNo; i++){ gridViewBorderMap.top.push(this.sheet.getBorder(new CellPoint(i, cellRange.minRowNo), BORDER_POSITION.TOP).toMinJS()); } //右侧border集合 for(var i = cellRange.minRowNo; i<= cellRange.maxRowNo; i++){ gridViewBorderMap.right.push(this.sheet.getBorder(new CellPoint(cellRange.maxColumnNo, i), BORDER_POSITION.RIGHT).toMinJS()); // gridViewBorderMap.right.push(this.sheet.getBorder(new CellPoint(cellRange.maxColumnNo + 1, i), BORDER_POSITION.LEFT).toMinJS()); } //底部border集合 for(var i = cellRange.minColumnNo; i<= cellRange.maxColumnNo; i++){ gridViewBorderMap.bottom.push(this.sheet.getBorder(new CellPoint(i, cellRange.maxRowNo), BORDER_POSITION.BOTTOM).toMinJS()); // gridViewBorderMap.bottom.push(this.sheet.getBorder(new CellPoint(i, cellRange.maxRowNo + 1), BORDER_POSITION.TOP).toMinJS()); } for(var position of iterators){ const result = { 'visible': true, 'weight': gridViewBorderMap[position][0].weight, 'color': gridViewBorderMap[position][0].colors ? gridViewBorderMap[position][0].colors[0] : undefined, 'lineStyle': gridViewBorderMap[position][0].lineStyle }; for(var gridViewBorder of gridViewBorderMap[position]){ if(Object.keys(gridViewBorder).length == 0){ result.visible = false; } if(!gridViewBorder.weight || gridViewBorder.weight != result.weight){ result.weight = propertyDefaultValues.weight; } if(!gridViewBorder.colors || gridViewBorder.colors[0] != result.color){ result.color = propertyDefaultValues.color; } if(!gridViewBorder.lineStyle || gridViewBorder.lineStyle !== result.lineStyle){ result.lineStyle = propertyDefaultValues.lineStyle; } } border[position].borderVisible = result.visible; border[position].borderWidth = Unit.pixel(result.weight); border[position].borderColor = result.color; border[position].borderStyle = BorderFromGridViewMap[result.lineStyle]; } return border; }, //当前操作改变选中对象时, 重新创建DataTableCellItem checkSelectItemsChange: (currentOperation:Operation) => { // 先移除 TableItem 中创建的所有 DataTableCellItem this.item.items.forEach((item:ReportItemBase) => item.dispose()); this.item.items.clear(); this._selectedMergeCellItems.length = 0; //并且, 当前有选中的元素 if (currentOperation.rangeItem) { const rangeItem = currentOperation.rangeItem; this._currentRangeItem = rangeItem; //遍历所有选中的cell, 创建item并且添加到selectionService中 for (var rowNo = rangeItem.minRowNo; rowNo <= rangeItem.maxRowNo; rowNo++) { for (var columnNo = rangeItem.minColumnNo; columnNo <= rangeItem.maxColumnNo; columnNo++) { this._handler.createCellItem(new CellPoint(columnNo, rowNo)); } } if (this.item.items.length > 0) { this._selectionService.replaceSelectedItems(this.item.items); } } }, //根据选中对象, 更新command区域 checkCommandChange: (currentOperation:Operation) => { //根据选择区域确定CommandMode const currentCommand:CommandDataTable = this._host.uiModel.commandModel.currentCommand; const rangeItem = currentOperation.rangeItem; const selectItem = currentOperation.selectItem; if(selectItem.objectType == OBJECT_TYPE.COLUMN_RESIZER || selectItem.objectType == OBJECT_TYPE.ROW_RESIZER){ return; } //选中行 if (selectItem && selectItem.cellPoint.columnNo == 0) { currentCommand.setCommandMode(CommandModeEnum.ROW); this._currentSelectRangeType = SelectRangeType.ROW; //选中列 } else if (selectItem && selectItem.cellPoint.rowNo == 0) { currentCommand.setCommandMode(CommandModeEnum.COLUMN); this._currentSelectRangeType = SelectRangeType.COLUMN; //选中一个单元格 } else { //选中的是一个格子 if (rangeItem.minColumnNo == rangeItem.maxColumnNo && rangeItem.minRowNo == rangeItem.maxRowNo) { currentCommand.setCommandMode(CommandModeEnum.CELL); this._currentSelectRangeType = SelectRangeType.CELL; //选中的是一个区域 } else { currentCommand.setCommandMode(CommandModeEnum.RANGE); this._currentSelectRangeType = SelectRangeType.RANGE; } } }, /** * 检查是否可以删除行或列 * @param operation */ checkCanDelete: (operation: Operation) => { const currentCommand:CommandDataTable = this._host.uiModel.commandModel.currentCommand; if(this._currentSelectRangeType === SelectRangeType.COLUMN){ if(this.sheet.columnHeader.items.size < 2){ currentCommand.setItemStatus(['deleteColumn'], 'useable', false); } }else if(this._currentSelectRangeType === SelectRangeType.ROW){ if(this.sheet.rowHeader.items.size < 2){ currentCommand.setItemStatus(['deleteRow'], 'useable', false); } } }, //检查merge状态 checkMergeStatus: (currentOperation:Operation) => { const rangeItem = currentOperation.rangeItem; const currentCommand:CommandDataTable = this._host.uiModel.commandModel.currentCommand; if (rangeItem) { //获取首行和尾行分别所在区域 const leftTopAreaIndex = this._handler.getAreaIndexOfRow(rangeItem.leftTopPoint.rowNo); const rightBottomAreaIndex = this._handler.getAreaIndexOfRow(rangeItem.rightBottomPoint.rowNo); //如果跨区域了, 则不允许合并单元格 if(leftTopAreaIndex != rightBottomAreaIndex){ currentCommand.setItemStatus(['mergeCell'], 'useable', false); } //检查合并单元格状态 const mergeRange = this.sheet.getCell(rangeItem.leftTopPoint).mergeRange; //TODO 此处耦合了 if (mergeRange) { currentCommand.setItemStatus(['mergeCell'], 'value', true); } } }, //根据行数, 获取在区域索引(header:1, body:2, footer:3) getAreaIndexOfRow: (rowNo:number) => { const config = this.item.config; //检查是否跨区域了 if (rowNo <= config.header.rows.length) { return 1; } else if (rowNo <= config.header.rows.length + config.body.rows.length) { return 2; } else { return 3; } }, bindCommandListener: () => { const currentCommand = this._host.uiModel.commandModel.currentCommand; currentCommand.on(CommandMenuEvent.DELETE_COLUMN, this._eventHandler.onDeleteColumn); currentCommand.on(CommandMenuEvent.INSERT_COLUMN, this._eventHandler.onInsertColumn); currentCommand.on(CommandMenuEvent.DELETE_ROW, this._eventHandler.onDeleteRow); currentCommand.on(CommandMenuEvent.INSERT_ROW, this._eventHandler.onInsertRow); currentCommand.on(CommandMenuEvent.MERGE_CELL, this._eventHandler.onMergeCell); }, selectCell: (cellRange: CellRange) => { // this._currentRangeItem = cellRange; // this._handler.setRangeItem(cellRange); // return; var objectType; if(this._currentSelectRangeType == SelectRangeType.COLUMN){ objectType = OBJECT_TYPE.COLUMN_HEADER; }else if(this._currentSelectRangeType == SelectRangeType.ROW){ objectType = OBJECT_TYPE.ROW_HEADER; }else{ objectType = OBJECT_TYPE.CELL; } const callback = () => { this._gridViewInstance.setRangeItem(cellRange, objectType); }; if (this._gridViewInstance) { this._gridViewInstance.setRangeItem(cellRange, objectType); } else { this._selectCellActionBatch.push(callback); } }, setRangeItem: (cellRange: CellRange) => { this.operation = this.operation .setSelectItem(new SelectInfo(OBJECT_TYPE.CELL, cellRange.leftTopPoint, null, null)) .setRangeItem(cellRange) .clearClipRanges() .pushClipRanges(cellRange); }, setBorderLeft: (sheet:Sheet, borderItem:BorderItem) => { const left = this._currentOperation.rangeItem.minColumnNo; const top = this._currentOperation.rangeItem.minRowNo; const bottom = this._currentOperation.rangeItem.maxRowNo; return this._handler.setBorder(sheet, BORDER_POSITION.LEFT, borderItem, left, top, left, bottom); }, setBorderTop: (sheet:Sheet, borderItem:BorderItem) => { const left = this._currentOperation.rangeItem.minColumnNo; const top = this._currentOperation.rangeItem.minRowNo; const right = this._currentOperation.rangeItem.maxColumnNo; return this._handler.setBorder(sheet, BORDER_POSITION.TOP, borderItem, left, top, right, top); }, setBorderRight: (sheet:Sheet, borderItem:BorderItem) => { const top = this._currentOperation.rangeItem.minRowNo; const right = this._currentOperation.rangeItem.maxColumnNo; const bottom = this._currentOperation.rangeItem.maxRowNo; return this._handler.setBorder(sheet, BORDER_POSITION.RIGHT, borderItem, right, top, right, bottom); }, setBorderBottom: (sheet:Sheet, borderItem:BorderItem) => { const left = this._currentOperation.rangeItem.minColumnNo; const top = this._currentOperation.rangeItem.minRowNo; const right = this._currentOperation.rangeItem.maxColumnNo; const bottom = this._currentOperation.rangeItem.maxRowNo; return this._handler.setBorder(sheet, BORDER_POSITION.BOTTOM, borderItem, left, bottom, right, bottom); }, setBorder: (sheet:Sheet, position:BORDER_POSITION, borderItem:BorderItem, left:number, top:number, right:number, bottom:number) => { return sheet.editBorders( CellRange.create(left, top, right, bottom), position, (border) => { if (!borderItem.borderVisible) { return null; } else { return border .setWeight(borderItem.borderWidth.toPixel()) .setColor(borderItem.borderColor) .setLineStyle(BorderToGridViewMap[borderItem.borderStyle]); } } ); } }; //事件监听集合 _eventHandler = { onDeleteColumn: () => { this.deleteColumn(); DesignerHost.instance().historyService.snap(); }, onInsertColumn: () => { this.insertColumn(); DesignerHost.instance().historyService.snap(); }, onDeleteRow: () => { this.deleteRow(); DesignerHost.instance().historyService.snap(); }, onInsertRow: (type) => { this.insertRow(type); DesignerHost.instance().historyService.snap(); }, onMergeCell: (isMerged) => { const rangeItem = this.operation.rangeItem; const mergeFunction = isMerged ? 'unMergeRange' : 'mergeRange'; this.sheet = this.sheet[mergeFunction]( new CellRange( new CellPoint(rangeItem.minColumnNo, rangeItem.minRowNo), new CellPoint(rangeItem.maxColumnNo, rangeItem.maxRowNo) ) ); //由于merge是自己操作数据, 所以无法触发change, 改变mergeCell的数据状态, 所以自己调用 //检测选择元素是否发生变化, 并对应更新selectItems this._handler.checkSelectItemsChange(this.operation); //根据选择元素类型, 更新command this._handler.checkCommandChange(this.operation); //检查当前所选元素是否可以merge 和 当前的merge状态 this._handler.checkMergeStatus(this.operation); DesignerHost.instance().historyService.snap(); }, //监听属性改变 onCellPropertyChangedByPropertyView: (cellPoint:CellPoint, data:PropertyChangeEventArgs) => { const sheet = this.sheet; switch (data.property) { //单元格的值发生了改变 case DataTableCellItem.CellProperty: //text更新到cellPoint指定的单元格, 其他样式如果有cellMerge, 则更新到整个Merge区域 const currentCell = sheet.getCell(cellPoint); if(currentCell.mergeRange){ this.sheet = sheet .editCells(currentCell.mergeRange, (cell, point) => { //只有当前的单元格全量更新 if(point.toId() == cellPoint.toId()){ return data.newValue; //其他单元格的text保留自己的 }else{ return (data.newValue as Cell).setText(cell.text); } }); }else{ this.sheet = sheet.setCell(cellPoint, data.newValue); } break; //单元格所在列宽发生改变 case DataTableCellProperty.width: const newWidth:Unit = data.newValue; const columnHeaderItem:ColumnHeaderItem = sheet.columnHeader.items.get(cellPoint.columnNo).setWidth(newWidth.toPixel()); const newColumnHeader = sheet.columnHeader.setItem(cellPoint.columnNo, columnHeaderItem); this.sheet = sheet.setColumnHeader(newColumnHeader); break; //单元格所在行高发生改变 case DataTableCellProperty.height: const newHeight:Unit = data.newValue; const rowHeaderItem:RowHeaderItem = sheet.rowHeader.items.get(cellPoint.rowNo).setHeight(newHeight.toPixel()); const newRowHeader = sheet.rowHeader.setItem(cellPoint.rowNo, rowHeaderItem); this.sheet = sheet.setRowHeader(newRowHeader); break; case DataTableCellProperty.border: const newBorder:Border = data.newValue; this.sheet = this._handler.setBorderLeft(this.sheet, newBorder.left); this.sheet = this._handler.setBorderTop(this.sheet, newBorder.top); this.sheet = this._handler.setBorderRight(this.sheet, newBorder.right); this.sheet = this._handler.setBorderBottom(this.sheet, newBorder.bottom); break; case DataTableCellProperty.x: break; case DataTableCellProperty.y: break; } } } constructor() { this._host = DesignerHost.instance(); this._selectionService = this._host.getService(SelectionService) as SelectionService; this._selectCellActionBatch = []; this._state = observable({ show: false, item: undefined, sheet: undefined, width: 0, height: 0 }); // this._selectedCellItems = []; this._selectedMergeCellItems = []; this._currentSelectRangeType = SelectRangeType.NONE; } //开始编辑 beginEdit = (item:DataTableItem, pt:PointF) => { console.log(item.parent); const sheet = item.sheet; item.isEditing = true; this._selectionService.addEventListener(SelectionService.SelectionChangeEvent, this.checkFinish); this._host.uiModel.disableToolBox(); const commandModel = this._host.uiModel.commandModel; commandModel.changeCommand('dataTable'); console.log('item.config', item.config); //判断数据表类型, 如果是数据表, 插入行有下拉 if(item.config.type === IDataTableType.DATA_TABLE){ console.log('dataTable'); commandModel.currentCommand.changeInsertType(false); }else{ console.log('staticTable'); commandModel.currentCommand.changeInsertType(true); } this._handler.bindCommandListener(); this._currentOperation = Operation.create(); //选中当前鼠标位置对应的单元格; const designer: DataTableDesigner = this._host.getDesigner(item) as DataTableDesigner; const bounds = designer.getBounds(); const position = { x: pt.x - bounds.x, y: pt.y - bounds.y } const currentCursorPoint = this._handler.getCellPointByLocation(sheet, item.config, position); this._handler.selectCell(new CellRange(currentCursorPoint, currentCursorPoint)); transaction(() => { this._state.show = true; extendObservable(this._state, {item: item}); extendObservable(this._state, {sheet: item.sheet}); extendObservable(this._state, { width: sheet.columnHeader.width, height: sheet.rowHeader.height + item.config.columnHeaderHeight }); }); }; //检查是否编辑完成 checkFinish = () => { const selectItems = this._selectionService.getSelectedItems(); if (selectItems.length == 0 || !(selectItems[0] instanceof DataTableCellItem)) { this.finishEdit(); } }; //退出编辑 finishEdit = () => { console.log(this.operation); //如果目前还在编辑状态, 则将值更新到dataTable中 if(this.operation.input.isInputing){ this.sheet = this.sheet.editCell(this.operation.selectItem.cellPoint, (cell: Cell) => { return cell.setText(this.operation.input.text); }); } this.item.isEditing = false; this._host.uiModel.restoreToolBox(); //重置会之前command const commandModel = this._host.uiModel.commandModel; commandModel.changeCommand('report'); //移除selectionService的事件监听 this._selectionService.removeEventListener(SelectionService.SelectionChangeEvent, this.checkFinish); //重置数组 this._selectCellActionBatch.length = 0; this._selectedMergeCellItems.length = 0; this._currentSelectRangeType = SelectRangeType.NONE; //重置item数据 transaction(() => { // 先移除 TableItem 中创建的所有 DataTableCellItem this.item.items.forEach((item:ReportItemBase) => item.dispose()); this.item.items.clear(); this._state.show = false; this._state.item = null; this._currentOperation = undefined; }); DesignerHost.instance().historyService.snap(); }; //gridView操作事件回调 onChangeOperation = (prevOperation:Operation, currentOperation:Operation) => { const selectItem = currentOperation.selectItem; const sheet = this.sheet; //TODO if(selectItem){ const cellPoint = selectItem.cellPoint; if(cellPoint && (cellPoint.rowNo > sheet.rowHeader.items.size || cellPoint.columnNo > sheet.columnHeader.items.size)){ // selectItem.setCellPoint(cellPoint.setColumnNo(cellPoint.columnNo-1)) this.operation = currentOperation.setSelectItem(new SelectInfo(null, null, null, null)); // this._handler.selectCell(new CellRange(new CellPoint(1, 1), new CellPoint(1, 1))); // this._handler.checkCommandChange(this.operation) return this.operation; } } //如果点击的是左上角, 不做任何处理 if (currentOperation.rangeItem && currentOperation.rangeItem.minColumnNo == 0) { return prevOperation; } // console.log('current operation', currentOperation); this.operation = currentOperation; if (prevOperation.rangeItem != currentOperation.rangeItem) { //检测选择元素是否发生变化, 并对应更新selectItems this._handler.checkSelectItemsChange(currentOperation); //根据选择元素类型, 更新command this._handler.checkCommandChange(currentOperation); //检查当前所选元素是否可以merge 和 当前的merge状态 this._handler.checkMergeStatus(currentOperation); this._handler.checkCanDelete(currentOperation); } return currentOperation; }; onChangeSheet = (prevSheet, currentSheet) => { const opeItem = this.operation.opeItem; transaction(() => { //如果当前操作是调整列宽或者行高, 应该重新选择之前的元素 if(opeItem){ if(opeItem.objectType == OBJECT_TYPE.COLUMN_RESIZER || opeItem.objectType == OBJECT_TYPE.ROW_RESIZER){ setTimeout(() => { // this.operation = this._gridViewInstance.setRangeItem(this._currentRangeItem); this._handler.selectCell(this._currentRangeItem); }, 0); } /*if(opeItem.objectType === OBJECT_TYPE.ROW_RESIZER){ this.item.updateRowsConfigBySheetInfo(); }*/ } this.sheet = currentSheet; }); if(opeItem && opeItem.objectType === OBJECT_TYPE.ROW_RESIZER){ this.item.updateRowsConfigBySheetInfo(); } if(opeItem && opeItem.objectType === OBJECT_TYPE.COLUMN_RESIZER){ this.item.updateColumnsConfigBySheetInfo(); } DesignerHost.instance().historyService.snap(); return currentSheet; }; insertRow(params) { const {type} = params; const item = this.item; let sheet = null; if (type === 'headerRow') { sheet = item.insertHeaderRow(); } else if(type === 'bodyRow') { sheet = item.insertBodyRow(); } else if(type === 'footerRow') { sheet = item.insertFooterRow(); } else { const operation = this.operation; const rowNo = operation.selectItem.cellPoint.rowNo || 1; sheet = item.insertRow(rowNo); } this.sheet = sheet; } deleteRow() { const operation = this.operation; const cellPoint = operation.selectItem.cellPoint; if(cellPoint){ let rowNo = cellPoint.rowNo; if (rowNo < 1 || this.sheet.rowHeader.items.size === 1) { return; } this.sheet = this.item.deleteRow(rowNo); } } insertColumn() { const operation = this.operation; const columnNo = operation.selectItem.cellPoint.columnNo || 1; this.sheet = this.item.insertColumn(columnNo); } deleteColumn() { const operation = this.operation; const cellPoint = operation.selectItem.cellPoint; if(cellPoint){ const columnNo = operation.selectItem.cellPoint.columnNo; if (columnNo < 1 || this.sheet.columnHeader.items.size === 1) { return; } this.sheet = this.item.deleteColumn(columnNo); } } /* START ------ getter and setter ------ START */ get show():boolean { return this._state.show; } get item():DataTableItem { return this._state.item; } get sheet():Sheet { return this._state.sheet; } set sheet(sheet:Sheet) { this._state.sheet = sheet; this.item.sheet = sheet; } get operation():Operation { return this._currentOperation; } set operation(operation:Operation) { this._currentOperation = operation; } get width() { return this._state.width; } get height() { return this._state.height; } set width(width:number) { this._state.width = width; } set height(height:number) { this._state.height = height; } get gridView():GridView { return this._gridViewInstance; } set gridView(gridView:GridView) { this._gridViewInstance = gridView; this._selectCellActionBatch.map(callback => callback()); this._selectCellActionBatch.length = 0; } /* END ------ getter and setter ------ END */ }