Sfoglia il codice sorgente

解决 撤销重做后 数据无法保存的问题

YaolongHan 4 anni fa
parent
commit
eaca0254fd

+ 79 - 4
src/components/mapClass/EditScence.ts

@@ -962,11 +962,23 @@ export class EditScence extends SGraphScene {
         } else {
             this.undoStack.redo();
             this.scenceUpdate(this);
-            // console.log(this.undoStack.command(this.undoStack.index))
+            const command = this.undoStack.command(this.undoStack.index);
+            // 如果为删除命令,重做需要讲数据数组中的item重新删去
+            if (command && command.command == "DeleteCommand") {
+                this.clearDataItem(command.item)
+            } else if (command && command.command == "DeleteCommandList") {
+                command.itemList.forEach(element => {
+                    this.clearDataItem(element)
+                });
+            } else if (command && command.command == "SGraphAddCommand") {
+                this.addDataItem(command.item)
+            } else if (command && command.command == "AddListCommand") {
+                command.itemList.forEach(element => {
+                    this.addDataItem(element)
+                });
+            }
         }
-
     }
-
     /**
     * 执行重做操作执行
     */
@@ -974,12 +986,75 @@ export class EditScence extends SGraphScene {
         if (this.grabItem && this.grabItem.undo) {
             this.grabItem.undo()
         } else {
-            // console.log(this.undoStack.command(this.undoStack.index))
+            const command = this.undoStack.command(this.undoStack.index);
+            // 如果为删除命令,重做需要讲数据数组中的item重新放回data中
+            if (command && command.command == "DeleteCommand") {
+                this.addDataItem(command.item)
+            } else if (command && command.command == "DeleteCommandList") {
+                command.itemList.forEach(element => {
+                    this.addDataItem(element)
+                });
+            } else if (command && command.command == "SGraphAddCommand") {
+                this.clearDataItem(command.item)
+            } else if (command && command.command == "AddListCommand") {
+                command.itemList.forEach(element => {
+                    this.clearDataItem(element)
+                });
+            }
             this.undoStack.undo();
             this.scenceUpdate(this);
         }
     }
     /**
+     * 清除data数据中指定的item
+     */
+    clearDataItem(commanditem: any) {
+        let a = -1
+        this.Nodes.forEach((item: any, index: number) => {
+            if (item.id == commanditem.id) {
+                a = index
+            }
+        });
+        if (a > -1) {
+            this.Nodes.splice(a, 1);
+        }
+        let b = -1;
+        this.Markers.forEach((item: any, index: number) => {
+            if (item.id == commanditem.id) {
+                b = index
+            }
+        });
+        if (b > -1) {
+            this.Markers.splice(b, 1);
+        }
+        let c = -1;
+        this.Relations.forEach((item: any, index: number) => {
+            if (item.id == commanditem.id) {
+                c = index
+            }
+        });
+        if (c > -1) {
+            this.Relations.splice(c, 1);
+        }
+    }
+
+    /**
+     * 增加指定Item到data数据中
+     */
+
+    addDataItem(item: any) {
+        //清空指定的item
+        this.clearDataItem(item);
+        // 重新填入
+        if (item instanceof STextMarkerItem || item instanceof SImageMarkerItem || item instanceof SLineMarkerItem || item instanceof SCustomLegendItem) {
+            this.Markers.push(item)
+        } else if (item instanceof SFHFQZoneLegendItem || item instanceof SSCPZZoneLegendItem || item instanceof SImageLegendItem || item instanceof SZoneLegendItem) {
+            this.Nodes.push(item)
+        } else if (item instanceof TipelineItem) {
+            this.Relations.push(item)
+        }
+    }
+    /**
      * 完成事件创建的回调函数
      */
     finishCreated(item: any) {

+ 2 - 0
src/components/mapClass/SGraphAddListCommand.ts

@@ -11,6 +11,8 @@ import { SUndoCommand } from "@saga-web/base/lib";
 export class SGraphAddListCommand extends SGraphCommand {
     /** 命令item对象    */
     itemList: SGraphItem[];
+    /** 命令名称    */
+    readonly command: string = "AddListCommand"
     /** 命令item的父类   */
     parent: SGraphItem | null;
     constructor(scene: SGraphScene, itemList: SGraphItem[]) {

+ 3 - 0
src/components/mapClass/SGraphDeleteCommand.ts

@@ -12,6 +12,9 @@ import { SUndoCommand } from "@saga-web/base/lib";
 export class SGraphDeleteCommand extends SGraphCommand {
     /** 命令item对象    */
     item: SGraphItem;
+    desc:string ='DeleteCommand';
+      /** 命令名称    */
+    readonly command: string = "DeleteCommand"
     /** 命令item的父类   */
     parent: SGraphItem | null;
 

+ 3 - 0
src/components/mapClass/SGraphDeleteListCommand.ts

@@ -11,6 +11,9 @@ import { SUndoCommand } from "@saga-web/base/lib";
 export class SGraphDeleteListCommand extends SGraphCommand {
     /** 命令item对象    */
     itemList: SGraphItem[];
+    desc: string = 'DeleteCommandList'
+    /** 命令名称    */
+    readonly command: string = "DeleteCommandList"
     /** 命令item的父类   */
     parent: SGraphItem | null;
     constructor(scene: SGraphScene, itemList: SGraphItem[]) {