浏览代码

属性命令修改

haojianlong 4 年之前
父节点
当前提交
ba75d42191

+ 2 - 2
persagy-web-big-edit/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/big-edit",
-    "version": "2.2.34",
+    "version": "2.2.35",
     "description": "博锐尚格二维图形编辑器。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@persagy-web/edit": "2.2.28",
+        "@persagy-web/edit": "2.2.29",
         "@types/uuid": "^8.0.0",
         "crypto-js": "^4.0.0",
         "axios": "^0.20.0"

+ 2 - 2
persagy-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/big",
-    "version": "2.2.55",
+    "version": "2.2.56",
     "description": "博锐尚格建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -41,7 +41,7 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@persagy-web/graph": "2.2.46",
+        "@persagy-web/graph": "2.2.47",
         "axios": "^0.18.0",
         "pako": "^1.0.10",
         "crypto-js": "^4.0.0",

+ 2 - 2
persagy-web-edit/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/edit",
-    "version": "2.2.28",
+    "version": "2.2.29",
     "description": "博锐尚格二维图形编辑器。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@persagy-web/big": "2.2.55",
+        "@persagy-web/big": "2.2.56",
         "@types/uuid": "^8.0.0"
     }
 }

+ 3 - 0
persagy-web-graph/README.md

@@ -6,6 +6,9 @@
     无特殊说明单版本为跟随依赖版本升级
     |
     |
+    |-- 2.2.47 属性修改命令 zorder 特殊处理需要多传参数
+    |
+    |
     |-- 2.2.44 item中通过参数控制,当前item入选择器时是增选还是替换
     |
     |

+ 1 - 1
persagy-web-graph/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/graph",
-    "version": "2.2.46",
+    "version": "2.2.47",
     "description": "博锐尚格二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 35 - 6
persagy-web-graph/src/commands/SGraphPropertyCommand.ts

@@ -44,28 +44,41 @@ export class SGraphPropertyCommand<T> extends SGraphCommand {
     oldProp: T;
     /** 属性新值 */
     newProp: T;
+    /** 修改层级时用到-旧的层级 */
+    oldIndex: number | null = null;
+    /** 修改层级时用到-新的层级 */
+    newIndex: number | null = null;
 
     /**
      * 构造函数
      *
-     * @param scene       命令所属的场景类
-     * @param item        命令所属的 item 类
-     * @param propName    修改的属性名称
-     * @param oldProp     修改前的属性值
-     * @param newProp     修改后的属性值
+     * @param scene     命令所属的场景类
+     * @param item      命令所属的 item 类
+     * @param propName  修改的属性名称
+     * @param oldProp   修改前的属性值
+     * @param newProp   修改后的属性值
+     * @param oldIndex  修改前 item 的索引, 修改 zOrder 时必填
+     * @param newIndex  修改后 item 的索引, 修改 zOrder 时必填
      */
     constructor(
         scene: SGraphScene,
         item: SGraphItem,
         propName: string,
         oldProp: T,
-        newProp: T
+        newProp: T,
+        oldIndex?: number,
+        newIndex?: number
     ) {
         super(scene);
         this.item = item;
         this.propName = propName;
         this.oldProp = oldProp;
         this.newProp = newProp;
+        // 传入了索引值
+        if (oldIndex && newIndex) {
+            this.oldIndex = oldIndex;
+            this.newIndex = newIndex;
+        }
         this.command = "SGraphPropertyCommand";
         this.command = `更新属性=${item.id}`;
     }
@@ -74,6 +87,14 @@ export class SGraphPropertyCommand<T> extends SGraphCommand {
      * redo 操作
      */
     redo(): void {
+        // 传入了索引值
+        if (this.oldIndex && this.newIndex) {
+            // 执行操作的对象有父节点
+            if (this.item.parent) {
+                this.item.parent.children.splice(this.oldIndex, 1);
+                this.item.parent.children.splice(this.newIndex, 0, this.item);
+            }
+        }
         // @ts-ignore
         this.item[this.propName] = this.newProp;
         this.item.update();
@@ -83,6 +104,14 @@ export class SGraphPropertyCommand<T> extends SGraphCommand {
      * undo 操作
      */
     undo(): void {
+        // 传入了索引值
+        if (this.oldIndex && this.newIndex) {
+            // 执行操作的对象有父节点
+            if (this.item.parent) {
+                this.item.parent.children.splice(this.newIndex, 1);
+                this.item.parent.children.splice(this.oldIndex, 0, this.item);
+            }
+        }
         // @ts-ignore
         this.item[this.propName] = this.oldProp;
         this.item.update();