From 2a73e346f9a12a01d33bfb9c4580c03a6922e49c Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Tue, 2 Jun 2026 08:33:02 +0800 Subject: [PATCH] xx --- src/components/devices/RobotTaskPage.tsx | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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]); // 获取路线列表