合并画布
This commit is contained in:
@@ -342,7 +342,7 @@ export class AddObjectToLayerCommand extends Command {
|
||||
this.canvas.remove(object);
|
||||
}
|
||||
|
||||
this.layerManager?.updateLayersObjectsInteractivity?.(false);
|
||||
await this.layerManager?.updateLayersObjectsInteractivity?.(false);
|
||||
// 重置为首次执行状态,以便重做时能正确恢复位置
|
||||
this.isFirstExecution = false; // 保持为false,因为已经执行过一次了
|
||||
});
|
||||
@@ -473,18 +473,28 @@ export class ChangeFixedImageCommand extends Command {
|
||||
this.scale = options.scale || { x: 1, y: 1 };
|
||||
this.preserveTransform = options.preserveTransform ?? false; // 默认不保留变换
|
||||
|
||||
this.options = options || {};
|
||||
|
||||
this.scale.x = options.scaleX || 1;
|
||||
this.scale.y = options.scaleY || 1;
|
||||
this.position.x = options.left || this.canvas.width / 2;
|
||||
this.position.y = options.top || this.canvas.height / 2;
|
||||
|
||||
// 用于回滚的状态
|
||||
this.previousImage = null;
|
||||
this.previousTransform = null;
|
||||
this.previousObjectId = null; // 保存之前对象的ID
|
||||
this.targetLayer = null;
|
||||
this.newObjectId = null; // 保存新对象的ID
|
||||
this.newObjectId = generateId("fixed_"); // 保存新对象的ID
|
||||
this.isExecuted = false;
|
||||
|
||||
// 错误处理
|
||||
this.maxRetries = options.maxRetries || 3;
|
||||
this.retryCount = 0;
|
||||
this.timeoutMs = options.timeoutMs || 10000;
|
||||
|
||||
// 查找目标图层
|
||||
this.targetLayer = this.findTargetLayer();
|
||||
}
|
||||
|
||||
async execute() {
|
||||
@@ -668,12 +678,9 @@ export class ChangeFixedImageCommand extends Command {
|
||||
|
||||
async applyImageToLayer(newImage) {
|
||||
await optimizeCanvasRendering(this.canvas, async () => {
|
||||
// 生成新对象ID
|
||||
this.newObjectId = generateId();
|
||||
|
||||
// 设置基本属性
|
||||
newImage.set({
|
||||
id: this.newObjectId,
|
||||
id: this.targetLayer?.fabricObject?.id || this.newObjectId,
|
||||
layerId: this.targetLayer.id,
|
||||
layerName: this.targetLayer.name,
|
||||
isBackground: this.targetLayer.isBackground,
|
||||
@@ -884,6 +891,8 @@ export class AddImageToLayerCommand extends Command {
|
||||
this.targetLayer = null;
|
||||
this.isExecuted = false;
|
||||
|
||||
this.imageId = generateId("image_");
|
||||
|
||||
// 错误处理
|
||||
this.maxRetries = options.maxRetries || 3;
|
||||
this.retryCount = 0;
|
||||
@@ -907,7 +916,7 @@ export class AddImageToLayerCommand extends Command {
|
||||
const newImage = await this.loadImageWithRetry();
|
||||
|
||||
// 添加图像到图层
|
||||
await this.addImageToLayer(newImage);
|
||||
await this.addImageToLayer(newImage, this.imageId);
|
||||
|
||||
this.isExecuted = true;
|
||||
|
||||
@@ -1061,10 +1070,7 @@ export class AddImageToLayerCommand extends Command {
|
||||
});
|
||||
}
|
||||
|
||||
async addImageToLayer(newImage) {
|
||||
// 生成唯一ID
|
||||
const objectId = generateId();
|
||||
|
||||
async addImageToLayer(newImage, objectId) {
|
||||
// 设置图像属性
|
||||
newImage.set({
|
||||
id: objectId,
|
||||
|
||||
Reference in New Issue
Block a user