routepost 匹配任务id

This commit is contained in:
mmc
2026-09-08 17:17:59 +08:00
parent 7ebba1bbf6
commit 02e29b25d1
2 changed files with 41 additions and 2 deletions

View File

@@ -271,7 +271,46 @@ export default function RobotTaskPage() {
controller.onLocationInfoUpdate = setRobotRealtimePosition;
controller.onIsFinished = handleFinish;
controller.handleArrivedPoint = handleFinishEdPoint;
controller.onRoutePost = setPoints;
// 处理路线点回调:taskId必须和当前选中任务一致
controller.onRoutePost = (msg) => {
console.log('收到 route_post 消息:', msg);
const { taskId, data } = msg;
// 1. 先在任务池中查找该taskId对应的任务
const matchedTask = taskPoolList.find(task => String(task.id) === String(taskId));
// 2. 两种情况处理:
// a) 当前没有选中任务,且匹配到了任务池中的任务 → 自动选中该任务
// b) 当前已选中任务,且选中任务的id === 传来的taskId → 更新数据
const isSameAsSelected = runningPoolTask && String(runningPoolTask.id) === String(taskId);
const shouldSelectNewTask = !runningPoolTask && matchedTask;
if (isSameAsSelected || shouldSelectNewTask) {
console.log('taskId匹配成功,处理路线数据', {
taskId,
runningPoolTaskId: runningPoolTask?.id,
matchedTask
});
// 如果是匹配到新任务就设置选中状态
if (shouldSelectNewTask) {
setRunningPoolTask(matchedTask);
}
// 先直接用推送的data设置点(实时性)
if (data) {
setPoints(data);
}
} else {
console.log('taskId不匹配,忽略本次推送', {
receivedTaskId: taskId,
currentSelectedTaskId: runningPoolTask?.id,
matchedTaskFound: !!matchedTask
});
}
};

View File

@@ -362,7 +362,7 @@ export default class DeviceController {
case 'route_post':
console.log('route post:', msg);
if (msg.deviceId) {
this.onRoutePost?.(msg.data);
this.onRoutePost?.(msg);
}
break;