From 27e43f3c977e904f0a658bb049fabce98f80eb43 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, 20 Jan 2026 13:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=81=E6=95=B0=E6=8D=AE=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E7=94=BB=E5=B8=83=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/Canvas/CanvasEditor/index.vue | 2 +- .../CanvasEditor/managers/CanvasManager.js | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/component/Canvas/CanvasEditor/index.vue b/src/component/Canvas/CanvasEditor/index.vue index 021dfbe1..7c6efd7c 100644 --- a/src/component/Canvas/CanvasEditor/index.vue +++ b/src/component/Canvas/CanvasEditor/index.vue @@ -139,7 +139,7 @@ const props = defineProps({ default: false, // 是否隐藏画布-隐藏关闭部分功能 }, }); - +console.log("config",props.config) const loading = ref(false); // 引用和状态 const canvasRef = ref(null); diff --git a/src/component/Canvas/CanvasEditor/managers/CanvasManager.js b/src/component/Canvas/CanvasEditor/managers/CanvasManager.js index 426188ee..bf7ea1a6 100644 --- a/src/component/Canvas/CanvasEditor/managers/CanvasManager.js +++ b/src/component/Canvas/CanvasEditor/managers/CanvasManager.js @@ -449,7 +449,28 @@ export class CanvasManager { // // 重新渲染画布使变更生效 // this.canvas.renderAll(); } - + // 重置画布大小参照固定图层 + async resetCanvasSizeByFixedLayer(){ + // 重置画布大小为固定图层的大小 + const fixedLayerObj = this.getFixedLayerObject(); + const backgroundObject = this.getBackgroundLayerObject(); + if (!fixedLayerObj || !backgroundObject) return + const fwidth = fixedLayerObj.width * fixedLayerObj.scaleX + const fheight = fixedLayerObj.height * fixedLayerObj.scaleY + const bwidth = backgroundObject.width * backgroundObject.scaleX + const bheight = backgroundObject.height * backgroundObject.scaleY + if(Math.abs(fwidth/bwidth - fheight/bheight) < 0.1) return; + this.canvasWidth.value = fwidth + this.canvasHeight.value = fheight + backgroundObject.set({ + width: this.canvasWidth.value, + height: this.canvasHeight.value, + }) + this.canvas?.clipPath?.set?.({ + width: this.canvasWidth.value, + height: this.canvasHeight.value, + }) +} /** * 重置视图变换,使元素回到原始位置 * @private @@ -1369,6 +1390,7 @@ export class CanvasManager { // 重置画布数据 await this.setCanvasSize(this.canvas.width, this.canvas.height); await this.centerBackgroundLayer(this.canvas.width, this.canvas.height); + await this.resetCanvasSizeByFixedLayer(); // 重新构建对象关系 // restoreObjectLayerAssociations(this.layers.value, this.canvas.getObjects()); // 验证图层关联关系 - 稳定后可以注释