From 68ebde55a4ed2dc70258bf212361afa61cb8b82f Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Thu, 19 Jun 2025 13:48:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=9C=B0=E5=9B=BE=E4=BB=AA=E8=A1=A8?= =?UTF-8?q?=E7=9B=98=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/device-ops/map-dashboard/index.tsx | 452 +++++++++++++++--- 1 file changed, 391 insertions(+), 61 deletions(-) diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device-ops/map-dashboard/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device-ops/map-dashboard/index.tsx index dc52df80..478b2a3d 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/device-ops/map-dashboard/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/device-ops/map-dashboard/index.tsx @@ -87,6 +87,23 @@ interface RealDevice { lastMaintenance: string; nextMaintenance: string; modeCode: number; + emergencyStopState: number; + alarmState: number; + // 新增官方协议字段 + putterState: number; + coverState: number; + silentMode: number; + supplementLightState: number; + batteryStoreMode: number; + homePositionIsValid: number; + safeLandHeight: number; + isAlternateConfigured: number; + airConditionerState: number; + switchTime: number; + devicePaired: number; + subDeviceSn: string; + deviceOnlineStatus: number; + firstPowerOn: number; }; airportStatus?: { flightTaskStep: number; @@ -252,6 +269,9 @@ const DeviceMapDashboard: React.FC = () => { const markersRef = useRef>(new Map()); const mapContainerRef = useRef(null); + // 全局鼠标位置跟踪 + const [globalMousePosition, setGlobalMousePosition] = useState<{ x: number; y: number }>({ x: 0, y: 0 }); + // WebSocket相关 const wsRef = useRef(null); const [wsConnected, setWsConnected] = useState(false); @@ -369,6 +389,23 @@ const DeviceMapDashboard: React.FC = () => { lastMaintenance: '', nextMaintenance: '', modeCode: 0, + emergencyStopState: 0, + alarmState: 0, + // 新增官方协议字段 + putterState: 0, + coverState: 0, + silentMode: 0, + supplementLightState: 0, + batteryStoreMode: 0, + homePositionIsValid: 0, + safeLandHeight: 0, + isAlternateConfigured: 0, + airConditionerState: 0, + switchTime: 0, + devicePaired: 0, + subDeviceSn: '', + deviceOnlineStatus: 0, + firstPowerOn: 0, } }))); } else { @@ -396,8 +433,13 @@ const DeviceMapDashboard: React.FC = () => { if (!hasRecentData) return DeviceStatus.OFFLINE; - // 检查告警状态 - if (device.metrics.errorCount > 0 || device.metrics.warningCount > 0) { + // 检查紧急停止状态 + if (device.metrics.emergencyStopState === 1) { + return DeviceStatus.ERROR; + } + + // 检查报警状态 + if (device.metrics.alarmState === 1) { return DeviceStatus.ERROR; } @@ -411,12 +453,27 @@ const DeviceMapDashboard: React.FC = () => { return DeviceStatus.MAINTENANCE; } + // 检查定位质量 + if (device.metrics.positionQuality < 3) { + return DeviceStatus.MAINTENANCE; + } + + // 检查环境条件(风速过大) + if (device.metrics.windSpeed > 10) { + return DeviceStatus.MAINTENANCE; + } + + // 检查降雨状态 + if (device.metrics.rainfall > 0) { + return DeviceStatus.MAINTENANCE; + } + // 检查无人机是否在机库中 if (device.metrics.droneInDock === 1) { return DeviceStatus.STANDBY; } - // 检查模式代码(飞行任务) + // 检查工作模式代码(飞行任务) if (device.metrics.modeCode > 0) { return DeviceStatus.TASK; } @@ -533,6 +590,23 @@ const DeviceMapDashboard: React.FC = () => { lastMaintenance: device.lastMaintenance || '', nextMaintenance: device.nextMaintenance || '', modeCode: 0, + emergencyStopState: 0, + alarmState: 0, + // 新增官方协议字段 + putterState: 0, + coverState: 0, + silentMode: 0, + supplementLightState: 0, + batteryStoreMode: 0, + homePositionIsValid: 0, + safeLandHeight: 0, + isAlternateConfigured: 0, + airConditionerState: 0, + switchTime: 0, + devicePaired: 0, + subDeviceSn: '', + deviceOnlineStatus: 0, + firstPowerOn: 0, } })); }; @@ -555,9 +629,18 @@ const DeviceMapDashboard: React.FC = () => { // 处理设备悬停 const handleDeviceHover = (device: RealDevice, event: React.MouseEvent) => { + // 使用全局鼠标位置或事件位置 + const mouseX = globalMousePosition.x || event.clientX; + const mouseY = globalMousePosition.y || event.clientY; + + console.log('handleDeviceHover - 鼠标位置:', { mouseX, mouseY }); + + // 使用智能定位 + const smartPosition = getSmartCardPosition(mouseX, mouseY); + setHoveredDevice(device); setShowDeviceCard(true); - setDeviceCardPosition({ x: event.clientX, y: event.clientY }); + setDeviceCardPosition(smartPosition); }; // 处理设备离开 @@ -611,6 +694,9 @@ const DeviceMapDashboard: React.FC = () => { // 刷新设备数据 const handleRefresh = () => { setLoading(true); + // 清除所有现有标记 + clearAllMarkers(); + setTimeout(() => { const newDevices = generateMockDevices(); setDevices(convertMockDevicesToRealDevices(newDevices)); @@ -624,6 +710,13 @@ const DeviceMapDashboard: React.FC = () => { fetchDeviceList(); initWebSocket(); + // 添加全局鼠标移动监听器 + const handleGlobalMouseMove = (event: MouseEvent) => { + setGlobalMousePosition({ x: event.clientX, y: event.clientY }); + }; + + document.addEventListener('mousemove', handleGlobalMouseMove); + return () => { if (wsRef.current) { wsRef.current.close(); @@ -637,6 +730,7 @@ const DeviceMapDashboard: React.FC = () => { if (tokenCache.timer) { clearTimeout(tokenCache.timer); } + document.removeEventListener('mousemove', handleGlobalMouseMove); }; }, []); @@ -811,7 +905,7 @@ const DeviceMapDashboard: React.FC = () => { // 清除不存在的标记 currentMarkers.forEach((marker, deviceSn) => { if (!newMarkers.find(m => m.device.deviceSn === deviceSn)) { - marker.remove(); + safeRemoveMarker(marker); currentMarkers.delete(deviceSn); } }); @@ -823,45 +917,27 @@ const DeviceMapDashboard: React.FC = () => { if (existingMarker) { // 更新现有标记 - existingMarker.setPosition(position); - existingMarker.setIcon({ - type: 'image', - image: createMarkerIcon(color, status), - size: [32, 32], - anchor: 'bottom-center' - }); + try { + if (typeof existingMarker.setPosition === 'function') { + existingMarker.setPosition(position); + } + if (typeof existingMarker.setIcon === 'function') { + existingMarker.setIcon({ + type: 'image', + image: createMarkerIcon(color, status), + size: [32, 32], + anchor: 'bottom-center' + }); + } + } catch (error) { + console.warn('更新标记失败:', error); + } } else { // 创建新标记 - const newMarker = new window.AMap.Marker({ - position, - icon: { - type: 'image', - image: createMarkerIcon(color, status), - size: [32, 32], - anchor: 'bottom-center' - }, - offset: [0, -16], - title: `${device.deviceName} (${DEVICE_STATUS_CONFIG[status].text})` - }); - - // 添加点击事件 - newMarker.on('click', () => { - handleDeviceClick(device, {} as React.MouseEvent); - }); - - // 添加鼠标事件 - newMarker.on('mouseover', () => { - setHoveredDevice(device); - setShowDeviceCard(true); - }); - - newMarker.on('mouseout', () => { - setHoveredDevice(null); - setShowDeviceCard(false); - }); - - newMarker.setMap(mapRef.current); - currentMarkers.set(device.deviceSn, newMarker); + const newMarker = safeCreateMarker(device, position, color, status); + if (newMarker) { + currentMarkers.set(device.deviceSn, newMarker); + } } }); }, [devices, mapMarkers]); @@ -1013,6 +1089,7 @@ const DeviceMapDashboard: React.FC = () => { const isFixed = eventData.position_state?.is_fixed || 0; const rtkNumber = eventData.position_state?.rtk_number || 0; const gpsNumber = eventData.position_state?.gps_number || 0; + const isCalibration = eventData.position_state?.is_calibration || 0; // 提取网络信息 const networkQuality = eventData.network_state?.quality || 0; @@ -1023,14 +1100,36 @@ const DeviceMapDashboard: React.FC = () => { const droneInDock = eventData.drone_in_dock || 0; const modeCode = eventData.mode_code || 0; - // 提取存储信息 - const storageTotal = eventData.storage?.total || 0; - const storageUsed = eventData.storage?.used || 0; - const diskUsage = storageTotal > 0 ? (storageUsed / storageTotal) * 100 : 0; - - // 提取告警状态 - const alarmState = eventData.alarm_state || 0; + // 提取设备部件状态 + const putterState = eventData.putter_state || 0; + const coverState = eventData.cover_state || 0; + const silentMode = eventData.silent_mode || 0; + const supplementLightState = eventData.supplement_light_state || 0; const emergencyStopState = eventData.emergency_stop_state || 0; + const batteryStoreMode = eventData.battery_store_mode || 0; + const homePositionIsValid = eventData.home_position_is_valid || 0; + + // 提取备用降落点信息 + const alternateLandPoint = eventData.alternate_land_point; + const safeLandHeight = alternateLandPoint?.safe_land_height || 0; + const isAlternateConfigured = alternateLandPoint?.is_configured || 0; + + // 提取空调状态 + const airConditioner = eventData.air_conditioner; + const airConditionerState = airConditioner?.air_conditioner_state || 0; + const switchTime = airConditioner?.switch_time || 0; + + // 提取子设备信息 + const subDevice = eventData.sub_device; + const devicePaired = subDevice?.device_paired || 0; + const subDeviceSn = subDevice?.device_sn || ''; + const deviceOnlineStatus = subDevice?.device_online_status || 0; + + // 提取报警状态 + const alarmState = eventData.alarm_state || 0; + + // 提取首次开机时间 + const firstPowerOn = eventData.first_power_on || 0; setDevices(prevDevices => prevDevices.map(device => @@ -1058,17 +1157,34 @@ const DeviceMapDashboard: React.FC = () => { // 无人机状态 droneInDock, modeCode, - // 存储数据 - diskUsage, - // 告警状态 - errorCount: alarmState > 0 ? (device.metrics.errorCount || 0) + 1 : device.metrics.errorCount || 0, - warningCount: emergencyStopState > 0 ? (device.metrics.warningCount || 0) + 1 : device.metrics.warningCount || 0, + // 设备部件状态 + putterState, + coverState, + silentMode, + supplementLightState, + emergencyStopState, + batteryStoreMode, + homePositionIsValid, + // 备用降落点 + safeLandHeight, + isAlternateConfigured, + // 空调状态 + airConditionerState, + switchTime, + // 子设备状态 + devicePaired, + subDeviceSn, + deviceOnlineStatus, + // 报警状态 + alarmState, + // 首次开机时间 + firstPowerOn, // 信号强度(基于网络质量) signalStrength: networkQuality, // 数据速率(基于网络速率) dataRate: networkRate, // 更新时间 - uptime: Date.now() - (eventData.first_power_on || Date.now()) + uptime: firstPowerOn > 0 ? Date.now() - firstPowerOn : 0 }, lastUpdateTime: new Date().toISOString() } @@ -1083,7 +1199,10 @@ const DeviceMapDashboard: React.FC = () => { humidity, positionQuality, networkQuality, - droneInDock + droneInDock, + emergencyStopState, + alarmState, + modeCode }); }; @@ -1430,6 +1549,117 @@ const DeviceMapDashboard: React.FC = () => { return false; }; + // 安全的地图标记管理方法 + const safeRemoveMarker = (marker: any) => { + try { + if (typeof marker.remove === 'function') { + marker.remove(); + return true; + } else if (typeof marker.setMap === 'function') { + marker.setMap(null); + return true; + } else if (typeof marker.destroy === 'function') { + marker.destroy(); + return true; + } else { + console.warn('无法移除标记,方法不可用'); + return false; + } + } catch (error) { + console.warn('移除标记失败:', error); + return false; + } + }; + + // 智能定位悬停卡片 + const getSmartCardPosition = (mouseX: number, mouseY: number) => { + const cardWidth = 280; + const cardHeight = 200; + const padding = 20; + + let left = mouseX + 10; + let top = mouseY - 10; + + // 检查右边界 + if (left + cardWidth > window.innerWidth - padding) { + left = mouseX - cardWidth - 10; + } + + // 检查下边界 + if (top + cardHeight > window.innerHeight - padding) { + top = mouseY - cardHeight - 10; + } + + // 确保不超出左边界和上边界 + left = Math.max(padding, left); + top = Math.max(padding, top); + + return { x: left, y: top }; + }; + + const safeCreateMarker = (device: RealDevice, position: [number, number], color: string, status: DeviceStatus) => { + try { + const newMarker = new window.AMap.CircleMarker({ + center: position, + radius: 8, + fillColor: color, + fillOpacity: 0.8, + strokeColor: '#fff', + strokeWeight: 2, + strokeOpacity: 1, + title: `${device.deviceName} (${DEVICE_STATUS_CONFIG[status].text})` + }); + + // 添加点击事件 + if (typeof newMarker.on === 'function') { + newMarker.on('click', () => { + handleDeviceClick(device, {} as React.MouseEvent); + }); + + newMarker.on('mouseover', (event: any) => { + console.log('地图标记mouseover事件:', event); + console.log('全局鼠标位置:', globalMousePosition); + + // 使用全局鼠标位置 + const mouseX = globalMousePosition.x; + const mouseY = globalMousePosition.y; + + console.log('使用的鼠标位置:', { mouseX, mouseY }); + + // 使用智能定位 + const smartPosition = getSmartCardPosition(mouseX, mouseY); + console.log('智能定位结果:', smartPosition); + + setHoveredDevice(device); + setShowDeviceCard(true); + setDeviceCardPosition(smartPosition); + }); + + newMarker.on('mouseout', () => { + setHoveredDevice(null); + setShowDeviceCard(false); + }); + } + + if (typeof newMarker.setMap === 'function') { + newMarker.setMap(mapRef.current); + } + + return newMarker; + } catch (error) { + console.warn('创建标记失败:', error); + return null; + } + }; + + const clearAllMarkers = () => { + const currentMarkers = markersRef.current; + currentMarkers.forEach((marker) => { + safeRemoveMarker(marker); + }); + currentMarkers.clear(); + }; + return (
{/* 顶部控制栏 */} @@ -1568,6 +1798,20 @@ const DeviceMapDashboard: React.FC = () => { 检查地图 + +