diff --git a/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js b/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js index 5aa051d5..3b450e4d 100644 --- a/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js +++ b/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js @@ -123,29 +123,42 @@ export class FillGroupLayerBackgroundCommand extends Command { scaleX: clippingMaskFabricObject.scaleX || 1, scaleY: clippingMaskFabricObject.scaleY || 1, }); - this.newFill.clipPath = clippingMaskFabricObject; // 设置填充的遮罩 - this.newFill.dirty = true; // 标记为脏,以便重新 - this.canvas.add(this.newFill); - this.firstObj = this.newFill; - layer.fabricObjects = [ - this.newFill.toObject(["id", "layerId"]) || this.newFill, - ]; - layer.fill = null; // this.newFill.toObject(["id", "layerId"]); - layer.fillColor = this.fillColor; - // 取消激活对象 - - this.canvas.discardActiveObject(); // 取消当前活动对象 - // 重新排序 - await this.layerManager?.sortLayersWithTool?.(); - // 更新画布上对象的可选择状态 - await this.layerManager?.updateLayersObjectsInteractivity?.(); - this.canvas.renderAll(); - - this.canvasManager.thumbnailManager?.generateLayerThumbnail( - this.layer.id - ); + } else { + this.newFill = new fabric.Rect({ + width: this.canvasManager?.canvasWidth?.value || this.canvas.width, + height: this.canvasManager?.canvasHeight?.value || this.canvas.height, + left: this.canvas.width / 2 || 0, + top: this.canvas.height / 2 || 0, + fill: this.fillColor, + layerId: this.layerId, + id: this.oldFill?.id || generateId("fill-"), + selectable: false, + evented: false, + originX: "center", + originY: "center", + }); } + this.newFill.clipPath = clippingMaskFabricObject; // 设置填充的遮罩 + this.newFill.dirty = true; // 标记为脏,以便重新 + this.canvas.add(this.newFill); + this.firstObj = this.newFill; + layer.fabricObjects = [ + this.newFill.toObject(["id", "layerId"]) || this.newFill, + ]; + layer.fill = null; // this.newFill.toObject(["id", "layerId"]); + layer.fillColor = this.fillColor; + // 取消激活对象 + this.canvas.discardActiveObject(); // 取消当前活动对象 + // 重新排序 + await this.layerManager?.sortLayersWithTool?.(); + // 更新画布上对象的可选择状态 + await this.layerManager?.updateLayersObjectsInteractivity?.(); + this.canvas.renderAll(); + + this.canvasManager.thumbnailManager?.generateLayerThumbnail( + this.layer.id + ); return false; } const canvasObj = findObjectById(this.canvas, firstObj?.id)?.object;