画布问题id丢失、撤回...

This commit is contained in:
李志鹏
2025-11-05 16:28:37 +08:00
parent b1bb96b6fd
commit 4030f54334
17 changed files with 182 additions and 74 deletions

View File

@@ -70,7 +70,7 @@ export class AddLayerCommand extends Command {
undo() {
// 从图层列表删除该图层
this.layers.value = this.beforeLayers;
this.layers.value = [...this.beforeLayers];
// 恢复原活动图层
this.activeLayerId.value = this.oldActiveLayerId;
@@ -563,6 +563,12 @@ export class RemoveLayerCommand extends Command {
allObjects.push(object);
}
}
layer.fabricObjects?.forEach((fabric) => {
const { object } = findObjectById(this.canvas, fabric.id);
if (object && !allObjects.includes(object)) {
allObjects.push(object);
}
});
// 递归收集子图层的对象
if (layer.children && Array.isArray(layer.children)) {
@@ -609,7 +615,7 @@ export class RemoveLayerCommand extends Command {
// this.canvas.renderAll();
// }
await this.layerManager?.updateLayersObjectsInteractivity?.();
// this.canvas.renderAll();
this.canvas.renderAll();
console.log(
`✅ 已移除图层: ${this.removedLayer.name} (ID: ${this.layerId}),包含 ${this.originalObjects.length} 个对象`
@@ -2013,7 +2019,7 @@ export class LayerObjectsToGroupCommand extends Command {
console.error("图层或Canvas未初始化");
return null;
}
this.activeLayer = this.layerManager.getActiveLayer();
// 查找图层中是否已有组对象
const existingGroup = this._findExistingGroup();
this.existingGroupId = existingGroup?.id || null;
@@ -2067,10 +2073,10 @@ export class LayerObjectsToGroupCommand extends Command {
}
// 更新交互性
this.layerManager?.updateLayersObjectsInteractivity?.(false);
// 更新缩略图
this._updateThumbnail();
this.layerManager?.updateLayersObjectsInteractivity?.(false).then(()=>{
// 更新缩略图
this._updateThumbnail();
});
});
// 标记为非首次执行
@@ -2220,7 +2226,7 @@ export class LayerObjectsToGroupCommand extends Command {
async undo() {
if (!this.activeLayer || !this.canvas || !this.groupObjectId) return;
this.activeLayer = this.layerManager.getActiveLayer();
try {
await optimizeCanvasRendering(this.canvas, async () => {
if (this.wasGroupCreated) {
@@ -2338,7 +2344,7 @@ export class LayerObjectsToGroupCommand extends Command {
// 将对象添加回画布
this.canvas.add(obj);
restoredObjects.push(obj);
restoredObjects.push(obj.toObject("id", "layerId", "layerName"));
console.log(
`✅ 恢复原始对象 ${obj.id || obj.type} 到位置 (${position.left}, ${
@@ -2537,9 +2543,9 @@ export class LayerObjectsToGroupCommand extends Command {
* @private
*/
_updateThumbnail() {
// this.canvas?.thumbnailManager?.generateLayerThumbnail?.(
// this.activeLayer.id
// );
this.canvas?.thumbnailManager?.generateLayerThumbnail?.(
this.activeLayer.id
);
}
getInfo() {