二维码生成和下载保存列表 优化 切换ws遗留的上一个在线设备数据 增加预定义路线生成 完善任务规划界面 的中英文

This commit is contained in:
mmc
2026-11-09 16:01:23 +08:00
parent 8924272656
commit 6401327522
9 changed files with 371 additions and 330 deletions

View File

@@ -109,8 +109,11 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
remark: '',
});
// 路径生成:工作模式(覆盖=true / 单点=false)、保存状态
const [isCoverage, setIscoverage] = useState(true);
// 路径生成:工作模式(coverage=覆盖 / single_point=单点 / predefined_path=预定义)、保存状态
const [workMode, setWorkMode] = useState<'coverage' | 'single_point' | 'predefined_path'>('coverage');
// 预定义模式:是否启动机器
const [ifStart, setIfStart] = useState(true);
const isCoverage = workMode === 'coverage' || workMode === 'predefined_path';
const [isSaving, setIsSaving] = useState(false);
// 预设路径点击预览(覆盖=多边形框,单点=折线)
const [previewPolyPoints, setPreviewPolyPoints] = useState<any[]>([]);
@@ -215,7 +218,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
id: String(p.id ?? genId()),
lon,
lat,
name: (p.alias || '').trim() || `返航点-${String(idx + 1).padStart(2, '0')}`,
name: (p.alias || '').trim() || `${t('devices.mapEditor.returnPoint')}-${String(idx + 1).padStart(2, '0')}`,
deviceId: p.bindDeviceId || undefined,
};
});
@@ -225,7 +228,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
const savedObstacles = (res?.data?.tempObstaclePoints || []).map((op: any, idx: number) => {
const lon = Number(op.position?.lng ?? op.position?.lon ?? op.position?.longitude ?? op.center?.lng ?? op.center?.lon ?? op.center?.longitude ?? op.longitude ?? 0);
const lat = Number(op.position?.lat ?? op.position?.latitude ?? op.center?.lat ?? op.center?.latitude ?? op.latitude ?? 0);
const name = (op.alias || op.name || '').trim() || `障碍物点-${idx + 1}`;
const name = (op.alias || op.name || '').trim() || t('devices.mapEditor.defaultObstaclePointName', { n: idx + 1 });
return {
id: op.id || genId(),
lon,
@@ -345,7 +348,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
...prev,
{
...point,
name: `返航点-${String(prev.length + 1).padStart(2, '0')}`,
name: `${t('devices.mapEditor.returnPoint')}-${String(prev.length + 1).padStart(2, '0')}`,
deviceId: selectedRobotId,
},
]);
@@ -354,7 +357,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
...prev,
{
...point,
name: `分区点-${String(prev.length + 1).padStart(2, '0')}`,
name: t('devices.mapEditor.defaultRegionName', { n: String(prev.length + 1).padStart(2, '0') }),
},
]);
} else if (activeType === 'routeGen') {
@@ -362,7 +365,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
...prev,
{
...point,
name: `路径点-${prev.length + 1}`,
name: t('devices.mapEditor.defaultRoutePointName', { n: prev.length + 1 }),
},
]);
} else {
@@ -371,7 +374,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
...prev,
{
...point,
name: `障碍物点-${prev.length + 1}`,
name: t('devices.mapEditor.defaultObstaclePointName', { n: prev.length + 1 }),
radius: 0.5,
shapeType: 'rect',
size_x: 0.5,
@@ -686,14 +689,14 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
if (!isReturnPoint && !isObstaclePoint) return;
const pointName = isReturnPoint
? item.alias || `返航点-${index + 1}`
: item.name || item.alias || `障碍物点-${index + 1}`;
? item.alias || `${t('devices.mapEditor.returnPoint')}-${index + 1}`
: item.name || item.alias || t('devices.mapEditor.defaultObstaclePointName', { n: index + 1 });
modal.confirm({
title: '确认删除',
content: `确定删除「${pointName}」吗?`,
okText: '删除',
cancelText: '取消',
title: t('devices.mapEditor.confirmDeleteTitle'),
content: t('devices.mapEditor.confirmDeleteContent', { name: pointName }),
okText: t('common.delete'),
cancelText: t('common.cancel'),
okButtonProps: { danger: true },
onOk: async () => {
@@ -754,69 +757,22 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
const res: any = await saveSiteMapInfo(payload);
if (res?.code === 200) {
messageApi.success('删除成功');
messageApi.success(t('common.deleteSuccess'));
// 刷新服务端数据及地图覆盖物
await getSiteMapInfoFn();
setOverlayRefreshKey((k) => k + 1);
} else {
messageApi.error(res?.msg || '删除失败');
messageApi.error(res?.msg || t('common.deleteFail'));
}
} catch (error) {
console.error('[MapEditor] 删除返航点/障碍物点失败:', error);
messageApi.error('删除失败,请稍后重试');
messageApi.error(t('devices.mapEditor.deleteFailedRetry'));
}
},
});
}; // 修改已配置障碍物点的尺寸
const handleUpdateObstacleDimensions = async (
item: any,
dimensions: { radius?: number; size_x?: number; size_y?: number; shapeType?: 'circle' | 'rect' }
) => {
try {
// 保留其他已配置障碍物点的数据,只修改当前项
const tempObstaclePoints = obstaclePointConfigList.map(
(point: any) => {
const isTarget = String(point.id) === String(item.id);
return {
position: {
lat: Number(point.position?.lat ?? point.lat ?? 0),
lng: Number(point.position?.lng ?? point.position?.lon ?? point.lon ?? 0),
},
radius: isTarget ? (dimensions.radius ?? point.radius) : Number(point.radius),
size_x: isTarget ? (dimensions.size_x ?? point.size_x) : Number(point.size_x),
size_y: isTarget ? (dimensions.size_y ?? point.size_y) : Number(point.size_y),
shapeType: isTarget ? (dimensions.shapeType ?? point.shapeType) : (point.shapeType || 'rect'),
alias: point.alias ?? point.name ?? '',
source: 'platform'
};
}
);
};
const payload: any = {
tempObstaclePoints,
siteId: stationId,
orgId: currentStation?.orgId,
};
if (siteMapInfoId != null) {
payload.id = siteMapInfoId;
}
const res: any = await saveSiteMapInfo(payload);
if (res?.code === 200) {
messageApi.success('障碍物点修改成功');
getSiteMapInfoFn();
setOverlayRefreshKey(k => k + 1);
} else {
messageApi.error(res?.msg || '障碍物点修改失败');
}
} catch (error) {
console.error('[MapEditor] update obstacle dimensions failed:', error);
messageApi.error('障碍物点修改失败');
}
};
// ========== 删除预设路径 ==========
const handleDeletePresetRoute = (route: any) => {
@@ -896,8 +852,9 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
siteId: stationId,
orgId: currentStation?.orgId,
jsonData: resultObj,
mode: isCoverage ? 'coverage' : 'single_point',
mode: workMode,
routeType: routeForm.routeType,
...(workMode === 'predefined_path' ? { ifStart } : {}),
};
formData.append('workRecord', new Blob([JSON.stringify(workRecord)], { type: 'application/json' }));
@@ -963,7 +920,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
onClick={() => setActiveType('returnPoint')}
icon={<Navigation size={14} />}
>
返航点
{t('devices.mapEditor.returnPoint')}
</Button>
<Button
type={activeType === 'restArea' ? 'primary' : 'default'}
@@ -971,7 +928,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
onClick={() => setActiveType('restArea')}
icon={<MapPinned size={14} />}
>
分区
{t('devices.mapEditor.restArea')}
</Button>
<Button
type={activeType === 'obstaclePoint' ? 'primary' : 'default'}
@@ -979,7 +936,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
onClick={() => setActiveType('obstaclePoint')}
icon={<MapPinned size={14} />}
>
障碍物点
{t('devices.mapEditor.obstaclePoint')}
</Button>
<Button
type={activeType === 'routeGen' ? 'primary' : 'default'}
@@ -987,7 +944,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
onClick={() => setActiveType('routeGen')}
icon={<Route size={14} />}
>
路径生成
{t('devices.mapEditor.routeGen')}
</Button>
</Space>
@@ -1016,16 +973,16 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
/>
</Space>
) : (
<span style={{ color: '#999', fontSize: 12 }}>路径模式:点击地图依次添加路径点</span>
<span style={{ color: '#999', fontSize: 12 }}>{t('devices.mapEditor.routeModeTip')}</span>
)}
<div style={{ flex: 1 }} />
<Space size={6}>
<Tooltip title="撤销">
<Tooltip title={t('devices.mapEditor.undo')}>
<Button size="small" icon={<UndoOutlined />} onClick={handleUndo} disabled={currentList.length === 0 && points.length === 0} />
</Tooltip>
<Tooltip title="清空">
<Tooltip title={t('devices.mapEditor.clearAll')}>
<Button size="small" icon={<ClearOutlined />} onClick={handleClearAll} />
</Tooltip>
</Space>
@@ -1072,7 +1029,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
zIndex: 10,
}}
>
{isRouteGen ? '点击地图添加路径点,按顺序生成路线' : '点击地图添加点位'}
{isRouteGen ? t('devices.mapEditor.clickAddRoutePoint') : t('devices.mapEditor.clickAddPoint')}
</div>
)}
@@ -1088,7 +1045,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
zIndex: 10,
}}
>
已选点位:{currentList.length}
{t('devices.mapEditor.selectedPoints', { count: currentList.length })}
</div>
)}
</div>
@@ -1111,7 +1068,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
{/* 【选择类型】卡片:嵌入模式下由任务规划右侧入口替代 */}
{!embedded && (<Card
size="small"
title="选择类型"
title={t('devices.mapEditor.selectType')}
variant="borderless"
styles={{ body: { padding: 12 } }}
>
@@ -1132,8 +1089,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
}}
>
<Navigation size={18} color="#165DFF" style={{ alignSelf: 'center' }} />
<div style={{ fontSize: 13, marginTop: 4 }}>返航点</div>
<div style={{ fontSize: 11, color: '#86909C' }}>机器人任务结束后返回的点位</div>
<div style={{ fontSize: 13, marginTop: 4 }}>{t('devices.mapEditor.returnPoint')}</div>
<div style={{ fontSize: 11, color: '#86909C' }}>{t('devices.mapEditor.returnPointDesc')}</div>
</div>
<div
onClick={() => setActiveType('restArea')}
@@ -1151,8 +1108,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
}}
>
<MapPinned size={18} color="#13C2C2" style={{ alignSelf: 'center' }} />
<div style={{ fontSize: 13, marginTop: 4 }}>分区</div>
<div style={{ fontSize: 11, color: '#86909C' }}>场站中发分区,绑定规划路线</div>
<div style={{ fontSize: 13, marginTop: 4 }}>{t('devices.mapEditor.restArea')}</div>
<div style={{ fontSize: 11, color: '#86909C' }}>{t('devices.mapEditor.restAreaDesc')}</div>
</div>
<div
@@ -1171,8 +1128,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
}}
>
<MapPinned size={18} color="#13C2C2" style={{ alignSelf: 'center' }} />
<div style={{ fontSize: 13, marginTop: 4 }}>障碍物点</div>
<div style={{ fontSize: 11, color: '#86909C' }}>场站中标记障碍物点,以半径为一个区域</div>
<div style={{ fontSize: 13, marginTop: 4 }}>{t('devices.mapEditor.obstaclePoint')}</div>
<div style={{ fontSize: 11, color: '#86909C' }}>{t('devices.mapEditor.obstaclePointDesc')}</div>
</div>
<div
onClick={() => setActiveType('routeGen')}
@@ -1190,8 +1147,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
}}
>
<Route size={18} color="#00B42A" style={{ alignSelf: 'center' }} />
<div style={{ fontSize: 13, marginTop: 4 }}>路径生成</div>
<div style={{ fontSize: 11, color: '#86909C' }}>生成规划路径</div>
<div style={{ fontSize: 13, marginTop: 4 }}>{t('devices.mapEditor.routeGen')}</div>
<div style={{ fontSize: 11, color: '#86909C' }}>{t('devices.mapEditor.routeGenDesc')}</div>
</div>
</div>
@@ -1259,21 +1216,38 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
</label>
<Select
className="w-full"
value={isCoverage}
onChange={(v) => setIscoverage(v)}
value={workMode}
onChange={(v) => setWorkMode(v)}
options={[
{ value: true, label: t('devices.coverageMode') },
{ value: false, label: t('devices.singleMode') },
{ value: 'coverage', label: t('devices.coverageMode') },
{ value: 'single_point', label: t('devices.singleMode') },
{ value: 'predefined_path', label: t('devices.predefinedPathMode') },
]}
/>
</div>
{workMode === 'predefined_path' && (
<div>
<label style={{ display: 'block', marginBottom: 6, fontSize: 13, color: '#333' }}>
{t('devices.startMachine')}
</label>
<Select
className="w-full"
value={ifStart}
onChange={(v) => setIfStart(v)}
options={[
{ value: true, label: t('common.yes') },
{ value: false, label: t('common.no') },
]}
/>
</div>
)}
{/* 路径点列表 */}
<div style={{ borderTop: '1px solid #f0f0f0', paddingTop: 10 }}>
<div style={{ fontSize: 13, fontWeight: 600, marginBottom: 8 }}>
{t('devices.mapEditor.routePoints')}
<span style={{ marginLeft: 8, fontSize: 12, color: '#999', fontWeight: 400 }}>
已选 {currentList.length} 个
{t('devices.mapEditor.selectedCount', { count: currentList.length })}
</span>
</div>
{currentList.length === 0 ? (
@@ -1328,9 +1302,9 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
size="small"
title={
<span style={{ fontSize: 14, fontWeight: 600 }}>
{activeType === 'returnPoint' ? '返航点列表' : activeType === 'obstaclePoint' ? '障碍物点列表' : '分区列表'}
{activeType === 'returnPoint' ? t('devices.mapEditor.returnPointList') : activeType === 'obstaclePoint' ? t('devices.mapEditor.configuredObstaclePoints') : t('devices.mapEditor.regionList')}
<span style={{ marginLeft: 8, fontSize: 12, color: '#999', fontWeight: 400 }}>
已选 {currentList.length} 个
{t('devices.mapEditor.selectedCount', { count: currentList.length })}
</span>
</span>
}
@@ -1354,7 +1328,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
{currentList.length === 0 ? (
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description="请在地图上选择或添加点位"
description={t('devices.mapEditor.pleaseAddPoint')}
/>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
@@ -1395,8 +1369,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
}}
style={{ marginBottom: 4 }}
>
<Radio value="rect">矩形</Radio>
{/*<Radio value="circle">圆形</Radio>*/}
<Radio value="rect">{t('devices.mapEditor.shapeRect')}</Radio>
{/*<Radio value="circle">{t('devices.mapEditor.shapeCircle')}</Radio>*/}
</Radio.Group>
{p.shapeType === 'circle' ? (
<Input
@@ -1404,7 +1378,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
value={p.radius}
type="number"
step="0.01"
prefix="半径:"
prefix={t('devices.mapEditor.radiusLabel') + ':'}
suffix="m"
onChange={(e) => {
const val = parseFloat(e.target.value);
@@ -1453,7 +1427,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
size="small"
value={p.deviceId}
allowClear
placeholder="未绑定"
placeholder={t('devices.mapEditor.unbound')}
onChange={(v) => bindRobot(p.id, v)}
style={{ width: '100%', marginTop: 4 }}
options={robots.map(r => ({
@@ -1487,7 +1461,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
<span style={{ fontSize: 14, fontWeight: 600 }}>
{t('devices.presetRoutes')}
<span style={{ marginLeft: 8, fontSize: 12, color: '#999', fontWeight: 400 }}>
共 {presetRoutes.length} 条
{t('devices.mapEditor.totalCountWithUnit', { count: presetRoutes.length })}
</span>
</span>
}
@@ -1524,8 +1498,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
</div>
<div style={{ fontSize: 11, color: '#86909C', marginTop: 2 }}>
{t('devices.mapEditor.mode')}: {route.mode === 'coverage' || route.mode === 'coverage_area'
? t('devices.coverageMode')
: t('devices.singleMode')}
? t('devices.coverageMode') : route.mode === 'predefined_path' ? t('devices.predefinedPathMode')
: t('devices.singleMode')}
{route.routeType && (
<span style={{ marginLeft: 8 }}>
· {route.routeType === 'MOWING_TASK' ? t('devices.mapEditor.typeMowing')
@@ -1563,7 +1537,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
{activeType === 'returnPoint'
? t('devices.mapEditor.configuredReturnPoints')
: activeType === 'obstaclePoint'
? '已配置障碍物点'
? t('devices.mapEditor.configuredObstaclePoints')
: t('devices.mapEditor.configuredRegions')}
<span
style={{
@@ -1691,10 +1665,10 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
>
<div onClick={(e) => e.stopPropagation()} style={{ fontSize: 13, fontWeight: 500, padding: '4px 0' }}>
{isReturnPoint
? ((item.alias || '').trim() || `返航点-${String(idx + 1).padStart(2, '0')}`)
? ((item.alias || '').trim() || `${t('devices.mapEditor.returnPoint')}-${String(idx + 1).padStart(2, '0')}`)
: isObstaclePoint
? (item.name || item.alias || `障碍物点-${idx + 1}`)
: (item.regionName || `分区-${idx + 1}`)}
? (item.name || item.alias || `${t('devices.mapEditor.obstaclePoint')}-${idx + 1}`)
: (item.regionName || `${t('devices.mapEditor.restArea')}-${idx + 1}`)}
</div>
{/* 已配置障碍物点:展示类型、尺寸与坐标 */}
@@ -1707,29 +1681,29 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
marginTop: 2,
}}
>
<div>类型: {item.shapeType === 'circle' ? '圆形' : '矩形'}</div>
<div>{t('common.type')}: {item.shapeType === 'circle' ? t('devices.mapEditor.shapeCircle') : t('devices.mapEditor.shapeRect')}</div>
{item.shapeType === 'circle' ? (
<div>半径: {item.radius}m</div>
<div>{t('devices.mapEditor.radiusLabel')}: {item.radius}m</div>
) : (
<div>尺寸: {item.size_x}m x {item.size_y}m</div>
<div>{t('devices.mapEditor.sizeLabel')}: {item.size_x}m x {item.size_y}m</div>
)}
<div style={{ color: '#C9CDD4', marginTop: 2 }}>
经度: {Number(item.lon ?? item.position?.lng ?? item.position?.lon ?? 0).toFixed(6)}
纬度: {Number(item.lat ?? item.position?.lat ?? 0).toFixed(6)}
{t('devices.mapEditor.longitude')}: {Number(item.lon ?? item.position?.lng ?? item.position?.lon ?? 0).toFixed(6)}
{t('devices.mapEditor.latitude')}: {Number(item.lat ?? item.position?.lat ?? 0).toFixed(6)}
</div>
</div>
)}
{isReturnPoint && (
<div style={{ fontSize: 11, color: '#C9CDD4', marginTop: 2 }}>
经度: {Number(item.lon ?? item.position?.lng ?? item.position?.lon ?? 0).toFixed(6)}
纬度: {Number(item.lat ?? item.position?.lat ?? 0).toFixed(6)}
{t('devices.mapEditor.longitude')}: {Number(item.lon ?? item.position?.lng ?? item.position?.lon ?? 0).toFixed(6)}
{t('devices.mapEditor.latitude')}: {Number(item.lat ?? item.position?.lat ?? 0).toFixed(6)}
</div>
)}
{/* 已配置返航点:展示绑定信息 */}
{isReturnPoint && item.bindDeviceId && (
<div style={{ fontSize: 11, color: '#86909C', marginTop: 2 }}>
绑定设备: {(() => {
{t('devices.mapEditor.bindDevice')}: {(() => {
const r = robots.find((x: any) => x.serialNumber === item.bindDeviceId);
return r ? `${r.deviceAlias || r.deviceName || r.serialNumber}(${r.serialNumber})` : item.bindDeviceId;
})()}

View File

@@ -824,7 +824,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
fetchTaskPoolList();
fetchTaskHistoryList();
} else {
utils.message.error(res.msg || '暂停失败');
utils.message.error(res.msg || t('devices.pauseFailed'));
}
} catch (err) {
console.error('暂停任务失败:', err);
@@ -846,7 +846,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
fetchTaskPoolList();
fetchTaskHistoryList();
} else {
utils.message.error(res.msg || '恢复失败');
utils.message.error(res.msg || t('devices.resumeFailed'));
}
} catch (err) {
console.error('恢复任务失败:', err);
@@ -1627,7 +1627,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
}}
>
<span style={{ fontSize: 14, fontWeight: 700 }}>
任务规划
{t('devices.mapEditor.taskPlan')}
</span>
@@ -2031,7 +2031,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
rowKey="id"
columns={taskHistoryColumns}
dataSource={taskHistoryList}
pagination={{ pageSize: 10, showSizeChanger: false, showQuickJumper: true, showTotal: (total) => '共 ' + total + ' 条' }}
pagination={{ pageSize: 10, showSizeChanger: false, showQuickJumper: true, showTotal: (total) => t('devices.mapEditor.totalCountWithUnit', { count: total }) }}
scroll={{ x: 800, y: 140 }}
/>
@@ -2097,7 +2097,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
]}
dataSource={consecutiveTaskList ?? []}
loading={consecutiveLoading}
pagination={{ pageSize: 10, showSizeChanger: false, showQuickJumper: true, showTotal: (total) => '共 ' + total + ' 条' }}
pagination={{ pageSize: 10, showSizeChanger: false, showQuickJumper: true, showTotal: (total) => t('devices.mapEditor.totalCountWithUnit', { count: total }) }}
scroll={{ x: 760, y: 140 }}
empty={<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />}
/>
@@ -2112,17 +2112,17 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
<Col xs={24} xl={8} style={{ display: "flex", flexDirection: "column" }}>
{/* 机器人任务规划:地图编辑能力入口 */}
<Card
title={<span style={{ fontSize: fontTitle, fontWeight: 700 }}>机器人任务规划</span>}
title={<span style={{ fontSize: fontTitle, fontWeight: 700 }}>{t('devices.mapEditor.robotTaskPlam')}</span>}
variant="borderless"
styles={{ body: { padding: 12 } }}
style={{ ...cardStyle, marginBottom: 10 }}
>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 8 }}>
{([
{ type: 'returnPoint' as const, label: '返航点', desc: '任务结束返回点', icon: <Navigation size={18} color="#165DFF" /> },
{ type: 'restArea' as const, label: '分区', desc: '绑定规划路线', icon: <MapPinned size={18} color="#13C2C2" /> },
{ type: 'obstaclePoint' as const, label: '障碍点', desc: '标记障碍区域', icon: <MapPinned size={18} color="#FF7D00" /> },
{ type: 'routeGen' as const, label: '路径生成', desc: '生成规划路径', icon: <Route size={18} color="#00B42A" /> },
{ type: 'returnPoint' as const, label: t('devices.mapEditor.returnPoint'), desc: t('devices.mapEditor.returnPointDesc'), icon: <Navigation size={18} color="#165DFF" /> },
{ type: 'restArea' as const, label: t('devices.mapEditor.restArea'), desc: t('devices.mapEditor.restAreaDesc'), icon: <MapPinned size={18} color="#13C2C2" /> },
{ type: 'obstaclePoint' as const, label: t('devices.mapEditor.obstaclePointLabel'), desc: t('devices.mapEditor.obstaclePointDesc'), icon: <MapPinned size={18} color="#FF7D00" /> },
{ type: 'routeGen' as const, label: t('devices.mapEditor.routeGen'), desc: t('devices.mapEditor.routeGenDesc'), icon: <Route size={18} color="#00B42A" /> },
]).map((item) => {
const selected = editorType === item.type;
return (
@@ -2258,7 +2258,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
lineHeight: '16px',
}}
>
选择需要执行任务的区域(可多选)
{t('devices.selectDispatchRegions')}
</div>
{/* 区域选择卡片 */}
@@ -2408,7 +2408,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
lineHeight: '16px',
}}
>
选择需要执行任务的路线(可多选)
{t('devices.selectDispatchRoutes')}
</div>
{/* 路线选择卡片 */}
@@ -2532,8 +2532,8 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 12 }}>
<TrendingUp size={16} style={{ color: '#1677ff' }} />
<span style={{ fontWeight: 600, fontSize: 13, color: '#1d2129' }}>调节执行顺序 (拖拽排序)</span>
<Tooltip title="机器人将按照下方列表从上到下的顺序依次执行路径任务">
<span style={{ fontWeight: 600, fontSize: 13, color: '#1d2129' }}>{t('devices.adjustExecutionOrder')}</span>
<Tooltip title={t('devices.dragSortTooltip')}>
<AlertCircle size={14} style={{ color: '#86909c', cursor: 'help' }} />
</Tooltip>
</div>

View File

@@ -30,6 +30,9 @@ export default class DeviceController {
this.wsStatus = 'disconnected';
this.wsDeviceInfo = {};
this.locationInfo = {};
// 切换设备后的实时数据门禁:AUTH 确认前丢弃无设备标识的遗留消息
this.authConfirmed = true;
this.switchAt = 0;
this.controlTimeout = null;
this.keepAliveInterval = null;
@@ -360,6 +363,9 @@ export default class DeviceController {
this.connectedDeviceSn = newSn;
this.wsDeviceInfo = {};
this.locationInfo = {};
// 切换设备:AUTH 确认前丢弃旧设备遗留的实时数据
this.authConfirmed = false;
this.switchAt = Date.now();
this.isControlled = false;
this.onControlStatusChange?.(false);
@@ -437,6 +443,20 @@ export default class DeviceController {
});
}
// 判断实时消息是否属于当前连接设备;设备切换过程中旧设备的遗留消息返回 true
isStaleRealtimeMessage(msg, data) {
const msgSn = data?.deviceId ?? data?.device_id ?? data?.deviceSn
?? msg?.deviceId ?? msg?.device_id ?? msg?.deviceSn ?? msg?.sn;
if (msgSn != null && String(msgSn) !== '') {
if (String(msgSn) !== String(this.connectedDeviceSn)) return true;
this.authConfirmed = true;
return false;
}
// 无设备标识:切换后 AUTH 确认前一律视为遗留数据(兜底 2 秒防止永久丢弃)
if (!this.authConfirmed) return Date.now() - (this.switchAt || 0) < 2000;
return false;
}
handleWsMessage(msg) {
console.log('WS message:', msg);
switch (msg.type) {
@@ -446,7 +466,7 @@ export default class DeviceController {
data[item.name] = item.value;
});
// 切换任务/切换设备时,忽略上一个设备遗留的实时数据
if (data?.deviceId && data.deviceId !== this.connectedDeviceSn) {
if (this.isStaleRealtimeMessage(msg, data)) {
break;
}
this.wsDeviceInfo = data;
@@ -459,7 +479,7 @@ export default class DeviceController {
data[item.name] = item.value;
});
// 切换任务/切换设备时,忽略上一个设备遗留的实时经纬度,只显示当前连接设备的实时轨迹
if (data?.deviceId && data.deviceId !== this.connectedDeviceSn) {
if (this.isStaleRealtimeMessage(msg, data)) {
break;
}
this.locationInfo = data;
@@ -469,6 +489,7 @@ export default class DeviceController {
case 'AUTH': {
if (msg.isAuth) {
this.authConfirmed = true;
this.getControl(this.connectedDeviceSn);
}
break;