Jelajahi Sumber

修复bug:34666

xushiting 2 tahun lalu
induk
melakukan
9433964c48

+ 10 - 2
src/views/draw-file/board/editCAD/Geometry/Table.js

@@ -130,9 +130,9 @@ export default class Table extends Geometry {
         let width=0;
         let height=0;
 
-        //删除多余的
+        //删除多余的
         for(let i=maxRow;i<this.cells.length;++i){
-            for(let j=maxCol;j<this.cells[i].length;++j){
+            for(let j=0;j<this.cells[i].length;++j){
                 const cell = floorplanService.getCell(this.cells[i][j]);
                 if(cell){
                     floorplanService.deleteCell(this.cells[i][j]);
@@ -140,7 +140,15 @@ export default class Table extends Geometry {
             }
         }
         this.cells.splice(maxRow, this.cells.length-maxRow); 
+
+        //删除多余的列,貌似目前暂时不用
         for(let i=0;i<maxRow;++i){
+            for(let j=maxCol;j<this.cells[i].length;++j){
+                const cell = floorplanService.getCell(this.cells[i][j]);
+                if(cell){
+                    floorplanService.deleteCell(this.cells[i][j]);
+                }
+            }
             this.cells[i].splice(maxCol, this.cells[0].length-maxCol); 
         }
 

+ 42 - 0
src/views/draw-file/board/editCAD/History/Change.js

@@ -21,6 +21,7 @@ export default class Change {
         this.lastData.signs = JSON.parse(JSON.stringify(floorplanService.getSigns()))
 
         this.lastData.tags = JSON.parse(JSON.stringify(floorplanService.getTags()))
+        this.lastData.cells = JSON.parse(JSON.stringify(floorplanService.getCells()))
         this.lastData.tables = JSON.parse(JSON.stringify(floorplanService.getTables()))
 
         this.lastData.rectangles = JSON.parse(JSON.stringify(floorplanService.getRectangles()))
@@ -44,6 +45,7 @@ export default class Change {
             this.compareSigns()
 
             this.compareTags()
+            this.compareCells()
             this.compareTables()
 
             this.compareRectangles()
@@ -67,6 +69,7 @@ export default class Change {
             this.elements.signs.length == 0 &&
 
             this.elements.tags.length == 0 &&
+            this.elements.cells.length == 0 &&
             this.elements.tables.length == 0 &&
 
             this.elements.rectangles.length == 0 &&
@@ -206,6 +209,45 @@ export default class Change {
         }
     }
 
+    compareCells() {
+        this.elements.cells = []
+        const cells = floorplanService.getCells()
+
+        for (const key in cells) {
+            const cell = cells[key]
+            const lastCell = this.lastData.cells[key]
+            // 不存在意味着增加
+            if (!lastCell) {
+                const item = {
+                    handle: HistoryEvents.AddCell,
+                    cell: historyUtil.getDataForCell(cell),
+                }
+                this.elements.cells.push(item)
+            } else {
+                if (!historyUtil.isDifferentForCells(cell, lastCell)) {
+                    delete this.lastData.cells[key]
+                    continue
+                } else {
+                    const item = {
+                        handle: HistoryEvents.ModifyCell,
+                        preCell: historyUtil.getDataForCell(lastCell),
+                        curCell: historyUtil.getDataForCell(cell),
+                    }
+                    this.elements.cells.push(item)
+                }
+            }
+            delete this.lastData.cells[key]
+        }
+
+        for (const key in this.lastData.cells) {
+            const item = {
+                handle: HistoryEvents.DeleteCell,
+                cell: historyUtil.getDataForCell(this.lastData.cells[key]),
+            }
+            this.elements.cells.push(item)
+        }
+    }
+
     compareTables() {
         this.elements.tables = []
         const tables = floorplanService.getTables()

+ 34 - 0
src/views/draw-file/board/editCAD/History/History.js

@@ -130,6 +130,7 @@ export default class History {
             this.goPreForPoints(item.points)
             this.goPreForWalls(item.walls)
             this.goPreForTags(item.tags)
+            this.goPreForCells(item.cells)
             this.goPreForTables(item.tables)
             this.goPreForRectangles(item.rectangles)
             this.goPreForCircles(item.circles)
@@ -223,6 +224,22 @@ export default class History {
         }
     }
 
+    goPreForCells(itemForCells) {
+        for (let i = 0; i < itemForCells.length; ++i) {
+            const item = itemForCells[i]
+            if (item.handle == HistoryEvents.AddCell) {    
+                tableService.deleteCell(item.cell.id)
+            } else if (item.handle == HistoryEvents.DeleteCell) {
+                let newCell = tableService.createCell(item.cell.parent,item.cell.id)
+                historyUtil.assignCellFromCell(newCell, item.cell)
+            } else if (item.handle == HistoryEvents.ModifyCell) {
+                const preCell = item.preCell
+                let curCell = floorplanService.getCell(item.curCell.id)
+                historyUtil.assignCellFromCell(curCell, preCell)
+            }
+        }
+    }
+
     goPreForTables(itemForTables) {
         for (let i = 0; i < itemForTables.length; ++i) {
             const item = itemForTables[i]
@@ -396,6 +413,22 @@ export default class History {
         }
     }
 
+    goNextForCells(itemForCells) {
+        for (let i = 0; i < itemForCells.length; ++i) {
+            const item = itemForCells[i]
+            if (item.handle == HistoryEvents.AddCell) {    
+                let vCell = tableService.createCell(item.cell.parent, item.cell.id)
+                historyUtil.assignCellFromCell(vCell, item.cell)
+            } else if (item.handle == HistoryEvents.DeleteCell) {
+                tableService.deleteCell(item.cell.id)
+            } else if (item.handle == HistoryEvents.ModifyCell) {
+                const curCell = item.curCell
+                let preCell = floorplanService.getCell(item.curCell.id)
+                historyUtil.assignCellFromCell(preCell, curCell)
+            }
+        }
+    }
+
     goNextForTables(itemForTables) {
         for (let i = 0; i < itemForTables.length; ++i) {
             const item = itemForTables[i]
@@ -553,6 +586,7 @@ export default class History {
                 this.goNextForPoints(item.points)
                 this.goNextForWalls(item.walls)
                 this.goNextForTags(item.tags)
+                this.goNextForCells(item.cells)
                 this.goNextForTables(item.tables)
                 this.goNextForRectangles(item.rectangles)
                 this.goNextForCircles(item.circles)

+ 26 - 2
src/views/draw-file/board/editCAD/History/HistoryUtil.js

@@ -51,14 +51,13 @@ export default class HistoryUtil {
     }
 
     isDifferentForCells(cell1, cell2) {
-        if (cell1.value == cell2.value&&cell1.width == cell2.width&&cell1.height == cell2.height) {
+        if (cell1.value == cell2.value&&cell1.width == cell2.width&&cell1.height == cell2.height&&cell1.colIndex == cell2.colIndex&&cell1.rowIndex == cell2.rowIndex&&cell1.parent == cell2.parent) {
             return false
         } else {
             return true
         }
     }
 
-
     isDifferentForRectangles(rectangle1, rectangle2) {
         for(let i=0;i<rectangle1.points.length;++i){
             if(!mathUtil.equalPoint(rectangle1.points[i], rectangle2.points[i])){
@@ -182,6 +181,18 @@ export default class HistoryUtil {
         tagService.setTagInfo(tagInfo)
     }
 
+    assignCellFromCell(cell1, cell2) {
+        const cellInfo = {}
+        cellInfo.vectorId = cell1.vectorId
+        cellInfo.width = cell2.width
+        cellInfo.height = cell2.height
+        cellInfo.value = cell2.value
+        cellInfo.colIndex = cell2.colIndex
+        cellInfo.rowIndex = cell2.rowIndex
+        cellInfo.parent = cell2.parent
+        tableService.setCellInfo(cellInfo)
+    }
+
     assignTableFromTable(table1, table2) {
         const tableInfo = {}
         tableInfo.vectorId = table1.vectorId
@@ -315,6 +326,19 @@ export default class HistoryUtil {
         return data
     }
 
+    getDataForCell(cell) {
+        const data = {}
+        data.id = cell.vectorId
+        data.type = cell.geoType
+        data.width = cell.width
+        data.height = cell.height
+        data.value = cell.value
+        data.colIndex = cell.colIndex
+        data.rowIndex = cell.rowIndex
+        data.parent = cell.parent
+        return data
+    }
+
     getDataForTable(table) {
         const data = {}
         data.id = table.vectorId

+ 15 - 0
src/views/draw-file/board/editCAD/Service/TableService.js

@@ -32,10 +32,25 @@ export default class TableService {
         table.cells = tableInfo.cells;  
     }
 
+    setCellInfo(cellInfo) {
+        let cell = floorplanService.getCell(cellInfo.vectorId)
+        cell.vectorId = cellInfo.vectorId
+        cell.width = cellInfo.width;
+        cell.height = cellInfo.height; 
+        cell.value = cellInfo.value;
+        cell.colIndex = cellInfo.colIndex;
+        cell.rowIndex = cellInfo.rowIndex;
+        cell.parent = cellInfo.parent;     
+    }
+
     deleteTable(tableId, floorNum) {
         floorplanService.deleteTable(tableId, floorNum)
     }
 
+    deleteCell(cellId, floorNum) {
+        floorplanService.deleteCell(cellId, floorNum)
+    }
+
     clearDefaultTables() {
         for (let i = 0; i < floorplanData.floors.length; ++i) {
             let tables = floorplanData.floors[i].tables

+ 4 - 0
src/views/draw-file/board/editCAD/enum/HistoryEvents.js

@@ -11,6 +11,10 @@ const HistoryEvents = {
     DeleteTag: 'deleteTag',
     ModifyTag: 'modifyTag',
 
+    AddCell: 'addCell',
+    DeleteCell: 'deleteCell',
+    ModifyCell: 'modifyCell',
+
     AddTable: 'addTable',
     DeleteTable: 'deleteTable',
     ModifyTable: 'modifyTable',