diff --git a/src/pages/movement-supervision.vue b/src/pages/movement-supervision.vue index 54f0511..0db3584 100644 --- a/src/pages/movement-supervision.vue +++ b/src/pages/movement-supervision.vue @@ -148,19 +148,30 @@ const monitorScene = async () => { } }); - // 批量设置位置和可见性,只渲染一次 - const positionUpdates = updates.map(({ id, data }) => { - const { x, y, angle } = data; - if (isNil(x) || isNil(y)) { - return { id, visible: false }; - } else { - const newX = x - 60; - const newY = y - 60; - // 后端 angle 为逆时针,把转换改为“先取反再加偏移”: - const rotate = angle == null ? undefined : -angle + 180; - return { id, x: newX, y: newY, rotate, visible: true, locked: LockState.None }; - } - }); + // 批量设置位置和可见性(仅在提供坐标时更新) + const positionUpdates = updates + .map(({ id, data }) => { + const { x, y, angle } = data; + // 仅当提供 x、y 或 angle 时才更新位置/角度,避免因缺省数据误将可见性设为 false + if (isNil(x) && isNil(y) && angle == null) { + return undefined; + } + const payload: any = { id }; + if (!isNil(x) && !isNil(y)) { + const newX = x - 60; + const newY = y - 60; + payload.x = newX; + payload.y = newY; + payload.visible = true; + payload.locked = LockState.None; + } + if (angle != null) { + // 后端 angle 为逆时针,把转换改为“先取反再加偏移” + payload.rotate = -angle + 180; + } + return payload; + }) + .filter((v) => v); // 使用Meta2D的批量更新方法,减少渲染调用 positionUpdates.forEach((update) => {