From 0771df25ffdfc57cf78ea1309c12c9b29ce4cf18 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 12 Jun 2026 17:13:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=B8=AA=E8=B7=AF=E5=BE=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20=E6=B5=8B=E8=AF=95=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/devices/RobotTaskPage.tsx | 108 +++++++++++++++-------- 1 file changed, 69 insertions(+), 39 deletions(-) diff --git a/src/components/devices/RobotTaskPage.tsx b/src/components/devices/RobotTaskPage.tsx index f46437c..15e0877 100644 --- a/src/components/devices/RobotTaskPage.tsx +++ b/src/components/devices/RobotTaskPage.tsx @@ -21,6 +21,7 @@ import { import { getRobotRouteList, + getSingleRouteList, getPlaneDeviceListAll, saveDeviceTask, getRobotTaskList, deleteDeviceTask, getSiteDevice, @@ -236,28 +237,44 @@ export default function RobotTaskPage() { } }; useEffect(() => { - - try { - // 1. 没有数据直接清空 - if (!selectedPathWork?.jsonData) { - setPoints([]); - return; - } - - // 2. 安全解析 JSON - const data = selectedPathWork?.jsonData; - const path = data?.path || []; - - // 3. 空路径提示 - if (path.length === 0) { - utils.message.warning('该路线暂无路径点数据'); - } - // 4. 设置点位 - setPoints(path); - } catch (err) { - console.error('解析路径 JSON 失败:', err); - setPoints([]); // 解析失败也不崩溃 + // 如果没有选中路线,清空点位 + if (!selectedPathWork?.id) { + setPoints([]); + return; } + + // 调用接口获取路线详情 + const fetchRouteDetail = async () => { + try { + const res = await getSingleRouteList({ id: selectedPathWork.id }); + if (res?.code === 200 && res?.data) { + let pathPoints = []; + try { + // 尝试解析 JSON + if (res.data.jsonData) { + const data = typeof res.data.jsonData === 'string' + ? JSON.parse(res.data.jsonData) + : res.data.jsonData; + pathPoints = data?.path || []; + } + } catch (err) { + console.error('解析路线数据失败:', err); + } + + if (pathPoints.length === 0) { + utils.message.warning('该路线暂无路径点数据'); + } + setPoints(pathPoints); + } else { + setPoints([]); + } + } catch (err) { + console.error('获取路线详情失败:', err); + setPoints([]); + } + }; + + fetchRouteDetail(); }, [selectedPathWork]); // 获取路线列表 @@ -297,28 +314,41 @@ export default function RobotTaskPage() { robot: null }); }; - const handleTaskexcuted = (route) => { - - // 检查路径点 - let hasPathPoints = false; + const handleTaskexcuted = async (route) => { try { - if (route.jsonData) { - const data = route.jsonData; - hasPathPoints = data.path && data.path.length > 0; + console.log(route); + setSelectedRouteForExecute(route); + + setExecuteModalVisible(true); + setSelectedRobotForExecute(null); + + // 调用接口检查是否有路径点 + const res = await getSingleRouteList({ id: route.id }); + let hasPathPoints = false; + + if (res?.code === 200 && res?.data) { + try { + if (res.data.jsonData) { + const data = typeof res.data.jsonData === 'string' + ? JSON.parse(res.data.jsonData) + : res.data.jsonData; + hasPathPoints = data?.path && data.path.length > 0; + } + } catch (err) { + console.error('解析路线数据失败:', err); + } } + + if (!hasPathPoints) { + utils.message.warning('该路线没有路径点,无法执行'); + return; + } + + } catch (err) { - console.error('解析路径数据失败:', err); - hasPathPoints = false; + console.error('检查路线失败:', err); + utils.message.error('检查路线失败'); } - - if (!hasPathPoints) { - utils.message.warning('该路线没有路径点,无法执行'); - return; - } - - setSelectedRouteForExecute(route); - setSelectedRobotForExecute(null); - setExecuteModalVisible(true); } const handleExecuteConfirm = async () => {