|
@@ -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();
|