和算法联调显示规划路径 并且 显示实时路径成功
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import {
|
||||
Row, Col, Card, Button, Space, Table, Tag, Typography, Progress, Badge,
|
||||
Tabs, Input, Switch, Divider, Tooltip, Timeline, Select, message, DatePicker,
|
||||
@@ -146,9 +146,7 @@ export default function RobotTaskPage() {
|
||||
setExecute(false);
|
||||
setShowVideo(false); // 任务完成关闭视频
|
||||
utils.message.success(t('devices.fixed2TaskSuspended2Fixed2CompletedFixed2'));
|
||||
//if (controllerRef.current) {
|
||||
// controllerRef.current.destroy?.();
|
||||
//}
|
||||
|
||||
setClearNavLine(clearNavLine + 1);
|
||||
setSelectedRobotForExecute(null);
|
||||
setSelectedRouteForExecute(null);
|
||||
@@ -157,6 +155,7 @@ export default function RobotTaskPage() {
|
||||
fetchTaskPoolList();
|
||||
|
||||
|
||||
|
||||
}
|
||||
const handleFinishEdPoint = (point) => {
|
||||
setArrivedPoint(point);
|
||||
@@ -252,6 +251,9 @@ export default function RobotTaskPage() {
|
||||
controller.onLocationInfoUpdate = setRobotRealtimePosition;
|
||||
controller.onIsFinished = handleFinish;
|
||||
controller.handleArrivedPoint = handleFinishEdPoint;
|
||||
controller.onRoutePost = setPoints;
|
||||
|
||||
|
||||
|
||||
controller.init();
|
||||
|
||||
@@ -284,6 +286,7 @@ export default function RobotTaskPage() {
|
||||
const runningTask = taskPoolList.find(item => ['EXECUTING', 'PAUSE'].includes(item.taskStaus));
|
||||
|
||||
if (!runningTask) return;
|
||||
fetchRouteDetail(runningTask?.id);
|
||||
|
||||
// 找到对应的设备
|
||||
const targetDevice = devices.find(d => d.serialNumber === runningTask.deviceId);
|
||||
@@ -391,43 +394,14 @@ export default function RobotTaskPage() {
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!selectedPathWork?.id) {
|
||||
//console.log('获取任务列表', selectedPathWork?.id);
|
||||
if (!selectedRobotForExecute?.id || !execute) {
|
||||
setPoints([]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用接口获取路线详情
|
||||
const fetchRouteDetail = async () => {
|
||||
try {
|
||||
const res = await getTaskPath({ taskId: selectedPathWork.id })
|
||||
//const res = await getSingleRouteList({ id: selectedPathWork.id });
|
||||
if (res?.code === 200 && res?.data) {
|
||||
let pathPoints = [];
|
||||
|
||||
try {
|
||||
// 尝试解析 JSON
|
||||
pathPoints = res.data || [];
|
||||
} catch (err) {
|
||||
console.error('解析路线数据失败:', err);
|
||||
}
|
||||
|
||||
if (pathPoints.length === 0) {
|
||||
utils.message.warning(t('devices.route2'));
|
||||
}
|
||||
|
||||
setPoints(pathPoints);
|
||||
|
||||
} else {
|
||||
setPoints([]);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取路线详情失败:', err);
|
||||
setPoints([]);
|
||||
}
|
||||
};
|
||||
|
||||
fetchRouteDetail();
|
||||
}, [selectedPathWork]);
|
||||
}, [selectedRobotForExecute?.id]);
|
||||
|
||||
// 监听任务池列表变化,自动加载第一个任务的路径
|
||||
useEffect(() => {
|
||||
@@ -436,6 +410,41 @@ export default function RobotTaskPage() {
|
||||
|
||||
}
|
||||
}, [taskPoolList]);
|
||||
// 调用接口获取路线详情
|
||||
const fetchRouteDetail = async (id) => {
|
||||
console.log(id, "获取正在执行任务的id")
|
||||
try {
|
||||
const params = {
|
||||
taskId: id,
|
||||
}
|
||||
|
||||
const res = await getTaskPath(params)
|
||||
//const res = await getSingleRouteList({ id: selectedPathWork.id });
|
||||
if (res?.code === 200 && res?.data) {
|
||||
let pathPoints = [];
|
||||
|
||||
try {
|
||||
// 尝试解析 JSON
|
||||
pathPoints = res.data || [];
|
||||
} catch (err) {
|
||||
console.error('解析路线数据失败:', err);
|
||||
}
|
||||
|
||||
if (pathPoints.length === 0) {
|
||||
utils.message.warning(t('devices.route2'));
|
||||
}
|
||||
|
||||
setPoints(pathPoints);
|
||||
|
||||
} else {
|
||||
setPoints([]);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取路线详情失败:', err);
|
||||
setPoints([]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -665,6 +674,8 @@ export default function RobotTaskPage() {
|
||||
setSelectedRobotForExecute(null);
|
||||
setSelectedRouteForExecute(null);
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
utils.message.error(t('devices.taskCancelFail'));
|
||||
}
|
||||
@@ -1169,7 +1180,7 @@ export default function RobotTaskPage() {
|
||||
focusLocation={focusLocation}
|
||||
realtimePosition={realtimePosition}
|
||||
realtimeType="robot"
|
||||
from="device-control"
|
||||
from="deviceStatus"
|
||||
drawRealTime={execute}
|
||||
finishPoint={arrivedPoint}
|
||||
ifClearNavLine={clearNavLine}
|
||||
|
||||
@@ -40,6 +40,7 @@ export default class DeviceController {
|
||||
this.onHasControlRightChange = null;
|
||||
this.onRequestControlStatusChange = null;
|
||||
this.onPermissionRequest = null;
|
||||
this.onRoutePost = null;
|
||||
this.onIsFinished = null;
|
||||
this.handleArrivedPoint = null;
|
||||
|
||||
@@ -358,6 +359,14 @@ export default class DeviceController {
|
||||
});
|
||||
break;
|
||||
|
||||
case 'route_post':
|
||||
console.log('route post:', msg);
|
||||
if (msg.deviceId) {
|
||||
this.onRoutePost?.(msg.data);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user