设备状态界面 无人机布局根据韩 建议优化
This commit is contained in:
@@ -883,229 +883,225 @@ export default function DeviceStatusPage({
|
||||
|
||||
</div>
|
||||
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24} lg={16}>
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
实时视频监控
|
||||
</>
|
||||
}
|
||||
//extra={
|
||||
// <Button
|
||||
// size="small"
|
||||
// onClick={() => {
|
||||
// // 取当前选中设备编号,执行设备切换/刷新逻辑
|
||||
// const currentSn = device?.device_sn || device?.serialNumber;
|
||||
// console.log('currentSn', currentSn);
|
||||
// onDeviceChange?.(currentSn);
|
||||
// }}
|
||||
// >
|
||||
// 刷新
|
||||
// </Button>
|
||||
//}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12, marginBottom: 8 }}
|
||||
bodyStyle={{ padding: 12 }}
|
||||
>
|
||||
{!isUAV && (
|
||||
{/* 无人机专用布局 */}
|
||||
{isUAV ? (
|
||||
<Row gutter={[16, 16]} align="stretch">
|
||||
{/* 左侧:机场视频 + 地图 */}
|
||||
<Col xs={24} lg={8}>
|
||||
{/* 无人机场视频 + 机场状态 */}
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
无人机场视频
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12, marginBottom: 8 }}
|
||||
bodyStyle={{ padding: 12 }}
|
||||
>
|
||||
<div style={{ borderRadius: 8, overflow: 'hidden', height: 300 }}>
|
||||
<DroneVideoPlayer
|
||||
device={realtimeDevice}
|
||||
height={300}
|
||||
dualVideo={false}
|
||||
showSourceSelect={false}
|
||||
videoSource="station"
|
||||
statusData={{ ...persistentHostData, ...uavState }}
|
||||
displayType="station"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 地图 */}
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<GlobalOutlined />
|
||||
位置态势图
|
||||
</>
|
||||
}
|
||||
extra={
|
||||
<Space size={4}>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => setClearNavLine((v) => v + 1)}
|
||||
>
|
||||
清空实时轨迹
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => {
|
||||
setPoints([]);
|
||||
setClearPlanLine((v) => v + 1);
|
||||
}}
|
||||
>
|
||||
清空规划航线
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12 }}
|
||||
bodyStyle={{ padding: 12, height: 400 }}
|
||||
>
|
||||
<CesiumMap
|
||||
ref={mapRef}
|
||||
devices={[mapDevices]}
|
||||
points={points}
|
||||
markedPoints={markedPoints}
|
||||
realtimePosition={realtimePosition}
|
||||
realtimeType={realtimeType}
|
||||
drawRealTime={true}
|
||||
finishPoint={arrivedPoint}
|
||||
ifClearNavLine={clearNavLine}
|
||||
ifClearPlanLine={clearPlanLine}
|
||||
from="deviceStatus"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 右侧:无人机视频 + 无人机状态 */}
|
||||
<Col xs={24} lg={16}>
|
||||
{/* 无人机视频 + 无人机状态 */}
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
无人机视频
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12, marginBottom: 8 }}
|
||||
bodyStyle={{ padding: 12 }}
|
||||
>
|
||||
<div style={{ borderRadius: 8, overflow: 'hidden', height: "100%" }}>
|
||||
<DroneVideoPlayer
|
||||
device={realtimeDevice}
|
||||
height={760}
|
||||
dualVideo={false}
|
||||
showSourceSelect={false}
|
||||
videoSource="drone"
|
||||
statusData={{ ...persistentDroneData, ...uavState }}
|
||||
displayType="drone"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
) : (
|
||||
// 机器人原布局
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24} lg={16}>
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
实时视频监控
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12, marginBottom: 8 }}
|
||||
bodyStyle={{ padding: 12 }}
|
||||
>
|
||||
<Space style={{ marginBottom: 8 }}>
|
||||
<Button type={mowerView === 'front' ? 'primary' : 'default'} onClick={() => setMowerView('front')}>前视</Button>
|
||||
<Button type={mowerView === 'back' ? 'primary' : 'default'} onClick={() => setMowerView('back')}>后视</Button>
|
||||
<Button type={mowerView === 'left' ? 'primary' : 'default'} onClick={() => setMowerView('left')}>左视</Button>
|
||||
<Button type={mowerView === 'right' ? 'primary' : 'default'} onClick={() => setMowerView('right')}>右视</Button>
|
||||
{/*<Button type={mowerView === 'top' ? 'primary' : 'default'} onClick={() => setMowerView('top')}>顶视</Button>*/}
|
||||
<Button type={mowerView === 'all' ? 'primary' : 'default'} onClick={() => setMowerView('all')}>全景</Button>
|
||||
</Space>
|
||||
)}
|
||||
|
||||
<div
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
overflow: 'hidden',
|
||||
display: 'flex',
|
||||
// flexWrap: 'wrap', // 左右排布不换行
|
||||
}}
|
||||
>
|
||||
{isUAV ? (
|
||||
<DroneVideoPlayer
|
||||
device={realtimeDevice}
|
||||
|
||||
height={450}
|
||||
|
||||
dualVideo={true}
|
||||
showSourceSelect={false}
|
||||
defaultSource="drone"
|
||||
/>
|
||||
) : robotVideo ? (
|
||||
// 全景模式 = T 型排布
|
||||
mowerView === 'all' ? (
|
||||
<MowerAllView
|
||||
serialNumber={serialNumber}
|
||||
robotVideo={robotVideo}
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
<div style={{ borderRadius: 8, overflow: 'hidden', display: 'flex' }}>
|
||||
{robotVideo ? (
|
||||
mowerView === 'all' ? (
|
||||
<MowerAllView
|
||||
serialNumber={serialNumber}
|
||||
robotVideo={robotVideo}
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
) : (
|
||||
<VideoPlayer
|
||||
deviceId={serialNumber}
|
||||
idx={
|
||||
mowerView === 'front' ? 1
|
||||
: mowerView === 'back' ? 2
|
||||
: mowerView === 'left' ? 3
|
||||
: 4
|
||||
}
|
||||
className="w-full h-full object-contain"
|
||||
video={robotVideo}
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
// 单画面模式
|
||||
<VideoPlayer
|
||||
deviceId={serialNumber}
|
||||
idx={
|
||||
mowerView === 'front' ? 1
|
||||
: mowerView === 'back' ? 2
|
||||
: mowerView === 'left' ? 3
|
||||
: 4
|
||||
}
|
||||
className="w-full h-full object-contain"
|
||||
video={robotVideo}
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<div style={{ color: '#ccc', margin: 'auto' }}>
|
||||
视频加载中...
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
<div style={{ color: '#ccc', margin: 'auto' }}>视频加载中...</div>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<GlobalOutlined />
|
||||
位置态势图
|
||||
</>
|
||||
}
|
||||
extra={
|
||||
<Space size={4}>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => {
|
||||
setClearNavLine((v) => v + 1);
|
||||
}}
|
||||
>
|
||||
清空实时轨迹
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => {
|
||||
setPoints([]);
|
||||
setClearPlanLine((v) => v + 1);
|
||||
}}
|
||||
>
|
||||
清空规划航线
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12 }}
|
||||
bodyStyle={{
|
||||
padding: 12,
|
||||
height: 400,
|
||||
}}
|
||||
>
|
||||
<CesiumMap
|
||||
ref={mapRef}
|
||||
devices={[mapDevices]}
|
||||
points={points}
|
||||
markedPoints={markedPoints}
|
||||
realtimePosition={realtimePosition}
|
||||
realtimeType={realtimeType}
|
||||
drawRealTime={true}
|
||||
finishPoint={arrivedPoint}
|
||||
ifClearNavLine={clearNavLine}
|
||||
ifClearPlanLine={clearPlanLine}
|
||||
from="deviceStatus"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<GlobalOutlined />
|
||||
位置态势图
|
||||
</>
|
||||
}
|
||||
extra={
|
||||
<Space size={4}>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => setClearNavLine((v) => v + 1)}
|
||||
>
|
||||
清空实时轨迹
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => {
|
||||
setPoints([]);
|
||||
setClearPlanLine((v) => v + 1);
|
||||
}}
|
||||
>
|
||||
清空规划航线
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12 }}
|
||||
bodyStyle={{ padding: 12, height: 400 }}
|
||||
>
|
||||
<CesiumMap
|
||||
ref={mapRef}
|
||||
devices={[mapDevices]}
|
||||
points={points}
|
||||
markedPoints={markedPoints}
|
||||
realtimePosition={realtimePosition}
|
||||
realtimeType={realtimeType}
|
||||
drawRealTime={true}
|
||||
finishPoint={arrivedPoint}
|
||||
ifClearNavLine={clearNavLine}
|
||||
ifClearPlanLine={clearPlanLine}
|
||||
from="deviceStatus"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} lg={8}>
|
||||
<Card
|
||||
title={<><DashboardOutlined /> {isUAV ? '无人机状态' : '机器人状态'}详情</>}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12, marginBottom: 8 }}
|
||||
extra={<Tag color={device.onlineStatus === 1 ? 'success' : 'default'}>{device.onlineStatus === 1 ? '在线' : '离线'}</Tag>}
|
||||
>
|
||||
{isUAV ? (
|
||||
<Descriptions column={2} size="small" layout="vertical">
|
||||
<Descriptions.Item label={<><ThunderboltOutlined /> 电池电量</>}>
|
||||
<Progress percent={(currentDroneData || uavState || device).capacity_percent || 0} size="small" status={((currentDroneData || uavState || device).capacity_percent || 0) < 20 ? 'exception' : 'active'} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={<><EnvironmentOutlined /> 飞行高度</>}>
|
||||
<Text strong style={{ fontSize: 16 }}>{fix2((currentDroneData || uavState || device).height)} m</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="水平速度">
|
||||
<Text>{fix2(currentDroneData?.horizontal_speed) || '-'} m/s</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="垂直速度">
|
||||
<Text>{fix2(currentDroneData?.vertical_speed) || '-'} m/s</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="环境风速">
|
||||
<Text>{fix2((currentDroneData || uavState || device).wind_speed)} m/s</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="环境温度">
|
||||
<Text>{fix2((currentDroneData || uavState || device).environment_temperature)} ℃</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="环境湿度">
|
||||
<Text>{(currentDroneData?.humidity) || '-'}{currentDroneData?.humidity ? '%' : ''}</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="机场温度">
|
||||
<Text>{fix2(currentDroneData?.temperature)} ℃</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="降雨状态">
|
||||
<Tag color={(currentDroneData || uavState || device).rainfall === 'no_rain' ? 'green' : 'red'}>{getVal((currentDroneData || uavState || device).rainfall)}</Tag>
|
||||
</Descriptions.Item>
|
||||
|
||||
<Descriptions.Item label="航向角">
|
||||
<Text>{fix2(currentDroneData?.heading)}°</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="飞行模式">
|
||||
<Tag color="blue">
|
||||
{currentDroneData?.mode_code !== undefined ? `模式 ${currentDroneData.mode_code}` : '-'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
|
||||
<Descriptions.Item label="无人机位置">
|
||||
<Tag color="blue">
|
||||
{currentDroneData?.drone_in_dock === 1 ? '在库' : '外出'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="机库状态">
|
||||
<Tag color={currentDroneData?.cover_state === 1 ? 'processing' : 'default'}>
|
||||
{currentDroneData?.cover_state === 1 ? '舱门打开' : '舱门关闭'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="机场空调">
|
||||
<Tag color={currentDroneData?.air_conditioner_state === 1 ? 'success' : 'default'}>
|
||||
{currentDroneData?.air_conditioner_state === 1 ? '开启' : '关闭'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="GPS 卫星数">
|
||||
<Badge showZero count={(currentDroneData || uavState || device).position_state?.gps_number || 0} style={{ backgroundColor: '#1890ff' }} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="RTK 卫星数">
|
||||
<Badge showZero count={(currentDroneData || uavState || device).position_state?.rtk_number || 0} style={{ backgroundColor: '#52c41a' }} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="RTK 状态">
|
||||
<Tag color={(currentDroneData || uavState || device).position_state?.is_fixed === 2 || (currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'success' : 'warning'}>
|
||||
{(currentDroneData || uavState || device).position_state?.is_fixed === 2 || (currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="实时经纬度" span={2}>
|
||||
<Text style={{ fontSize: '12px' }}>
|
||||
{currentDroneData?.latitude && currentDroneData?.longitude ?
|
||||
`${currentDroneData.latitude.toFixed(6)}, ${currentDroneData.longitude.toFixed(6)}` : '-'}
|
||||
</Text>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
) : (
|
||||
<Col xs={24} lg={8}>
|
||||
<Card
|
||||
title={<><DashboardOutlined /> 机器人状态详情</>}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12, marginBottom: 8 }}
|
||||
extra={<Tag color={device.onlineStatus === 1 ? 'success' : 'default'}>{device.onlineStatus === 1 ? '在线' : '离线'}</Tag>}
|
||||
>
|
||||
<Descriptions column={2} size="small" layout="vertical">
|
||||
<Descriptions.Item label={<><ThunderboltOutlined /> 电池电量</>}>
|
||||
<Progress percent={runningStatus.battery || 0} size="small" status={(runningStatus.battery || 0) < 20 ? 'exception' : 'active'} />
|
||||
@@ -1122,8 +1118,6 @@ export default function DeviceStatusPage({
|
||||
<Descriptions.Item label="主控温度"><Text>{fix2(runningStatus?.chipTemp)} ℃</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="航向角状态"><Text>{(runningStatus?.headingStatus == 1 ? "已初始化" : "未初始化")}</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="控制模式"><Text>{(runningStatus?.controlMode == 1 ? "本地模式" : runningStatus?.controlMode == 3 ? "远程模式" : "控制模式")}</Text></Descriptions.Item>
|
||||
|
||||
|
||||
<Descriptions.Item label="定位质量">
|
||||
<Text>
|
||||
{runningStatus?.qual == 0
|
||||
@@ -1145,9 +1139,8 @@ export default function DeviceStatusPage({
|
||||
<Descriptions.Item label="偏航角 (Yaw)"><Text>{fix2(runningStatus?.yaw)}°</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="俯仰角 (Pitch)"><Text>{fix2(runningStatus?.pitch)}°</Text></Descriptions.Item>
|
||||
</Descriptions>
|
||||
)}
|
||||
</Card>
|
||||
{!isUAV && (
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
@@ -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}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
</Col>
|
||||
</Row>
|
||||
)}
|
||||
|
||||
<Modal
|
||||
open={isModalOpen}
|
||||
|
||||
@@ -16,17 +16,24 @@ interface DroneVideoPlayerProps {
|
||||
defaultSource?: 'station' | 'drone';
|
||||
videoSource?: 'station' | 'drone';
|
||||
onSourceChange?: (source: 'station' | 'drone') => void;
|
||||
// 新增:状态数据
|
||||
statusData?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
// 新增:显示类型(用于区分显示机场状态还是无人机状态)
|
||||
displayType?: 'station' | 'drone';
|
||||
}
|
||||
|
||||
const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
|
||||
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<DroneVideoPlayerProps> = ({
|
||||
const prevRef = useRef({
|
||||
selectedCamera: '',
|
||||
selectedLens: '',
|
||||
deviceSn: '',
|
||||
gatewaySn: '',
|
||||
videoSource: ''
|
||||
});
|
||||
|
||||
// 记住是否已经加载过,避免重复加载
|
||||
const hasLoadedRef = useRef({
|
||||
station: false,
|
||||
drone: false
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@@ -133,37 +149,69 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
|
||||
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<DroneVideoPlayerProps> = ({
|
||||
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 (
|
||||
<div style={{
|
||||
flex: 1,
|
||||
@@ -291,9 +348,62 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 状态详情叠加层 - 左上角 */}
|
||||
{data && (
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
top: 6,
|
||||
left: 6,
|
||||
background: 'rgba(0,0,0,0.7)',
|
||||
color: '#fff',
|
||||
padding: '8px 10px',
|
||||
borderRadius: 6,
|
||||
fontSize: 11,
|
||||
zIndex: 5,
|
||||
maxWidth: '40%',
|
||||
backdropFilter: 'blur(4px)'
|
||||
}}>
|
||||
{currentDisplayType === 'station' ? (
|
||||
<>
|
||||
<div style={{ marginBottom: 4, fontWeight: 600, color: '#1890ff' }}>机场状态</div>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'auto auto', gap: '2px 8px' }}>
|
||||
<span>温度:</span><span>{formatNumber(data.temperature || data.environment_temperature)}°C</span>
|
||||
<span>湿度:</span><span>{data.humidity !== undefined ? `${data.humidity}%` : '-'}</span>
|
||||
<span>风速:</span><span>{formatNumber(data.wind_speed)}m/s</span>
|
||||
<span>降雨:</span><span style={{ color: data.rainfall === 'no_rain' || data.rainfall === 0 ? '#52c41a' : '#ff4d4f' }}>
|
||||
{data.rainfall === 'no_rain' || data.rainfall === 0 ? '无' : '有'}
|
||||
</span>
|
||||
<span>机库:</span><span style={{ color: data.cover_state === 1 || data.cover_state === 'open' ? '#52c41a' : '#faad14' }}>
|
||||
{data.cover_state === 1 || data.cover_state === 'open' ? '已开' : '已关'}
|
||||
</span>
|
||||
<span>无人机:</span><span style={{ color: data.drone_in_dock === 1 || data.drone_in_dock === true ? '#52c41a' : '#1890ff' }}>
|
||||
{data.drone_in_dock === 1 || data.drone_in_dock === true ? '在库' : '外出'}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div style={{ marginBottom: 4, fontWeight: 600, color: '#52c41a' }}>无人机状态</div>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'auto auto', gap: '2px 8px' }}>
|
||||
<span>电量:</span><span style={{ color: (data.capacity_percent || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
|
||||
{data.capacity_percent !== undefined ? `${data.capacity_percent}%` : '-'}
|
||||
</span>
|
||||
<span>高度:</span><span>{formatNumber(data.height)}m</span>
|
||||
<span>水平速度:</span><span>{formatNumber(data.horizontal_speed)}m/s</span>
|
||||
<span>垂直速度:</span><span>{formatNumber(data.vertical_speed)}m/s</span>
|
||||
<span>航向角:</span><span>{formatNumber(data.heading)}°</span>
|
||||
<span>GPS:</span><span>{data.position_state?.gps_number || 0}颗</span>
|
||||
<span>RTK:</span><span style={{ color: data.position_state?.is_fixed === 2 || data.position_state?.is_fixed === 'fixing_successful' ? '#52c41a' : '#faad14' }}>
|
||||
{data.position_state?.is_fixed === 2 || data.position_state?.is_fixed === 'fixing_successful' ? '已固定' : '未固定'}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 底部信息叠加 */}
|
||||
{isDrone && device && (
|
||||
{/* 底部信息叠加 - 显示经纬度 */}
|
||||
{data && data.latitude !== undefined && data.longitude !== undefined && (
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
bottom: 0,
|
||||
@@ -302,12 +412,11 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
|
||||
background: 'rgba(0,0,0,0.6)',
|
||||
color: '#fff',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
justifyContent: 'center',
|
||||
padding: '4px 8px',
|
||||
fontSize: 10
|
||||
}}>
|
||||
{/*<span>高度 {Number(device?.height)?.toFixed(2) || '-'}m</span>
|
||||
<span>风速 {Number(device?.wind_speed?.toFixed(2) || '0')}m/s</span>*/}
|
||||
<span>位置: {formatNumber(data.latitude, 6)}, {formatNumber(data.longitude, 6)}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user