feat: 优化跨层级移动和套索抠图命令,支持异步执行,改进画布刷新逻辑,新增背景裁剪选项

This commit is contained in:
bighuixiang
2025-07-11 00:26:38 +08:00
parent d3e22f368b
commit 96e13cb22a
10 changed files with 129 additions and 121 deletions

View File

@@ -181,7 +181,7 @@ export class CrossLevelMoveCommand extends Command {
return ancestor ? checkChildren(ancestor.children) : false;
}
execute() {
async execute() {
console.log("🎯 执行跨层级移动命令:", {
layerId: this.layerId,
from: this.fromContainerType,
@@ -220,10 +220,13 @@ export class CrossLevelMoveCommand extends Command {
this.saveAfterState();
// 刷新画布
if (this.canvas) {
this.canvas.renderAll();
console.log("🎨 画布已刷新");
}
// if (this.canvas) {
// this.canvas.renderAll();
// console.log("🎨 画布已刷新");
// }
await this.layerManager?.updateLayersObjectsInteractivity();
this.canvas?.renderAll();
console.log("✅ 跨层级移动命令执行成功");
return true;
@@ -248,7 +251,7 @@ export class CrossLevelMoveCommand extends Command {
}
}
undo() {
async undo() {
if (!this.beforeState) {
throw new Error("没有保存的前置状态,无法撤销");
}
@@ -262,14 +265,10 @@ export class CrossLevelMoveCommand extends Command {
// 恢复fabric对象状态
this.restoreFabricObjectStates(this.beforeState.fabricObjects);
await this.layerManager?.updateLayersObjectsInteractivity();
this.canvas?.renderAll();
// 刷新画布
if (this.canvas) {
// 使用 requestAnimationFrame 确保DOM更新完成后再渲染
requestAnimationFrame(() => {
this.canvas.renderAll();
});
}
this.canvas?.renderAll();
console.log("✅ 跨层级移动命令撤销成功");
return true;
} catch (error) {
@@ -331,7 +330,7 @@ export class CrossLevelMoveCommand extends Command {
/**
* 重做命令
*/
redo() {
async redo() {
if (!this.afterState) {
throw new Error("没有保存的后置状态,无法重做");
}
@@ -345,13 +344,9 @@ export class CrossLevelMoveCommand extends Command {
// 恢复fabric对象状态
this.restoreFabricObjectStates(this.afterState.fabricObjects);
await this.layerManager?.updateLayersObjectsInteractivity();
// 刷新画布
if (this.canvas) {
// 使用 requestAnimationFrame 确保DOM更新完成后再渲染
requestAnimationFrame(() => {
this.canvas.renderAll();
});
}
this.canvas?.renderAll();
console.log("✅ 跨层级移动命令重做成功");
return true;