From 951b9fa9e52083e5b9d8f591d6b86cc9c240f910 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 30 Oct 2026 16:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=9C=E7=A2=8D=E7=89=A9=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Map.jsx | 291 +++++++++++--------- src/components/devices/DeviceStatusPage.tsx | 19 ++ src/components/devices/MapEditorPage.tsx | 13 +- src/components/devices/RobotTaskPage.tsx | 10 + src/components/devices/deviceController.js | 23 +- src/locales/en/index.ts | 2 + src/locales/zh/index.ts | 1 + 7 files changed, 215 insertions(+), 144 deletions(-) diff --git a/src/components/Map.jsx b/src/components/Map.jsx index 3924391..4857f4c 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -16,7 +16,7 @@ import * as Cesium from 'cesium'; import 'cesium/Build/Cesium/Widgets/widgets.css'; -const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, finishPoint, drawRealTime, realtimePosition, realtimeType, pathPoints = [], devices = [], onCameraClick, focusLocation, points = [], markedPoints = [], onPathChange, from, onClearDraw, onMarkPoint, routeMode = '', polyPoints, mapLayer, activeType, overlayRefreshKey = 0, focusOverlay = null, onObstacleRadiusChange, obstacleShapes = [], onObstacleRectResize, siteMapInfoId }, ref) => { +const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, finishPoint, drawRealTime, realtimePosition, realtimeType, pathPoints = [], devices = [], onCameraClick, focusLocation, points = [], markedPoints = [], onPathChange, from, onClearDraw, onMarkPoint, routeMode = '', polyPoints, mapLayer, activeType, overlayRefreshKey = 0, focusOverlay = null, onObstacleRadiusChange, obstacleShapes = [], onObstacleRectResize, siteMapInfoId, detectReportInfo }, ref) => { const containerRef = useRef(null); const viewerRef = useRef(null); const tooltipRef = useRef(null); @@ -78,6 +78,8 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, // try { viewer.camera.cancelFlight(); } catch (e) { /* 忽略取消异常 */ } // viewer.camera.flyTo(config); //}; + + const resetFlightPriority = () => { lastFlightPriorityRef.current = -1; }; const getObstacleHandlePosition = ( lon, @@ -246,80 +248,12 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, if (lastFlightPromiseRef.current) viewer.camera.cancelFlight(); }; }, []); - - const flyToView = (viewer, priority, config, key = '') => { - if (!viewer || viewer.isDestroyed()) return false; - - const state = flightStateRef.current; - const now = Date.now(); - - // 相同目标正在飞行,忽略重复请求 - if ( - state.flying && - state.priority === priority && - state.key === key && - now - (state.startedAt || 0) < 3000 - ) { - return false; - } - - // 仅在当前飞行尚未结束时执行优先级比较 - if (state.flying && priority < state.priority) { - return false; - } - - const token = ++state.token; - - state.priority = priority; - state.key = key; - state.startedAt = now; - state.flying = true; - - try { - viewer.camera.cancelFlight(); - - viewer.camera.flyTo({ - ...config, - - complete: () => { - // 旧飞行的回调不能清除新飞行状态 - if (flightStateRef.current.token !== token) return; - - flightStateRef.current.flying = false; - flightStateRef.current.priority = -1; - flightStateRef.current.key = null; - - config.complete?.(); - }, - - cancel: () => { - if (flightStateRef.current.token !== token) return; - - flightStateRef.current.flying = false; - flightStateRef.current.priority = -1; - flightStateRef.current.key = null; - - config.cancel?.(); - }, - }); - - return true; - } catch (error) { - if (flightStateRef.current.token === token) { - flightStateRef.current.flying = false; - flightStateRef.current.priority = -1; - flightStateRef.current.key = null; - } - - console.error('地图飞行失败:', error); - return false; - } - }; - function updateLiveObstacleBoxes( viewer, message, ) { + console.log(message, "障碍物信息") + return; const payload = message.data ?? message; const objects = payload.objects ?? []; @@ -404,6 +338,88 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, }); } + + const handleDetectFn = (res) => { + console.log(res, "监测到障碍物") + const viewer = viewerRef.current; + updateLiveObstacleBoxes(viewer, res); + }; + + + + + + const flyToView = (viewer, priority, config, key = '') => { + if (!viewer || viewer.isDestroyed()) return false; + + const state = flightStateRef.current; + const now = Date.now(); + + // 相同目标正在飞行,忽略重复请求 + if ( + state.flying && + state.priority === priority && + state.key === key && + now - (state.startedAt || 0) < 3000 + ) { + return false; + } + + // 仅在当前飞行尚未结束时执行优先级比较 + if (state.flying && priority < state.priority) { + return false; + } + + const token = ++state.token; + + state.priority = priority; + state.key = key; + state.startedAt = now; + state.flying = true; + + try { + viewer.camera.cancelFlight(); + + viewer.camera.flyTo({ + ...config, + + complete: () => { + // 旧飞行的回调不能清除新飞行状态 + if (flightStateRef.current.token !== token) return; + + flightStateRef.current.flying = false; + flightStateRef.current.priority = -1; + flightStateRef.current.key = null; + + config.complete?.(); + }, + + cancel: () => { + if (flightStateRef.current.token !== token) return; + + flightStateRef.current.flying = false; + flightStateRef.current.priority = -1; + flightStateRef.current.key = null; + + config.cancel?.(); + }, + }); + + return true; + } catch (error) { + if (flightStateRef.current.token === token) { + flightStateRef.current.flying = false; + flightStateRef.current.priority = -1; + flightStateRef.current.key = null; + } + + console.error('地图飞行失败:', error); + return false; + } + }; + + + const clearDrawingPath = () => { const viewer = viewerRef.current; if (!viewer) return; @@ -1626,11 +1642,11 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, ); const lat = Number(obstacle?.position?.lat); const radius = Number(obstacle?.radius ?? 2); - // 形状配置:圆形走原有半径逻辑,矩形按长宽渲染 - const shapeConfig = obstacleShapes?.[idx] || {}; - const isRect = shapeConfig.shapeType === 'rect'; - const rectWidth = Math.max(0.1, Number(shapeConfig.width) || radius * 2); - const rectHeight = Math.max(0.1, Number(shapeConfig.height) || radius * 2); + // 形状配置:圆形走原有半径逻辑,矩形按长宽渲染 + const shapeConfig = obstacleShapes?.[idx] || {}; + const isRect = shapeConfig.shapeType === 'rect'; + const rectWidth = Math.max(0.1, Number(shapeConfig.width) || radius * 2); + const rectHeight = Math.max(0.1, Number(shapeConfig.height) || radius * 2); if ( !Number.isFinite(lon) || @@ -1704,7 +1720,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, outlineColor: redColor, outlineWidth: isHighlighted ? 4 : 2, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, - } + } : undefined, // 圆心标记 @@ -1834,12 +1850,12 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, const shapeConfig = obstacleShapes?.[index] || {}; const isRect = shapeConfig.shapeType === 'rect'; const rectWidth = Math.max( - 0.1, - Number(shapeConfig.width) || radius * 2 + 0.1, + Number(shapeConfig.width) || radius * 2 ); const rectHeight = Math.max( - 0.1, - Number(shapeConfig.height) || radius * 2 + 0.1, + Number(shapeConfig.height) || radius * 2 ); draggingObstacleRef.current = { @@ -1952,20 +1968,20 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, const mouseLat = Cesium.Math.toDegrees(carto.latitude); const width = Math.max( - 0.2, - 2 * - Cesium.Cartesian3.distance( - dragging.center, - Cesium.Cartesian3.fromDegrees(mouseLon, dragging.lat, 0) - ) + 0.2, + 2 * + Cesium.Cartesian3.distance( + dragging.center, + Cesium.Cartesian3.fromDegrees(mouseLon, dragging.lat, 0) + ) ); const height = Math.max( - 0.2, - 2 * - Cesium.Cartesian3.distance( - dragging.center, - Cesium.Cartesian3.fromDegrees(dragging.lon, mouseLat, 0) - ) + 0.2, + 2 * + Cesium.Cartesian3.distance( + dragging.center, + Cesium.Cartesian3.fromDegrees(dragging.lon, mouseLat, 0) + ) ); dragging.width = width; @@ -1975,31 +1991,31 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, const rectHandle = viewer.entities.getById(dragging.handleId); if (rectEntity?.rectangle) { - rectEntity.rectangle.coordinates.setValue( - getObstacleRectCoordinates( - dragging.lon, - dragging.lat, - width, - height - ) - ); + rectEntity.rectangle.coordinates.setValue( + getObstacleRectCoordinates( + dragging.lon, + dragging.lat, + width, + height + ) + ); } if (rectHandle) { - rectHandle.position = new Cesium.ConstantPositionProperty( - getObstacleRectHandlePosition( - dragging.lon, - dragging.lat, - width, - height - ) - ); + rectHandle.position = new Cesium.ConstantPositionProperty( + getObstacleRectHandlePosition( + dragging.lon, + dragging.lat, + width, + height + ) + ); } if (rectEntity?.label) { - const obstacle = - stationOverlay.tempObstaclePoints?.[dragging.index]; - rectEntity.label.text.setValue( - `${obstacle?.alias || `障碍物点-${dragging.index + 1}`} (${width.toFixed(2)}×${height.toFixed(2)}m)` - ); + const obstacle = + stationOverlay.tempObstaclePoints?.[dragging.index]; + rectEntity.label.text.setValue( + `${obstacle?.alias || `障碍物点-${dragging.index + 1}`} (${width.toFixed(2)}×${height.toFixed(2)}m)` + ); } viewer.scene.requestRender(); @@ -2064,34 +2080,34 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, setIsDraggingObstacle(false); if (viewer) { - const ctrl = viewer.scene.screenSpaceCameraController; - ctrl.enableRotate = true; - ctrl.enableTranslate = true; - ctrl.enableZoom = true; + const ctrl = viewer.scene.screenSpaceCameraController; + ctrl.enableRotate = true; + ctrl.enableTranslate = true; + ctrl.enableZoom = true; } // 矩形:打印信息并回传长宽给父组件(暂不走圆形保存逻辑) if (dragging.shapeType === 'rect') { - const obstacle = - stationOverlay.tempObstaclePoints?.[index]; - const { width, height } = dragging; + const obstacle = + stationOverlay.tempObstaclePoints?.[index]; + const { width, height } = dragging; - logRectObstacleInfo( - obstacle, - index, - dragging.lon, - dragging.lat, - width, - height - ); + logRectObstacleInfo( + obstacle, + index, + dragging.lon, + dragging.lat, + width, + height + ); - onObstacleRectResize?.( - index, - Number(width.toFixed(2)), - Number(height.toFixed(2)) - ); - viewer?.scene.requestRender(); - return; + onObstacleRectResize?.( + index, + Number(width.toFixed(2)), + Number(height.toFixed(2)) + ); + viewer?.scene.requestRender(); + return; } // 通知父组件更新列表 @@ -3553,6 +3569,9 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, resolve(dataUrl); }); }, []); + useEffect(() => { + handleDetectFn(detectReportInfo) + }, [detectReportInfo]) // 暴露 ref 方法 useImperativeHandle(ref, () => ({ diff --git a/src/components/devices/DeviceStatusPage.tsx b/src/components/devices/DeviceStatusPage.tsx index b3298e5..f5add44 100644 --- a/src/components/devices/DeviceStatusPage.tsx +++ b/src/components/devices/DeviceStatusPage.tsx @@ -344,6 +344,7 @@ export default function DeviceStatusPage() { const controllerRef = useRef(null); const isFirstConnect = useRef(true); + const [detectReportInfo, setDeportInfo] = useState(null); // 标记本次会话是否已经发起过控制权限申请,避免手柄/方向盘高频更新时重复申请 @@ -1184,6 +1185,11 @@ export default function DeviceStatusPage() { mapRef.current?.flyToPosition?.(realtimePosition, { height: 300 }); }; + const handleDetectionReport = (res) => { + setDeportInfo(res); + console.log("获取障碍物信息", res) + + } @@ -1207,6 +1213,9 @@ export default function DeviceStatusPage() { controller.handleArrivedPoint = handleFinishEdPoint; + controller.onDetectionReport = handleDetectionReport; + + @@ -1511,6 +1520,14 @@ export default function DeviceStatusPage() { return; + } + console.log(realtimePosition?.controlMode, "现在的控制controlmode") + if (realtimePosition?.controlMode != 3 || realtimePosition?.control_mode != 3) { + + messageApi.warning(t('devices.noRemoteControl')); + + return; + } console.log('Gamepad state updated:', state); @@ -2433,6 +2450,8 @@ export default function DeviceStatusPage() { ifClearNavLine={clearNavLine} ifClearPlanLine={clearPlanLine} + detectReportInfo={detectReportInfo} + from="deviceStatus" onMarkPoint={handleMapMarkPoint} onClearDraw={(fn) => { clearDrawRef.current = fn; }} diff --git a/src/components/devices/MapEditorPage.tsx b/src/components/devices/MapEditorPage.tsx index be41e4e..b854aef 100644 --- a/src/components/devices/MapEditorPage.tsx +++ b/src/components/devices/MapEditorPage.tsx @@ -144,14 +144,11 @@ export default function MapEditorPage() { }; loadDevices(); }, [stationId]); - useEffect(() => { - console.log("siteMapInfoId state:", siteMapInfoId); - }, [siteMapInfoId]); + const getSiteMapInfoFn = () => { getSiteMapInfo({ siteId: stationId }).then((res: any) => { if (res?.code === 200 && res.data) { setSiteMapInfoId(res.data.id ?? null); - console.log(res.data.id, "res.data.id") setReturnPointConfigList(res?.data?.restPoints || []); // 同时加载已保存的障碍物点(tempObstaclePoints),方便编辑 const savedObstacles = (res?.data?.tempObstaclePoints || []).map((op: any) => ({ @@ -160,12 +157,17 @@ export default function MapEditorPage() { lat: Number(op.position?.lat ?? 0), name: op.alias || '', radius: Number(op.radius) || 2.0, + //shapeType: + // op.shapeType === 'rect' || op.shape_type === 'aabb' + // ? 'rect' + // : 'circle', + //width: Number(op.width ?? op.size?.[0]) || (Number(op.radius) || 2) * 2, + //height: Number(op.height ?? op.size?.[1]) || (Number(op.radius) || 2) * 2, })); setObstaclePointConfigList(savedObstacles); } else { setSiteMapInfoId(null); - console.log("res.data.id111") setReturnPointConfigList([]); setObstaclePointConfigList([]); @@ -173,7 +175,6 @@ export default function MapEditorPage() { } }).catch(() => { setSiteMapInfoId(null); - console.log("res.data.id112221") setReturnPointConfigList([]); setObstaclePointConfigList([]); diff --git a/src/components/devices/RobotTaskPage.tsx b/src/components/devices/RobotTaskPage.tsx index e864e48..a756848 100644 --- a/src/components/devices/RobotTaskPage.tsx +++ b/src/components/devices/RobotTaskPage.tsx @@ -72,6 +72,8 @@ export default function RobotTaskPage() { const [taskList, setTaskList] = useState([]); const { modal } = App.useApp(); const [polyPoints, setPolyPoints] = useState([]); + const [detectReportInfo, setDeportInfo] = useState(null); + @@ -281,6 +283,10 @@ export default function RobotTaskPage() { //if (isFirstConnect.current) { isFirstConnect.current = false; controllerRef.current?.connectDevice(targetDevice); } else { controllerRef.current?.switchDevice(targetDevice); } //setShowVideo(true); }; + const handleDetectionReport = (res) => { + console.log('收到障碍物物信息', res); + setDeportInfo(res); + } useEffect(() => { @@ -298,6 +304,8 @@ export default function RobotTaskPage() { controller.deviceStatusChangedMsg = () => { fetchAllData(); } + controller.onDetectionReport = handleDetectionReport; + @@ -1565,6 +1573,8 @@ export default function RobotTaskPage() { routeMode={routeMode} mapLayer={currentStation?.siteMapName} focusOverlay={focusOverlay} + detectReportInfo={detectReportInfo} + /> {/* 机器人状态悬浮面板 - 绝对定位左上角 */} diff --git a/src/components/devices/deviceController.js b/src/components/devices/deviceController.js index 16d4844..aa889f9 100644 --- a/src/components/devices/deviceController.js +++ b/src/components/devices/deviceController.js @@ -47,6 +47,7 @@ export default class DeviceController { this.onIsFinished = null; this.onIsExecuting = null; this.handleArrivedPoint = null; + this.onDetectionReport = null; // 全量设备实时状态(mapPush)连接 this.mapPushWs = null; @@ -167,6 +168,23 @@ export default class DeviceController { console.log('route_post'); this.onRoutePost?.(msg); } + if (msg?.type == 'detectionReport') { + console.log('detectionReport'); + this.onDetectionReport?.(msg); + } + + // case 'detectionReport': + //const { isSecure, obstacle } = msg.data; + //if (isSecure) return; + //const type = obstacle?.type; + //const distance = (obstacle?.distance || 0).toFixed(2); + //const types = { 0: i18n.t('constants.locationUnknown'), 1: i18n.t('devices.obstaclePerson'), 2: i18n.t('devices.obstacleVehicle'), 3: i18n.t('devices.obstacleFence'), 4: i18n.t('devices.obstaclePothole'), 5: i18n.t('devices.obstacleGrass') }; + //this.messageApi.warning({ + // key: 'obstacle-warning', + // content: i18n.t('devices.obstacleDetectedReport', { obstacle: types[type] ?? i18n.t('devices.unknownObject'), distance }), + // duration: 3, + //}); + //break; @@ -527,10 +545,11 @@ export default class DeviceController { this.deviceStatusChangedMsg?.(msg); break; - case 'remoteControl': - + case 'detectionReport': + this.onDetectionReport?.(msg); break; + default: break; } diff --git a/src/locales/en/index.ts b/src/locales/en/index.ts index b6c3c0b..5a6525d 100644 --- a/src/locales/en/index.ts +++ b/src/locales/en/index.ts @@ -1451,6 +1451,8 @@ cutterSpedd: 'cutterSpedd', controlOff: 'controlOff', localCpntrol: 'localCpntrol', + noRemoteControl: "no RemoteControl Mode", + autoTask: 'autoTask', manualTask: 'manualTask', manualControl: 'manualControl', diff --git a/src/locales/zh/index.ts b/src/locales/zh/index.ts index 0b985ec..08a8f45 100644 --- a/src/locales/zh/index.ts +++ b/src/locales/zh/index.ts @@ -394,6 +394,7 @@ const zh = { timelineMaintenanceDetail: '所有割草机返回充电站', autoGenerateTodayPlan: '智能生成今日计划', deviceEnvironment: '设备环境与状态', + noRemoteControl: "非远程控制模式", currentTemp: '当前温度', humidity: '环境湿度', positionAccuracy: '定位精度',