From a73ebc1bf463f76626578796bec5b77138098141 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Wed, 8 Jul 2026 09:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=20=E6=97=A0=E4=BA=BA=E6=9C=BA=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E9=9F=A9=20=E5=BB=BA=E8=AE=AE=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/devices/DeviceStatusPage.tsx | 438 ++++++++++---------- src/components/devices/DroneVideoPlayer.tsx | 141 ++++++- 2 files changed, 339 insertions(+), 240 deletions(-) diff --git a/src/components/devices/DeviceStatusPage.tsx b/src/components/devices/DeviceStatusPage.tsx index 4513694..17913f9 100644 --- a/src/components/devices/DeviceStatusPage.tsx +++ b/src/components/devices/DeviceStatusPage.tsx @@ -883,229 +883,225 @@ export default function DeviceStatusPage({ - - - - - 实时视频监控 - - } - //extra={ - // - //} - bordered={false} - style={{ borderRadius: 12, marginBottom: 8 }} - bodyStyle={{ padding: 12 }} - > - {!isUAV && ( + {/* 无人机专用布局 */} + {isUAV ? ( + + {/* 左侧:机场视频 + 地图 */} + + {/* 无人机场视频 + 机场状态 */} + + + 无人机场视频 + + } + bordered={false} + style={{ borderRadius: 12, marginBottom: 8 }} + bodyStyle={{ padding: 12 }} + > +
+ +
+
+ + {/* 地图 */} + + + 位置态势图 + + } + extra={ + + + + + } + bordered={false} + style={{ borderRadius: 12 }} + bodyStyle={{ padding: 12, height: 400 }} + > + + + + + {/* 右侧:无人机视频 + 无人机状态 */} + + {/* 无人机视频 + 无人机状态 */} + + + 无人机视频 + + } + bordered={false} + style={{ borderRadius: 12, marginBottom: 8 }} + bodyStyle={{ padding: 12 }} + > +
+ +
+
+ +
+ ) : ( + // 机器人原布局 + + + + + 实时视频监控 + + } + bordered={false} + style={{ borderRadius: 12, marginBottom: 8 }} + bodyStyle={{ padding: 12 }} + > - {/**/} - )} -
- {isUAV ? ( - - ) : robotVideo ? ( - // 全景模式 = T 型排布 - mowerView === 'all' ? ( - +
+ {robotVideo ? ( + mowerView === 'all' ? ( + + ) : ( + + ) ) : ( - // 单画面模式 - - ) - ) : ( -
- 视频加载中... -
- )} -
- +
视频加载中...
+ )} +
+
- - - 位置态势图 - - } - extra={ - - - - - } - bordered={false} - style={{ borderRadius: 12 }} - bodyStyle={{ - padding: 12, - height: 400, - }} - > - - - + + + 位置态势图 + + } + extra={ + + + + + } + bordered={false} + style={{ borderRadius: 12 }} + bodyStyle={{ padding: 12, height: 400 }} + > + + + - - {isUAV ? '无人机状态' : '机器人状态'}详情} - bordered={false} - style={{ borderRadius: 12, marginBottom: 8 }} - extra={{device.onlineStatus === 1 ? '在线' : '离线'}} - > - {isUAV ? ( - - 电池电量}> - - - 飞行高度}> - {fix2((currentDroneData || uavState || device).height)} m - - - {fix2(currentDroneData?.horizontal_speed) || '-'} m/s - - - {fix2(currentDroneData?.vertical_speed) || '-'} m/s - - - {fix2((currentDroneData || uavState || device).wind_speed)} m/s - - - {fix2((currentDroneData || uavState || device).environment_temperature)} ℃ - - - {(currentDroneData?.humidity) || '-'}{currentDroneData?.humidity ? '%' : ''} - - - {fix2(currentDroneData?.temperature)} ℃ - - - {getVal((currentDroneData || uavState || device).rainfall)} - - - - {fix2(currentDroneData?.heading)}° - - - - {currentDroneData?.mode_code !== undefined ? `模式 ${currentDroneData.mode_code}` : '-'} - - - - - - {currentDroneData?.drone_in_dock === 1 ? '在库' : '外出'} - - - - - {currentDroneData?.cover_state === 1 ? '舱门打开' : '舱门关闭'} - - - - - {currentDroneData?.air_conditioner_state === 1 ? '开启' : '关闭'} - - - - - - - - - - - {(currentDroneData || uavState || device).position_state?.is_fixed === 2 || (currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'} - - - - - {currentDroneData?.latitude && currentDroneData?.longitude ? - `${currentDroneData.latitude.toFixed(6)}, ${currentDroneData.longitude.toFixed(6)}` : '-'} - - - - ) : ( + + 机器人状态详情} + bordered={false} + style={{ borderRadius: 12, marginBottom: 8 }} + extra={{device.onlineStatus === 1 ? '在线' : '离线'}} + > 电池电量}> @@ -1122,8 +1118,6 @@ export default function DeviceStatusPage({ {fix2(runningStatus?.chipTemp)} ℃ {(runningStatus?.headingStatus == 1 ? "已初始化" : "未初始化")} {(runningStatus?.controlMode == 1 ? "本地模式" : runningStatus?.controlMode == 3 ? "远程模式" : "控制模式")} - - {runningStatus?.qual == 0 @@ -1145,9 +1139,8 @@ export default function DeviceStatusPage({ {fix2(runningStatus?.yaw)}° {fix2(runningStatus?.pitch)}° - )} - - {!isUAV && ( + + @@ -1156,10 +1149,7 @@ export default function DeviceStatusPage({ } bordered={false} - style={{ - borderRadius: 12, - background: '#0f172a', - }} + style={{ borderRadius: 12, background: '#0f172a' }} headStyle={{ color: '#fff' }} bodyStyle={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }} > @@ -1171,9 +1161,9 @@ export default function DeviceStatusPage({ isConnecting={connecting} /> - )} - -
+ +
+ )} void; + // 新增:状态数据 + statusData?: { + [key: string]: any; + }; + // 新增:显示类型(用于区分显示机场状态还是无人机状态) + displayType?: 'station' | 'drone'; } const DroneVideoPlayer: React.FC = ({ device, - height = 160, showSourceSelect = true, dualVideo = false, defaultSource = 'drone', videoSource: propsVideoSource, - onSourceChange + onSourceChange, + statusData, + displayType }) => { const [internalVideoSource, setInternalVideoSource] = useState<'station' | 'drone'>(defaultSource); const videoSource = propsVideoSource !== undefined ? propsVideoSource : internalVideoSource; @@ -125,6 +132,15 @@ const DroneVideoPlayer: React.FC = ({ const prevRef = useRef({ selectedCamera: '', selectedLens: '', + deviceSn: '', + gatewaySn: '', + videoSource: '' + }); + + // 记住是否已经加载过,避免重复加载 + const hasLoadedRef = useRef({ + station: false, + drone: false }); useEffect(() => { @@ -133,37 +149,69 @@ const DroneVideoPlayer: React.FC = ({ const prev = prevRef.current; const currentCamera = selectedCamera; const currentLens = selectedLens; + const currentDeviceSn = device?.device_sn || ''; + const currentGatewaySn = device?.gateway_sn || ''; + const currentVideoSource = videoSource; // 双画面:只刷新【真正变化】的那一路,另一路不动 if (dualVideo) { - // 只有【机场摄像头】变化了,才刷新机场 - if (currentCamera !== prev.selectedCamera) { + // 只有【机场摄像头】或设备变化了,才刷新机场 + const stationChanged = currentCamera !== prev.selectedCamera || currentGatewaySn !== prev.gatewaySn; + if (stationChanged || !hasLoadedRef.current.station) { setStationStreamData(null); loadStationCamera(currentCamera); + hasLoadedRef.current.station = true; } - // 只有【无人机镜头】变化了,才刷新无人机 - if (currentLens !== prev.selectedLens) { + // 只有【无人机镜头】或设备变化了,才刷新无人机 + const droneChanged = currentLens !== prev.selectedLens || currentDeviceSn !== prev.deviceSn; + if (droneChanged || !hasLoadedRef.current.drone) { setDroneStreamData(null); loadDroneLens(currentLens); + hasLoadedRef.current.drone = true; } // 保存最新值,供下一次对比 prevRef.current = { selectedCamera: currentCamera, selectedLens: currentLens, + deviceSn: currentDeviceSn, + gatewaySn: currentGatewaySn, + videoSource: currentVideoSource }; return; } - // 单画面:保持原有逻辑 + // 单画面:只在真正变化时才重新加载 + const sourceChanged = currentVideoSource !== prev.videoSource; + const deviceChanged = currentDeviceSn !== prev.deviceSn || currentGatewaySn !== prev.gatewaySn; + const lensChanged = currentLens !== prev.selectedLens; + const cameraChanged = currentCamera !== prev.selectedCamera; + if (videoSource === 'station') { - setStationStreamData(null); - loadStationCamera(currentCamera); + if ((sourceChanged || cameraChanged || deviceChanged) || !hasLoadedRef.current.station) { + setStationStreamData(null); + loadStationCamera(currentCamera); + hasLoadedRef.current.station = true; + hasLoadedRef.current.drone = false; // 重置另一边的加载状态 + } } else { - setDroneStreamData(null); - loadDroneLens(currentLens); + if ((sourceChanged || lensChanged || deviceChanged) || !hasLoadedRef.current.drone) { + setDroneStreamData(null); + loadDroneLens(currentLens); + hasLoadedRef.current.drone = true; + hasLoadedRef.current.station = false; // 重置另一边的加载状态 + } } + + // 保存最新值,供下一次对比 + prevRef.current = { + selectedCamera: currentCamera, + selectedLens: currentLens, + deviceSn: currentDeviceSn, + gatewaySn: currentGatewaySn, + videoSource: currentVideoSource + }; }, [ device, videoSource, @@ -179,8 +227,17 @@ const DroneVideoPlayer: React.FC = ({ value: idx, })) || []; + // 格式化数字 + const formatNumber = (num: any, decimals = 2) => { + if (num === null || num === undefined || isNaN(num)) return '-'; + return Number(num).toFixed(decimals); + }; + const renderVideo = (type: 'drone' | 'station', streamData: any, loading: boolean) => { const isDrone = type === 'drone'; + const currentDisplayType = displayType || type; + const data = statusData; + return (
= ({
)} + {/* 状态详情叠加层 - 左上角 */} + {data && ( +
+ {currentDisplayType === 'station' ? ( + <> +
机场状态
+
+ 温度:{formatNumber(data.temperature || data.environment_temperature)}°C + 湿度:{data.humidity !== undefined ? `${data.humidity}%` : '-'} + 风速:{formatNumber(data.wind_speed)}m/s + 降雨: + {data.rainfall === 'no_rain' || data.rainfall === 0 ? '无' : '有'} + + 机库: + {data.cover_state === 1 || data.cover_state === 'open' ? '已开' : '已关'} + + 无人机: + {data.drone_in_dock === 1 || data.drone_in_dock === true ? '在库' : '外出'} + +
+ + ) : ( + <> +
无人机状态
+
+ 电量: + {data.capacity_percent !== undefined ? `${data.capacity_percent}%` : '-'} + + 高度:{formatNumber(data.height)}m + 水平速度:{formatNumber(data.horizontal_speed)}m/s + 垂直速度:{formatNumber(data.vertical_speed)}m/s + 航向角:{formatNumber(data.heading)}° + GPS:{data.position_state?.gps_number || 0}颗 + RTK: + {data.position_state?.is_fixed === 2 || data.position_state?.is_fixed === 'fixing_successful' ? '已固定' : '未固定'} + +
+ + )} +
+ )} - {/* 底部信息叠加 */} - {isDrone && device && ( + {/* 底部信息叠加 - 显示经纬度 */} + {data && data.latitude !== undefined && data.longitude !== undefined && (
= ({ background: 'rgba(0,0,0,0.6)', color: '#fff', display: 'flex', - justifyContent: 'space-between', + justifyContent: 'center', padding: '4px 8px', fontSize: 10 }}> - {/*高度 {Number(device?.height)?.toFixed(2) || '-'}m - 风速 {Number(device?.wind_speed?.toFixed(2) || '0')}m/s*/} + 位置: {formatNumber(data.latitude, 6)}, {formatNumber(data.longitude, 6)}
)}