Compare commits

2 Commits

Author SHA1 Message Date
李志鹏
c731df2ae7 Merge branch 'StableVersion' of http://18.167.251.121:10003/aidlab/aida_front into StableVersion 2026-01-21 16:31:09 +08:00
李志鹏
40c9bb1190 json修复 2026-01-21 16:31:07 +08:00
2 changed files with 30 additions and 6 deletions

View File

@@ -1098,7 +1098,7 @@ FixJsonIdLoss(json){
// console.log("图层关联验证结果:", isValidate);
// 排序
// 使用LayerSort工具重新排列画布对象如果可用
await this?.layerManager?.layerSort?.rearrangeObjects();
await this?.layerManager?.layerSort?.rearrangeObjectsAsync();
this.layerManager.activeLayerId.value = this.layers.value[0]
.children?.length
@@ -1140,6 +1140,27 @@ FixJsonIdLoss(json){
throw new Error("解析JSON失败请检查输入格式: " + error.message);
}
}
/** 修复JSON数据中的ID丢失问题 */
FixJsonIdLoss(json){
const layers = json?.layers || [];
const objects = json?.canvas?.objects || [];
layers.forEach((layer) => {
if(!layer.fabricObjects?.[0]?.id && !layer.fabricObject?.id){
const obj = objects?.find((o) => o.layerId === layer.id);
if(obj) {
layer.fabricObjects = [{
id: obj.id,
type: obj.type,
}]
}
}
})
// 排序
objects.sort((a, b) => {
if (a.isBackground) return -1;
if (b.isBackground) return 1;
})
}
/**
* 缩放红绿图模式内容以适应当前画布大小

View File

@@ -71,14 +71,17 @@ export class LayerSort {
// if (!layer.visible) {
// continue;
// }
let id = layer.fabricObject?.id || layer.fabricObjects?.[0]?.id || null;
// 处理不同类型的图层
if (layer.isBackground && layer.fabricObject) {
if (layer.isBackground && id) {
// 背景图层对象放在最底层
zIndexMap.set(layer.fabricObject.id, currentZIndex++);
} else if (layer.isFixed && layer.fabricObject) {
zIndexMap.set(id, currentZIndex++);
} else if (layer.isFixed && id) {
// 固定图层对象
zIndexMap.set(layer.fabricObject.id, currentZIndex++);
zIndexMap.set(id, currentZIndex++);
} else if (layer.isFixedOther && id) {
// 其他固定图层对象
zIndexMap.set(id, currentZIndex++);
} else if (!layer.isBackground && !layer.isFixed) {
// 普通图层
currentZIndex = this.processLayerObjects(