feat(scene-editor): 优化多楼层场景保存逻辑,为每个楼层注入楼层号,增强数据完整性
This commit is contained in:
parent
7d0abea45e
commit
e7e53a9622
@ -139,7 +139,20 @@ const saveScene = async (payload?: SaveScenePayload) => {
|
||||
|
||||
let dataToSave: string | undefined;
|
||||
if (floorScenes.value.length > 1) {
|
||||
dataToSave = JSON.stringify(floorScenes.value);
|
||||
// 多楼层:为每个楼层的 JSON 注入 floor 楼层号(从 1 开始)
|
||||
const floorsWithIndex = floorScenes.value.map((scene: any, idx: number) => {
|
||||
try {
|
||||
const obj = typeof scene === 'string' ? JSON.parse(scene) : scene;
|
||||
if (obj && typeof obj === 'object') {
|
||||
return { ...obj, floor: idx + 1 };
|
||||
}
|
||||
return obj;
|
||||
} catch {
|
||||
// 解析失败则原样返回,避免中断保存
|
||||
return scene;
|
||||
}
|
||||
});
|
||||
dataToSave = JSON.stringify(floorsWithIndex);
|
||||
} else {
|
||||
const singleScene = floorScenes.value[0];
|
||||
if (typeof singleScene === 'string') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user