From 4dfa9433fd56af9d7decbf99fbd61e6ce3e64ab5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E9=B9=8F?= <2916022834@qq.com>
Date: Tue, 27 Jan 2026 11:01:33 +0800
Subject: [PATCH] =?UTF-8?q?=E7=94=BB=E5=B8=83=20=E9=83=A8=E4=BB=B6?=
=?UTF-8?q?=E9=80=89=E5=8F=96=E3=80=81=E5=8D=B0=E8=8A=B1=E7=A6=81=E7=94=A8?=
=?UTF-8?q?=E5=A4=9A=E9=80=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FillGroupLayerBackgroundCommand.js | 5 +-
.../commands/LassoCutoutCommand.js | 12 +-
.../CanvasEditor/commands/PartCommands.js | 56 ++++
.../components/PartSelectorPanel.vue | 76 +----
.../components/SelectMenuPanel/index.vue | 13 +-
src/component/Canvas/CanvasEditor/index.vue | 8 +-
.../CanvasEditor/managers/CanvasManager.js | 6 +-
.../CanvasEditor/managers/PartManager.js | 316 ++++++++++++------
.../CanvasEditor/managers/ToolManager.js | 4 +-
.../Canvas/CanvasEditor/utils/helper.js | 1 +
src/component/Canvas/canvasExample.vue | 11 +-
src/component/Canvas/test.vue | 2 +-
12 files changed, 328 insertions(+), 182 deletions(-)
create mode 100644 src/component/Canvas/CanvasEditor/commands/PartCommands.js
diff --git a/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js b/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js
index edd061ac..26f90e2c 100644
--- a/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js
+++ b/src/component/Canvas/CanvasEditor/commands/FillGroupLayerBackgroundCommand.js
@@ -106,7 +106,6 @@ export class FillGroupLayerBackgroundCommand extends Command {
});
}
}
-
// 判断fabricObjects是否是组对象
const firstObj = layer.fabricObjects?.[0] || null;
// 如果没有找到第一个对象,则直接添加到当前画布
@@ -173,8 +172,8 @@ export class FillGroupLayerBackgroundCommand extends Command {
}
const canvasObj = findObjectById(this.canvas, firstObj?.id)?.object;
if (
- (canvasObj && canvasObj.type === "group") ||
- canvasObj._objects?.length > 0
+ canvasObj && (canvasObj.type === "group" ||
+ canvasObj._objects?.length > 0)
) {
this.newFill.set({
left: 0,
diff --git a/src/component/Canvas/CanvasEditor/commands/LassoCutoutCommand.js b/src/component/Canvas/CanvasEditor/commands/LassoCutoutCommand.js
index a3ad1eaf..b69f2cdc 100644
--- a/src/component/Canvas/CanvasEditor/commands/LassoCutoutCommand.js
+++ b/src/component/Canvas/CanvasEditor/commands/LassoCutoutCommand.js
@@ -147,11 +147,11 @@ export class LassoCutoutCommand extends CompositeCommand {
}
// 确定源图层
- const sourceLayer = this.layerManager.getActiveLayer();
- if (!sourceLayer) {
- console.error("无法执行套索抠图:源图层无效");
- return false;
- }
+ // const sourceLayer = this.layerManager.getActiveLayer();
+ // if (!sourceLayer) {
+ // console.error("无法执行套索抠图:源图层无效");
+ // return false;
+ // }
// 获取源图层的所有对象(包括子图层)
// const sourceObjects = this._getLayerObjects(sourceLayer);
@@ -225,7 +225,7 @@ export class LassoCutoutCommand extends CompositeCommand {
const layers = this.layerManager.layers.value;
var topLayerIndex = 0;
- layers.forEach((layer, index) => {
+ if(this.originalLayer)layers.forEach((layer, index) => {
if (layer.id === this.originalLayer.id) {
topLayerIndex = index;
}else if (layer.children.length > 0) {
diff --git a/src/component/Canvas/CanvasEditor/commands/PartCommands.js b/src/component/Canvas/CanvasEditor/commands/PartCommands.js
new file mode 100644
index 00000000..c8e1178c
--- /dev/null
+++ b/src/component/Canvas/CanvasEditor/commands/PartCommands.js
@@ -0,0 +1,56 @@
+import { Command } from "./Command.js";
+
+/**
+ * 部件绘制命令
+ */
+export class PartDrawCommand extends Command {
+ constructor(options) {
+ super({
+ name: "部件绘制命令",
+ saveState: false,
+ });
+
+ this.canvas = options.canvas;
+ this.partManager = options.partManager;
+ this.partCanvas = options.partCanvas;
+ this.oldPartCanvas = this.partManager.partCanvas;
+ }
+ execute() {
+ this.partManager.drawPartCanvas(this.partCanvas);
+ return true;
+ }
+ undo() {
+ this.partManager.drawPartCanvas(this.oldPartCanvas);
+ return true;
+ }
+}
+/**
+ * 部件点选绘制命令
+ */
+export class PartPointDrawCommand extends Command {
+ constructor(options) {
+ super({
+ name: "部件点选绘制命令",
+ saveState: false,
+ });
+
+ this.canvas = options.canvas;
+ this.partManager = options.partManager;
+ this.partCanvas = options.partCanvas;
+ this.pointList = options.pointList;
+ this.oldPartCanvas = this.partManager.partCanvas;
+ this.oldPointList = [...this.partManager.pointList];
+ }
+ async execute() {
+ const list = [...this.pointList];
+ const canvas = this.partCanvas;
+ const res = await this.partManager.pointDrawPartCanvas(list, canvas);
+ return res;
+ }
+ async undo() {
+ const list = [...this.oldPointList];
+ const canvas = this.oldPartCanvas;
+ const res = await this.partManager.pointDrawPartCanvas(list, canvas);
+ return res;
+ }
+}
diff --git a/src/component/Canvas/CanvasEditor/components/PartSelectorPanel.vue b/src/component/Canvas/CanvasEditor/components/PartSelectorPanel.vue
index 658d647f..1bf5d790 100644
--- a/src/component/Canvas/CanvasEditor/components/PartSelectorPanel.vue
+++ b/src/component/Canvas/CanvasEditor/components/PartSelectorPanel.vue
@@ -20,13 +20,13 @@
- Left Click: Add
+ {{ t("Canvas.LeftClickAdd") }}
- Right Click: Remove
+ {{ t("Canvas.RightClickRemove") }}