From 640132752214bb3834a33fb1a7525738054ca712 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Mon, 9 Nov 2026 16:01:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=92=8C=E4=B8=8B=E8=BD=BD=E4=BF=9D=E5=AD=98=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20=20=20=E4=BC=98=E5=8C=96=20=20=E5=88=87=E6=8D=A2ws=E9=81=97?= =?UTF-8?q?=E7=95=99=E7=9A=84=E4=B8=8A=E4=B8=80=E4=B8=AA=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=95=B0=E6=8D=AE=20=20=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=A2=84=E5=AE=9A=E4=B9=89=E8=B7=AF=E7=BA=BF=E7=94=9F=E6=88=90?= =?UTF-8?q?=20=20=20=20=E5=AE=8C=E5=96=84=E4=BB=BB=E5=8A=A1=E8=A7=84?= =?UTF-8?q?=E5=88=92=E7=95=8C=E9=9D=A2=20=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/systemSetting.ts | 3 +- src/components/Map.jsx | 3 +- ...lNumGenerate.jsx => SerialNumGenerate.tsx} | 292 ++++++------------ src/components/devices/MapEditorView.tsx | 196 +++++------- src/components/devices/TaskPlanningView.tsx | 28 +- src/components/devices/deviceController.js | 25 +- src/components/taskRadio/taskRadio.tsx | 16 +- src/locales/en/index.ts | 76 ++++- src/locales/zh/index.ts | 62 ++++ 9 files changed, 371 insertions(+), 330 deletions(-) rename src/components/SystemSetting/{SerialNumGenerate.jsx => SerialNumGenerate.tsx} (59%) diff --git a/src/api/systemSetting.ts b/src/api/systemSetting.ts index 568ccb4..d7242e9 100644 --- a/src/api/systemSetting.ts +++ b/src/api/systemSetting.ts @@ -293,10 +293,11 @@ export function getCodeListApi() { //分页查询二维码/system/qrcode/page -export function getCodeListPageApi() { +export function getCodeListPageApi(params) { return request({ url: `/system/qrcode/page`, method: 'get', + params }); } diff --git a/src/components/Map.jsx b/src/components/Map.jsx index eb2e9a5..5e877e6 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -1112,6 +1112,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, function resolveDeviceStatus(device) { const fsRaw = device?.feStatus; const stRaw = device?.status; + if (device?.onlineStatus == 0) return 'offline'; // feStatus:0=离线,1=工作中,2=空闲 if (fsRaw !== undefined && fsRaw !== null && fsRaw !== '') { @@ -3894,7 +3895,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, }} > ⌖ - 定位到机器 + {t('devices.mapEditor.location')} )} diff --git a/src/components/SystemSetting/SerialNumGenerate.jsx b/src/components/SystemSetting/SerialNumGenerate.tsx similarity index 59% rename from src/components/SystemSetting/SerialNumGenerate.jsx rename to src/components/SystemSetting/SerialNumGenerate.tsx index 4c82548..8d9936c 100644 --- a/src/components/SystemSetting/SerialNumGenerate.jsx +++ b/src/components/SystemSetting/SerialNumGenerate.tsx @@ -6,12 +6,12 @@ import { import QRCode from 'qrcode'; import DictManager from "../DictManager"; import request from '../../api/request'; -import { Country, State } from 'country-state-city'; import { useTranslation } from 'react-i18next'; import { EyeOutlined, EditOutlined, DeleteOutlined, + DownloadOutlined } from '@ant-design/icons'; // 接口导入 @@ -45,10 +45,6 @@ const SerialNumGenerate = () => { const [form] = Form.useForm(); const [searchForm] = Form.useForm(); - // 国家/省份 - const [allCountries, setAllCountries] = useState([]); - const [provinces, setProvinces] = useState([]); - // 二维码生成 const [qrUrl, setQrUrl] = useState(''); const [serialNumber, setSerialNumber] = useState(''); @@ -62,10 +58,7 @@ const SerialNumGenerate = () => { const [manageVisible, setManageVisible] = useState(false); const [addModalVisible, setAddModalVisible] = useState(false); - // 业务数据 - const [types, setTypes] = useState([]); - const [models, setModels] = useState([]); - const [configs, setConfigs] = useState([]); + // 二维码列表 const [codeList, setCodeList] = useState([]); @@ -81,40 +74,12 @@ const SerialNumGenerate = () => { const [viewModal, setViewModal] = useState(false); const [viewRecord, setViewRecord] = useState(null); - // 映射 - const countryNameMap = useRef({}); - const provinceNameMap = useRef({}); - - // 工具方法:解析 qrJson - const parseQrJson = (qrJson) => { - if (!qrJson) return {}; - try { - return JSON.parse(qrJson); - } catch { - return {}; - } - }; - // 初始化 useEffect(() => { - const countries = Country.getAllCountries(); - setAllCountries(countries || []); - countries.forEach(item => { - countryNameMap.current[item.isoCode] = item.name; - }); - loadTypeList(); - loadModelList(); - loadConfigList(); + loadCodeList(); }, [currentPage]); - // 国家切换 - const handleCountryChange = (countryCode) => { - const states = State.getStatesOfCountry(countryCode); - setProvinces(states || []); - form.setFieldsValue({ province: undefined }); - }; - // 加载二维码列表 const loadCodeList = async () => { setCodeLoading(true); @@ -165,64 +130,28 @@ const SerialNumGenerate = () => { setViewModal(true); }; - // 加载数据 - const loadTypeList = async () => { - try { - const res = await getRobotTypeListApi({}); - if (res?.code === 200) setTypes(res.data || []); - } catch (e) { } - }; - const loadModelList = async () => { - try { - const res = await getRobotModelPageApi({ pageNum: 1, pageSize: 100 }); - if (res?.code === 200) setModels(res.data || []); - } catch (e) { } - }; - const loadConfigList = async () => { - try { - const res = await getRobotConfigListApi({}); - if (res?.code === 200) setConfigs(res.data || []); - } catch (e) { } + // 列表下载单个二维码 + const handleDownloadItem = async (record) => { + if (!record.qrCodeBase64) { + return messageApi.warning(t('systemSetting.s26')); + } + const link = document.createElement('a'); + link.download = `${record.serialNumber || 'qrcode'}.png`; + link.href = record.qrCodeBase64; + link.click(); }; - // 生成序列号 - const generateSerialSuffix = () => { - const num = Math.floor(Math.random() * 100000000).toString(16).toUpperCase().padStart(8, '0'); - const check = Math.floor(Math.random() * 256).toString(16).toUpperCase().padStart(2, '0'); - return `${num}-${check}`; - }; - // 生成二维码 - const generateQRCode = async () => { + + // 根据输入的序列号生成二维码 + const generateQRCodeBySn = async (sn: string) => { try { - const values = await form.validateFields(); - const { model, config, type, country, province } = values; - const ts = Date.now(); - const suffix = generateSerialSuffix(); - - const parts = []; - if (model) parts.push(model + config); - if (country) parts.push(country); - if (province) parts.push(province); - parts.push(ts); - parts.push(suffix); - - const serialNumber = parts.join('-'); - const qrData = { - model, - config, - type, - countryCode: country, - countryFullName: countryNameMap.current[country] || country, - provinceCode: province, - provinceFullName: provinceNameMap.current[province] || province, - serialNumber + serialNumber: sn }; const qrContent = JSON.stringify(qrData, null, 2); const url = await QRCode.toDataURL(qrContent); - - setSerialNumber(serialNumber); + setSerialNumber(sn); setQrJson(qrContent); setQrUrl(url); } catch (err) { @@ -230,7 +159,19 @@ const SerialNumGenerate = () => { } }; - // 下载 + // 新增弹窗序列号输入变化时自动生成二维码 + const handleSnChange = (e: React.ChangeEvent) => { + const sn = e.target.value.trim(); + if (sn) { + generateQRCodeBySn(sn); + } else { + setSerialNumber(''); + setQrUrl(''); + setQrJson(''); + } + }; + + // 下载当前弹窗二维码 const downloadQRCode = () => { if (!qrUrl) return messageApi.warning(t('systemSetting.s26')); const link = document.createElement('a'); @@ -239,23 +180,15 @@ const SerialNumGenerate = () => { link.click(); }; - // 保存 + // 保存到数据库 const saveToDatabase = async () => { if (!serialNumber) return messageApi.warning(t('systemSetting.s26')); try { setLoading(true); - const values = form.getFieldsValue(); - const model = models.find(m => m.displayName === values.model); - const config = configs.find(c => c.displayName === values.config); - const type = types.find(t => t.storeValue === values.type); - const data = { serialNumber, - modelId: model?.id || 0, - configId: config?.id || 0, - typeId: type?.id || 0, qrCode: qrUrl, - qrJson: qrJson + }; const res = await saveCodeApi(data); @@ -279,9 +212,7 @@ const SerialNumGenerate = () => { // 查询 const handleQueryQRCode = async () => { - // 从搜索表单中获取序列号 const serialNumber = searchForm.getFieldValue('serialNumber'); - if (!serialNumber) { loadCodeList(); return; @@ -290,7 +221,6 @@ const SerialNumGenerate = () => { try { const res = await getCodeImgApi(serialNumber); if (res.data) { - setCodeList([res.data]); } else { messageApi.warning(t('systemSetting.notFixed2Search')); @@ -323,52 +253,8 @@ const SerialNumGenerate = () => { }; // 表格列 - // 表格列 —— 已修改:全部显示名称,不显示编码 const columns = [ - { - title: t('systemSetting.s222'), - key: 'idx', - width: 70, - render: (_, __, index) => (currentPage - 1) * pageSize + index + 1 - }, { title: t('systemSetting.s6'), width: 380, dataIndex: 'serialNumber', key: 'sn', ellipsis: true }, - { - title: t('systemSetting.s92'), - key: 'model', - render: (_, r) => { - const qrInfo = parseQrJson(r.qrJson); - const modelItem = models.find(m => m.storeValue == qrInfo.model); - return modelItem?.displayName || qrInfo.model || '-'; - } - }, - { - title: t('systemSetting.s112'), - key: 'config', - render: (_, r) => { - const qrInfo = parseQrJson(r.qrJson); - const configItem = configs.find(c => c.storeValue === qrInfo.config); - return configItem?.displayName || qrInfo.config || '-'; - } - }, - { - title: t('common.type'), - key: 'type', - render: (_, r) => { - const qrInfo = parseQrJson(r.qrJson); - const typeItem = types.find(t => t.storeValue === qrInfo.type); - return typeItem?.displayName || qrInfo.type || '-'; - } - }, - { - title: t('systemSetting.s142'), - key: 'country', - render: (_, r) => parseQrJson(r.qrJson).countryFullName || '-' - }, - { - title: t('systemSetting.s162'), - key: 'province', - render: (_, r) => parseQrJson(r.qrJson).provinceFullName || '-' - }, { title: t('systemSetting.s23'), key: 'img', @@ -378,11 +264,12 @@ const SerialNumGenerate = () => { { title: t('roles.actions'), key: 'opt', - width: 180, + width: 240, fixed: "right", render: (_, r) => ( + handleDelete(r.id)} @@ -410,14 +297,13 @@ const SerialNumGenerate = () => { extra={ - + {/**/} } > - {/* 筛选栏 */}
@@ -431,7 +317,7 @@ const SerialNumGenerate = () => {
- {/* 列表 —— 完全自适应 + 右侧固定 + 不溢出 */} + {/* 列表 */}
{ - {/* 新增弹窗 */} + {/* 新增弹窗 - 优化样式,只留序列号 */} { setAddModalVisible(false); form.resetFields(); @@ -461,44 +346,41 @@ const SerialNumGenerate = () => { footer={null} destroyOnClose > - - - - - - - - - - - - - - - - - - - - + + + + + - - -
+
+
{serialNumber && ( -
+
{t('systemSetting.s6')}:{serialNumber}
)} @@ -516,22 +398,44 @@ const SerialNumGenerate = () => { - {/* 查看二维码 */} - setViewModal(false)} footer={null} width={400}> + {/* 查看二维码弹窗 - 优化样式 + 增加下载 */} + setViewModal(false)} + footer={null} + width={420} + > {viewRecord && ( -
- qrcode -
{t('systemSetting.s6')}:{viewRecord.serialNumber}
+
+
+ qrcode + +
+
+ {t('systemSetting.s6')}:{viewRecord.serialNumber} +
+
)} {/* 数据管理 */} - setManageVisible(false)} footer={} destroyOnClose> + {/* setManageVisible(false)} footer={} destroyOnClose> - + */}
); }; diff --git a/src/components/devices/MapEditorView.tsx b/src/components/devices/MapEditorView.tsx index 5bc9b73..eba6f01 100644 --- a/src/components/devices/MapEditorView.tsx +++ b/src/components/devices/MapEditorView.tsx @@ -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([]); @@ -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={} > - 返航点 + {t('devices.mapEditor.returnPoint')} @@ -1016,16 +973,16 @@ export const MapEditorView = React.forwardRef(function MapEditorView( /> ) : ( - 路径模式:点击地图依次添加路径点 + {t('devices.mapEditor.routeModeTip')} )}
- +
)} @@ -1088,7 +1045,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView( zIndex: 10, }} > - 已选点位:{currentList.length} + {t('devices.mapEditor.selectedPoints', { count: currentList.length })}
)}
@@ -1111,7 +1068,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView( {/* 【选择类型】卡片:嵌入模式下由任务规划右侧入口替代 */} {!embedded && ( @@ -1132,8 +1089,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView( }} > -
返航点
-
机器人任务结束后返回的点位
+
{t('devices.mapEditor.returnPoint')}
+
{t('devices.mapEditor.returnPointDesc')}
setActiveType('restArea')} @@ -1151,8 +1108,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView( }} > -
分区
-
场站中发分区,绑定规划路线
+
{t('devices.mapEditor.restArea')}
+
{t('devices.mapEditor.restAreaDesc')}
-
障碍物点
-
场站中标记障碍物点,以半径为一个区域
+
{t('devices.mapEditor.obstaclePoint')}
+
{t('devices.mapEditor.obstaclePointDesc')}
setActiveType('routeGen')} @@ -1190,8 +1147,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView( }} > -
路径生成
-
生成规划路径
+
{t('devices.mapEditor.routeGen')}
+
{t('devices.mapEditor.routeGenDesc')}
@@ -1259,21 +1216,38 @@ export const MapEditorView = React.forwardRef(function MapEditorView( setIfStart(v)} + options={[ + { value: true, label: t('common.yes') }, + { value: false, label: t('common.no') }, + ]} + /> + + )} {/* 路径点列表 */}
{t('devices.mapEditor.routePoints')} - 已选 {currentList.length} 个 + {t('devices.mapEditor.selectedCount', { count: currentList.length })}
{currentList.length === 0 ? ( @@ -1328,9 +1302,9 @@ export const MapEditorView = React.forwardRef(function MapEditorView( size="small" title={ - {activeType === 'returnPoint' ? '返航点列表' : activeType === 'obstaclePoint' ? '障碍物点列表' : '分区列表'} + {activeType === 'returnPoint' ? t('devices.mapEditor.returnPointList') : activeType === 'obstaclePoint' ? t('devices.mapEditor.configuredObstaclePoints') : t('devices.mapEditor.regionList')} - 已选 {currentList.length} 个 + {t('devices.mapEditor.selectedCount', { count: currentList.length })} } @@ -1354,7 +1328,7 @@ export const MapEditorView = React.forwardRef(function MapEditorView( {currentList.length === 0 ? ( ) : (
@@ -1395,8 +1369,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView( }} style={{ marginBottom: 4 }} > - 矩形 - {/*圆形*/} + {t('devices.mapEditor.shapeRect')} + {/*{t('devices.mapEditor.shapeCircle')}*/} {p.shapeType === 'circle' ? ( { 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( {t('devices.presetRoutes')} - 共 {presetRoutes.length} 条 + {t('devices.mapEditor.totalCountWithUnit', { count: presetRoutes.length })} } @@ -1524,8 +1498,8 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
{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 && ( · {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')}
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}`)}
{/* 已配置障碍物点:展示类型、尺寸与坐标 */} @@ -1707,29 +1681,29 @@ export const MapEditorView = React.forwardRef(function MapEditorView( marginTop: 2, }} > -
类型: {item.shapeType === 'circle' ? '圆形' : '矩形'}
+
{t('common.type')}: {item.shapeType === 'circle' ? t('devices.mapEditor.shapeCircle') : t('devices.mapEditor.shapeRect')}
{item.shapeType === 'circle' ? ( -
半径: {item.radius}m
+
{t('devices.mapEditor.radiusLabel')}: {item.radius}m
) : ( -
尺寸: {item.size_x}m x {item.size_y}m
+
{t('devices.mapEditor.sizeLabel')}: {item.size_x}m x {item.size_y}m
)}
- 经度: {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)}
)} {isReturnPoint && (
- 经度: {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)}
)} {/* 已配置返航点:展示绑定信息 */} {isReturnPoint && item.bindDeviceId && (
- 绑定设备: {(() => { + {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; })()} diff --git a/src/components/devices/TaskPlanningView.tsx b/src/components/devices/TaskPlanningView.tsx index fbecf2a..71e1637 100644 --- a/src/components/devices/TaskPlanningView.tsx +++ b/src/components/devices/TaskPlanningView.tsx @@ -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 }} > - 任务规划 + {t('devices.mapEditor.taskPlan')} @@ -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={} /> @@ -2112,17 +2112,17 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
{/* 机器人任务规划:地图编辑能力入口 */} 机器人任务规划} + title={{t('devices.mapEditor.robotTaskPlam')}} variant="borderless" styles={{ body: { padding: 12 } }} style={{ ...cardStyle, marginBottom: 10 }} >
{([ - { type: 'returnPoint' as const, label: '返航点', desc: '任务结束返回点', icon: }, - { type: 'restArea' as const, label: '分区', desc: '绑定规划路线', icon: }, - { type: 'obstaclePoint' as const, label: '障碍点', desc: '标记障碍区域', icon: }, - { type: 'routeGen' as const, label: '路径生成', desc: '生成规划路径', icon: }, + { type: 'returnPoint' as const, label: t('devices.mapEditor.returnPoint'), desc: t('devices.mapEditor.returnPointDesc'), icon: }, + { type: 'restArea' as const, label: t('devices.mapEditor.restArea'), desc: t('devices.mapEditor.restAreaDesc'), icon: }, + { type: 'obstaclePoint' as const, label: t('devices.mapEditor.obstaclePointLabel'), desc: t('devices.mapEditor.obstaclePointDesc'), icon: }, + { type: 'routeGen' as const, label: t('devices.mapEditor.routeGen'), desc: t('devices.mapEditor.routeGenDesc'), icon: }, ]).map((item) => { const selected = editorType === item.type; return ( @@ -2258,7 +2258,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC lineHeight: '16px', }} > - 选择需要执行任务的区域(可多选) + {t('devices.selectDispatchRegions')}
{/* 区域选择卡片 */} @@ -2408,7 +2408,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC lineHeight: '16px', }} > - 选择需要执行任务的路线(可多选) + {t('devices.selectDispatchRoutes')} {/* 路线选择卡片 */} @@ -2532,8 +2532,8 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC >
- 调节执行顺序 (拖拽排序) - + {t('devices.adjustExecutionOrder')} +
diff --git a/src/components/devices/deviceController.js b/src/components/devices/deviceController.js index 6d74e34..8bf656b 100644 --- a/src/components/devices/deviceController.js +++ b/src/components/devices/deviceController.js @@ -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; diff --git a/src/components/taskRadio/taskRadio.tsx b/src/components/taskRadio/taskRadio.tsx index 518841c..4615238 100644 --- a/src/components/taskRadio/taskRadio.tsx +++ b/src/components/taskRadio/taskRadio.tsx @@ -6,6 +6,8 @@ import { CheckCircleFilled, } from '@ant-design/icons'; import './TaskTypeRadio.css' +import { useTranslation } from 'react-i18next'; + type DispatchMode = 'immediate' | 'scheduled'; interface TaskTypeRadioProps { @@ -17,6 +19,8 @@ const TaskTypeRadio: React.FC = ({ value, onChange, }) => { + const { t } = useTranslation(); + const options: { value: DispatchMode; title: string; @@ -25,22 +29,24 @@ const TaskTypeRadio: React.FC = ({ }[] = [ { value: 'immediate', - title: '立即执行任务', - description: '下发后机器人立即开始执行', + title: t('devices.taskTypeRadio.immediate'), + description: t('devices.taskTypeRadio.immediateDescription'), icon: , }, { value: 'scheduled', - title: '定时任务', - description: '设置开始时间和重复周期', + title: t('devices.taskTypeRadio.scheduled'), + description: t('devices.taskTypeRadio.scheduledDescription'), icon: , }, ]; + + return (
- 选择任务类型 + {t('devices.taskTypeRadio.taskType')}