From 00ebd9c988cd4a89be469eeaf31c762d7e46ecc7 Mon Sep 17 00:00:00 2001 From: bighuixiang <472705331@qq.com> Date: Fri, 25 Jul 2025 21:38:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=94=BB=E5=B8=83?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=B1=82=E5=B1=85=E4=B8=AD=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E6=B2=A1=E6=9C=89=E8=A3=81?= =?UTF-8?q?=E5=89=AA=E8=B7=AF=E5=BE=84=E6=97=B6=E8=87=AA=E5=8A=A8=E5=B1=85?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CanvasEditor/managers/CanvasManager.js | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/component/Canvas/CanvasEditor/managers/CanvasManager.js b/src/component/Canvas/CanvasEditor/managers/CanvasManager.js index 6d258eea..164cc8c1 100644 --- a/src/component/Canvas/CanvasEditor/managers/CanvasManager.js +++ b/src/component/Canvas/CanvasEditor/managers/CanvasManager.js @@ -448,6 +448,9 @@ export class CanvasManager { // 获取背景对象 const backgroundObject = visibleObjects.find((obj) => obj.isBackground); + !this.canvas?.clipPath && + this.centerBackgroundLayer(this.canvas.width, this.canvas.height); + this.canvas?.clipPath?.set?.({ left: this.width / 2, top: this.height / 2, @@ -1031,11 +1034,11 @@ export class CanvasManager { // 重置视图变换以确保元素位置正确 this._resetViewportTransform(1); - let canvasClipPath = null; - // 克隆当前裁剪路径 - if (this.canvas?.clipPath) { - canvasClipPath = this.canvas?.clipPath; - } + // let canvasClipPath = null; + // // 克隆当前裁剪路径 + // if (this.canvas?.clipPath) { + // canvasClipPath = this.canvas?.clipPath; + // } // 清除当前画布内容 // this.canvas.clear(); // 清除画布内容 可以先去掉 这样加载闪动的情况就比较少 如果有问题 可以再打开 @@ -1047,26 +1050,28 @@ export class CanvasManager { // 清空重做栈 this.commandManager?.clear?.(); this.backgroundColor = parsedJson.backgroundColor || "#ffffff"; - if (canvasClipPath) { - // canvasClipPath.set({ - // absolutePositioned: true, - // }); - this.canvas.clipPath = canvasClipPath; - // await new Promise((resolve) => { - // debugger; - // fabric.util.enlivenObjects([canvasClipPath], (clipPaths) => { - // if (clipPaths && clipPaths.length > 0) { - // resolve(clipPaths[0]); - // } else { - // resolve(null); - // } - // }); - // }); - // debugger; - } + // if (canvasClipPath) { + // // canvasClipPath.set({ + // // absolutePositioned: true, + // // }); + // this.canvas.clipPath = canvasClipPath; + // // await new Promise((resolve) => { + // // debugger; + // // fabric.util.enlivenObjects([canvasClipPath], (clipPaths) => { + // // if (clipPaths && clipPaths.length > 0) { + // // resolve(clipPaths[0]); + // // } else { + // // resolve(null); + // // } + // // }); + // // }); + // // debugger; + // } try { // 重置画布数据 this.setCanvasSize(this.canvas.width, this.canvas.height); + this.centerBackgroundLayer(this.canvas.width, this.canvas.height); + debugger; // 重新构建对象关系 // restoreObjectLayerAssociations(this.layers.value, this.canvas.getObjects()); // 验证图层关联关系 - 稳定后可以注释