fix
This commit is contained in:
@@ -1330,7 +1330,7 @@ backgroundObject.scaleY,'CanvasManager resetCanvasSizeByFixedLayer')
|
|||||||
}
|
}
|
||||||
// 解析JSON字符串
|
// 解析JSON字符串
|
||||||
try {
|
try {
|
||||||
const parsedJson = JSON.parse(json);
|
const parsedJson = window.testCanvasJson || JSON.parse(json);
|
||||||
console.log("加载画布JSON数据:", parsedJson);
|
console.log("加载画布JSON数据:", parsedJson);
|
||||||
this.FixJsonIdLoss(parsedJson);
|
this.FixJsonIdLoss(parsedJson);
|
||||||
this.canvasWidth.value = parsedJson.canvasWidth || this.width;
|
this.canvasWidth.value = parsedJson.canvasWidth || this.width;
|
||||||
@@ -1411,7 +1411,7 @@ backgroundObject.scaleY,'CanvasManager resetCanvasSizeByFixedLayer')
|
|||||||
// console.log("图层关联验证结果:", isValidate);
|
// console.log("图层关联验证结果:", isValidate);
|
||||||
// 排序
|
// 排序
|
||||||
// 使用LayerSort工具重新排列画布对象(如果可用)
|
// 使用LayerSort工具重新排列画布对象(如果可用)
|
||||||
await this?.layerManager?.layerSort?.rearrangeObjects();
|
await this?.layerManager?.layerSort?.rearrangeObjectsAsync();
|
||||||
|
|
||||||
this.layerManager.activeLayerId.value = this.layers.value[0]
|
this.layerManager.activeLayerId.value = this.layers.value[0]
|
||||||
.children?.length
|
.children?.length
|
||||||
@@ -1455,15 +1455,21 @@ backgroundObject.scaleY,'CanvasManager resetCanvasSizeByFixedLayer')
|
|||||||
const layers = json?.layers || [];
|
const layers = json?.layers || [];
|
||||||
const objects = json?.canvas?.objects || [];
|
const objects = json?.canvas?.objects || [];
|
||||||
layers.forEach((layer) => {
|
layers.forEach((layer) => {
|
||||||
if(!layer.fabricObjects?.length && !layer.fabricObject){
|
if(!layer.fabricObjects?.[0]?.id && !layer.fabricObject?.id){
|
||||||
const obj = objects?.find((o) => o.layerId === layer.id);
|
const obj = objects?.find((o) => o.layerId === layer.id);
|
||||||
if(!obj) return;
|
if(obj) {
|
||||||
layer.fabricObjects = [{
|
layer.fabricObjects = [{
|
||||||
id: obj.id,
|
id: obj.id,
|
||||||
type: obj.type,
|
type: obj.type,
|
||||||
}]
|
}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// 排序
|
||||||
|
objects.sort((a, b) => {
|
||||||
|
if (a.isBackground) return -1;
|
||||||
|
if (b.isBackground) return 1;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1612,11 +1612,11 @@ export class LayerManager {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_rearrangeObjects() {
|
_rearrangeObjects() {
|
||||||
if (this.layerSort) {
|
// if (this.layerSort) {
|
||||||
// 使用LayerSort的高级排序
|
// // 使用LayerSort的高级排序
|
||||||
this.layerSort.rearrangeObjects();
|
// this.layerSort.rearrangeObjects();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 传统排序逻辑(保持原有逻辑作为备用)
|
// 传统排序逻辑(保持原有逻辑作为备用)
|
||||||
if (!this.canvas) return;
|
if (!this.canvas) return;
|
||||||
|
|||||||
@@ -71,17 +71,17 @@ export class LayerSort {
|
|||||||
// if (!layer.visible) {
|
// if (!layer.visible) {
|
||||||
// continue;
|
// 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++);
|
zIndexMap.set(id, currentZIndex++);
|
||||||
} else if (layer.isFixed && layer.fabricObject) {
|
} else if (layer.isFixed && id) {
|
||||||
// 固定图层对象
|
// 固定图层对象
|
||||||
zIndexMap.set(layer.fabricObject.id, currentZIndex++);
|
zIndexMap.set(id, currentZIndex++);
|
||||||
} else if (layer.isFixedOther && layer.fabricObject) {
|
} else if (layer.isFixedOther && id) {
|
||||||
// 其他固定图层对象
|
// 其他固定图层对象
|
||||||
zIndexMap.set(layer.fabricObject.id, currentZIndex++);
|
zIndexMap.set(id, currentZIndex++);
|
||||||
} else if (!layer.isBackground && !layer.isFixed) {
|
} else if (!layer.isBackground && !layer.isFixed) {
|
||||||
// 普通图层
|
// 普通图层
|
||||||
currentZIndex = this.processLayerObjects(
|
currentZIndex = this.processLayerObjects(
|
||||||
@@ -91,7 +91,6 @@ export class LayerSort {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return zIndexMap;
|
return zIndexMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user