diff --git a/src/components/devices/RobotTaskPage.tsx b/src/components/devices/RobotTaskPage.tsx index 70ebc18..701197c 100644 --- a/src/components/devices/RobotTaskPage.tsx +++ b/src/components/devices/RobotTaskPage.tsx @@ -100,10 +100,28 @@ export default function RobotTaskPage({ devices }) { }; useEffect(() => { console.log('selectedPathWork changed:', selectedPathWork); - if (JSON.parse(selectedPathWork.jsonData)?.path?.length == 0) { - utils.message.warning('该路线暂无路径点数据'); + + try { + // 1. 没有数据直接清空 + if (!selectedPathWork?.jsonData) { + setPoints([]); + return; + } + + // 2. 安全解析 JSON + const data = JSON.parse(selectedPathWork?.jsonData); + const path = data?.path || []; + + // 3. 空路径提示 + if (path.length === 0) { + utils.message.warning('该路线暂无路径点数据'); + } + // 4. 设置点位 + setPoints(path); + } catch (err) { + console.error('解析路径 JSON 失败:', err); + setPoints([]); // 解析失败也不崩溃 } - setPoints(selectedPathWork ? JSON.parse(selectedPathWork.jsonData)?.path || [] : []); }, [selectedPathWork]); // 获取路线列表