fix(playback-websocket): 增强机器人数据更新逻辑,确保状态和充电信息的准确传递

This commit is contained in:
xudan 2025-10-29 09:42:25 +08:00
parent 1fbdb5efcb
commit 260ac45cb7

View File

@ -171,7 +171,7 @@ export function usePlaybackWebSocket(editorService: ShallowRef<EditorService | u
updates.forEach(({ id, data }) => {
const robotExists = editor.checkRobotById(id);
if (robotExists) {
const { x, y, angle, state, ...rest } = data;
const { x, y, angle, state, isCharging, isCarrying, canOrder, ...rest } = data;
const pen = editor.getPenById(id);
const currentState = pen?.robot?.state;
// 将业务数据和位置数据合并到一个对象中,通过 setValue 一次性更新
@ -186,10 +186,17 @@ export function usePlaybackWebSocket(editorService: ShallowRef<EditorService | u
...rest,
// 增加更严格的校验:确保 state 的值存在于 RobotState 枚举中
state: RobotState[state] ? state : (currentState ?? RobotState.),
// 确保传递载货和充电状态
isCharging: isCharging ?? 0,
isCarrying: isCarrying ?? 0,
canOrder: canOrder ?? true,
}, // 将业务数据挂载到图元的 robot 属性上
},
{ render: false },
);
// 更新状态覆盖图标
editor.updateRobotStatusOverlay(id, false);
}
});
};