This commit is contained in:
李志鹏
2026-01-21 16:38:10 +08:00
parent c731df2ae7
commit 8c4f4c206b

View File

@@ -993,21 +993,6 @@ export class CanvasManager {
throw new Error("获取画布JSON失败");
}
}
/** 修复JSON数据中的ID丢失问题 */
FixJsonIdLoss(json){
const layers = json?.layers || [];
const objects = json?.canvas?.objects || [];
layers.forEach((layer) => {
if(!layer.fabricObjects?.length && !layer.fabricObject){
const obj = objects?.find((o) => o.layerId === layer.id);
if(!obj) return;
layer.fabricObjects = [{
id: obj.id,
type: obj.type,
}]
}
})
}
loadJSON(json, calllBack) {
console.log("加载画布JSON数据:", json);
@@ -1019,7 +1004,7 @@ FixJsonIdLoss(json){
}
// 解析JSON字符串
try {
const parsedJson = JSON.parse(json);
const parsedJson = window.testCanvasJson || JSON.parse(json);
this.FixJsonIdLoss(parsedJson);
this.canvasWidth.value = parsedJson.canvasWidth || this.width;
this.canvasHeight.value = parsedJson.canvasHeight || this.height;