老数据重置画布大小

This commit is contained in:
李志鹏
2026-01-20 13:18:28 +08:00
parent eb1de5abb3
commit 27e43f3c97
2 changed files with 24 additions and 2 deletions

View File

@@ -139,7 +139,7 @@ const props = defineProps({
default: false, // 是否隐藏画布-隐藏关闭部分功能
},
});
console.log("config",props.config)
const loading = ref(false);
// 引用和状态
const canvasRef = ref(null);

View File

@@ -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());
// 验证图层关联关系 - 稳定后可以注释