航线 设备状态 装备总览界面无人机和机场实时状态接入,并且地图上就可以实时显示无人机定位,根据航向角转角度
This commit is contained in:
@@ -23,6 +23,8 @@ import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
|
||||
import VideoPlayer from '../VideoPlayer.tsx.tsx';
|
||||
import CesiumMap from '../Map.jsx';
|
||||
import { getUAVState } from '@/api/device.ts';
|
||||
import { useMqtt } from '@/hooks/useMqtt';
|
||||
import envConfig from '../../../env';
|
||||
|
||||
const { Content } = Layout;
|
||||
const { Text, Title } = Typography;
|
||||
@@ -45,54 +47,181 @@ const logs = [
|
||||
{ time: '10:05:22', device: 'RBT-01', type: '事件', desc: '电量较低,建议回充', level: '低电量' },
|
||||
];
|
||||
|
||||
export default function DeviceOverviewPage({ devices, planedevices, devicesAll, onViewStatus, selectedSn, onDeviceSelect, mqttDroneData }) {
|
||||
export default function DeviceOverviewPage({ devices, planedevices, devicesAll, onViewStatus, selectedSn, onDeviceSelect }) {
|
||||
const [zoomedVideo, setZoomedVideo] = useState(null);
|
||||
const [mowerView, setMowerView] = useState('front');
|
||||
const [videoSource, setVideoSource] = useState('drone'); // 恢复 videoSource 状态管理
|
||||
const [videoSource, setVideoSource] = useState('drone');
|
||||
const [uavState, setUavState] = useState(null);
|
||||
const [persistentDroneData, setPersistentDroneData] = useState(null); // 持久化无人机数据
|
||||
const [persistentDroneData, setPersistentDroneData] = useState(null);
|
||||
const [persistentHostData, setPersistentHostData] = useState(null);
|
||||
|
||||
// 当MQTT数据更新时,更新持久化数据(只在有新数据时更新)
|
||||
useEffect(() => {
|
||||
if (mqttDroneData && mqttDroneData.host) {
|
||||
const { host } = mqttDroneData;
|
||||
setPersistentDroneData({
|
||||
// 无人机状态数据映射
|
||||
capacity_percent: host.drone_charge_state?.capacity_percent,
|
||||
environment_temperature: host.environment_temperature,
|
||||
height: host.height,
|
||||
wind_speed: host.wind_speed,
|
||||
rainfall: host.rainfall === 0 ? 'no_rain' : 'rain',
|
||||
position_state: host.position_state,
|
||||
longitude: host.longitude,
|
||||
latitude: host.latitude,
|
||||
heading: host.heading,
|
||||
humidity: host.humidity,
|
||||
drone_in_dock: host.drone_in_dock,
|
||||
cover_state: host.cover_state,
|
||||
temperature: host.temperature,
|
||||
});
|
||||
}
|
||||
}, [mqttDroneData]);
|
||||
|
||||
// 优先使用持久化数据,然后是API数据
|
||||
const currentDroneData = React.useMemo(() => {
|
||||
return persistentDroneData; // 总是返回持久化数据(不会变回null)
|
||||
}, [persistentDroneData]);
|
||||
|
||||
const selectedDevice = React.useMemo(() => {
|
||||
// 当前选中设备(切换时才变)
|
||||
const selectedDevice = useMemo(() => {
|
||||
const sn = selectedSn || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
|
||||
return devicesAll?.find(item => (item.device_sn || item.serialNumber) === sn) || null;
|
||||
}, [devicesAll, selectedSn]);
|
||||
|
||||
const isUAV = !!selectedDevice?.gateway_sn;
|
||||
|
||||
// ======================== 核心优化:视频用设备对象(绝不随MQTT刷新)========================
|
||||
const videoDevice = useMemo(() => {
|
||||
if (!selectedDevice) return null;
|
||||
return { ...selectedDevice };
|
||||
}, [selectedDevice]); // 只有切设备才变 → 视频不闪
|
||||
|
||||
// ======================== UI显示用(MQTT实时更新)========================
|
||||
const realtimeDevice = useMemo(() => {
|
||||
if (!selectedDevice) return null;
|
||||
return {
|
||||
...selectedDevice,
|
||||
...uavState,
|
||||
...persistentHostData,
|
||||
...persistentDroneData,
|
||||
};
|
||||
}, [selectedDevice, uavState, persistentHostData, persistentDroneData?.wind_speed]);
|
||||
console.log('实时设备数据:', realtimeDevice);
|
||||
|
||||
// MQTT消息处理
|
||||
const handleMqttMessage = (topic, message) => {
|
||||
console.log('DeviceOverviewPage MQTT Topic:', topic);
|
||||
console.log('DeviceOverviewPage MQTT Message:', message);
|
||||
console.log('实时设备数据:', realtimeDevice);
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(message);
|
||||
console.log('MQTT解析结果:', parsed);
|
||||
if (parsed.data?.host) {
|
||||
const { host } = parsed.data;
|
||||
|
||||
// 判断是无人机数据还是机场数据:无人机数据有 battery 字段
|
||||
const isDroneData = host.battery !== undefined;
|
||||
|
||||
if (isDroneData) {
|
||||
// 处理无人机数据
|
||||
setPersistentDroneData(prevData => {
|
||||
const newData = { ...prevData };
|
||||
|
||||
// 无人机特有字段
|
||||
if (host.battery?.capacity_percent !== undefined) {
|
||||
newData.capacity_percent = host.battery.capacity_percent;
|
||||
}
|
||||
if (host.attitude_head !== undefined) {
|
||||
newData.heading = host.attitude_head;
|
||||
}
|
||||
if (host.horizontal_speed !== undefined) {
|
||||
newData.horizontal_speed = host.horizontal_speed;
|
||||
}
|
||||
if (host.vertical_speed !== undefined) {
|
||||
newData.vertical_speed = host.vertical_speed;
|
||||
}
|
||||
if (host.total_flight_time !== undefined) {
|
||||
newData.total_flight_time = host.total_flight_time;
|
||||
}
|
||||
if (host.total_flight_sorties !== undefined) {
|
||||
newData.total_flight_sorties = host.total_flight_sorties;
|
||||
}
|
||||
if (host.mode_code !== undefined) {
|
||||
newData.mode_code = host.mode_code;
|
||||
}
|
||||
|
||||
// 通用字段
|
||||
if (host.height !== undefined) {
|
||||
newData.height = host.height;
|
||||
}
|
||||
if (host.wind_speed !== undefined) {
|
||||
newData.wind_speed = host.wind_speed;
|
||||
}
|
||||
if (host.position_state !== undefined) {
|
||||
newData.position_state = host.position_state;
|
||||
}
|
||||
if (host.longitude !== undefined) {
|
||||
newData.longitude = host.longitude;
|
||||
}
|
||||
if (host.latitude !== undefined) {
|
||||
newData.latitude = host.latitude;
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
} else {
|
||||
// 处理机场数据
|
||||
setPersistentHostData(prevData => {
|
||||
const newData = { ...prevData };
|
||||
|
||||
// 机场特有字段
|
||||
if (host.drone_charge_state?.capacity_percent !== undefined) {
|
||||
newData.capacity_percent = host.drone_charge_state.capacity_percent;
|
||||
}
|
||||
if (host.air_conditioner?.air_conditioner_state !== undefined) {
|
||||
newData.air_conditioner_state = host.air_conditioner.air_conditioner_state;
|
||||
}
|
||||
if (host.air_conditioner_state !== undefined) {
|
||||
newData.air_conditioner_state = host.air_conditioner_state;
|
||||
}
|
||||
|
||||
// 通用字段
|
||||
if (host.environment_temperature !== undefined) {
|
||||
newData.environment_temperature = host.environment_temperature;
|
||||
}
|
||||
if (host.wind_speed !== undefined) {
|
||||
newData.wind_speed = host.wind_speed;
|
||||
}
|
||||
if (host.rainfall !== undefined) {
|
||||
newData.rainfall = host.rainfall === 0 ? 'no_rain' : 'rain';
|
||||
}
|
||||
if (host.humidity !== undefined) {
|
||||
newData.humidity = host.humidity;
|
||||
}
|
||||
if (host.drone_in_dock !== undefined) {
|
||||
newData.drone_in_dock = host.drone_in_dock;
|
||||
}
|
||||
if (host.cover_state !== undefined) {
|
||||
newData.cover_state = host.cover_state;
|
||||
}
|
||||
if (host.temperature !== undefined) {
|
||||
newData.temperature = host.temperature;
|
||||
}
|
||||
if (host.home_distance !== undefined) {
|
||||
newData.home_distance = host.home_distance;
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('MQTT解析失败', err);
|
||||
}
|
||||
};
|
||||
|
||||
// MQTT订阅
|
||||
const mqttTopics = useMemo(() => {
|
||||
if (!isUAV || !selectedDevice) return [];
|
||||
const topics = [];
|
||||
if (selectedDevice.device_sn) {
|
||||
topics.push(`thing/product/${selectedDevice.device_sn}/osd`);
|
||||
}
|
||||
if (selectedDevice.gateway_sn && selectedDevice.gateway_sn !== selectedDevice.device_sn) {
|
||||
topics.push(`thing/product/${selectedDevice.gateway_sn}/osd`);
|
||||
}
|
||||
console.log('DeviceOverviewPage 订阅的MQTT主题:', topics);
|
||||
return topics;
|
||||
}, [selectedDevice]);
|
||||
|
||||
useMqtt({
|
||||
url: envConfig.mqtt_url,
|
||||
topic: mqttTopics,
|
||||
onMessage: handleMqttMessage,
|
||||
});
|
||||
|
||||
// 机器人视频
|
||||
const { video: robotVideo, error, ready } = useWebRTCPlayer(
|
||||
!isUAV ? selectedDevice?.serialNumber || '' : '',
|
||||
`webrtc://1.95.137.212/live/livestream/${selectedDevice?.serialNumber}`,
|
||||
);
|
||||
|
||||
const dynamicTopCards = React.useMemo(() => {
|
||||
// 顶部统计卡片
|
||||
const dynamicTopCards = useMemo(() => {
|
||||
const totalDrones = planedevices?.length || 0;
|
||||
const onlineDrones = planedevices?.filter(d => d.onlineStatus === 1).length || 0;
|
||||
const totalRobots = devicesAll?.filter(d => d.productName?.includes('巡检')).length || 0;
|
||||
@@ -109,18 +238,19 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
];
|
||||
}, [devicesAll, planedevices]);
|
||||
|
||||
const dynamicScheduleList = React.useMemo(() => {
|
||||
return devicesAll.map((d, index) => ({
|
||||
// 设备调度列表
|
||||
const dynamicScheduleList = useMemo(() => {
|
||||
return devicesAll?.map((d, index) => ({
|
||||
id: d.deviceId || index,
|
||||
name: d.deviceAlias || d.deviceName || d.callsign || '未知设备',
|
||||
type: d.productName || '未知类型',
|
||||
status: d.onlineStatus === 1 ? '在线' : '离线',
|
||||
mode: d.status === 4 ? '待命' : '作业中',
|
||||
battery: d.capacity_percent || 100,
|
||||
capacity_percent: d.capacity_percent || 100,
|
||||
position: d.position || '站内',
|
||||
task: d.status === 4 ? '待命' : '作业中',
|
||||
comm: d.rssi ? `${d.rssi}dBm` : '良好'
|
||||
}));
|
||||
})) || [];
|
||||
}, [devicesAll]);
|
||||
|
||||
const handleStart = () => message.success('任务已启动');
|
||||
@@ -140,17 +270,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
if (onDeviceSelect) onDeviceSelect(id);
|
||||
};
|
||||
|
||||
// 用于视频、状态展示的实时设备数据(优先使用持久化MQTT数据)
|
||||
const realtimeDevice = useMemo(() => {
|
||||
if (!selectedDevice) return null;
|
||||
return {
|
||||
...selectedDevice,
|
||||
...uavState,
|
||||
...currentDroneData, // 持久化数据最后覆盖,确保优先显示
|
||||
};
|
||||
}, [selectedDevice, uavState, currentDroneData]);
|
||||
|
||||
|
||||
// 获取无人机状态
|
||||
useEffect(() => {
|
||||
const fetchUavState = async () => {
|
||||
if (isUAV && selectedDevice?.gateway_sn && selectedDevice?.device_sn) {
|
||||
@@ -159,9 +279,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
sn: selectedDevice.gateway_sn,
|
||||
droneSn: selectedDevice.device_sn
|
||||
});
|
||||
if (res.code === 200) {
|
||||
setUavState(res.data);
|
||||
}
|
||||
if (res.code === 200) setUavState(res.data);
|
||||
} catch (err) {
|
||||
console.error('获取无人机状态失败', err);
|
||||
}
|
||||
@@ -169,10 +287,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
setUavState(null);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUavState();
|
||||
|
||||
|
||||
}, [isUAV, selectedDevice]);
|
||||
|
||||
return (
|
||||
@@ -292,12 +407,12 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 4 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||
<span style={{ color: '#52c41a' }}><ThunderboltOutlined /></span>
|
||||
<span style={{ fontSize: 12 }}>电量 {fix2((uavState || selectedDevice).capacity_percent || 100)}%</span>
|
||||
<span style={{ fontSize: 12 }}>电量 {fix2(realtimeDevice?.capacity_percent || 100)}%</span>
|
||||
</div>
|
||||
{(uavState || selectedDevice).environment_temperature && (
|
||||
{realtimeDevice?.environment_temperature && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{ fontSize: 12 }}>温度</span>
|
||||
<span style={{ color: '#faad14' }}>{fix2((uavState || selectedDevice).environment_temperature || 25)}℃</span>
|
||||
<span style={{ color: '#faad14' }}>{fix2(realtimeDevice.environment_temperature || 25)}℃</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -331,22 +446,21 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
<>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<span style={{ color: '#666', fontSize: 12 }}>飞行高度</span>
|
||||
<span style={{ fontSize: 12 }}>{fix2((uavState || selectedDevice).height)} m</span>
|
||||
<span style={{ fontSize: 12 }}>{fix2(realtimeDevice?.height)} m</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<span style={{ color: '#666', fontSize: 12 }}>飞行风速</span>
|
||||
<span style={{ fontSize: 12 }}>{fix2((uavState || selectedDevice).wind_speed)} m/s</span>
|
||||
<span style={{ fontSize: 12 }}>{fix2(realtimeDevice?.wind_speed)} m/s</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<span style={{ color: '#666', fontSize: 12 }}>rtk数量</span>
|
||||
<span style={{ fontSize: 12 }}>
|
||||
{/*<Badge count={(uavState || selectedDevice).position_state?.gps_number || 0} style={{ backgroundColor: '#1890ff', transform: 'scale(0.8)' }} />
|
||||
<span style={{ margin: '0 2px' }}>/</span>*/}
|
||||
<Badge
|
||||
showZero={true}
|
||||
count={(uavState || selectedDevice)?.position_state?.rtk_number || 0}
|
||||
count={realtimeDevice?.position_state?.rtk_number || 0}
|
||||
style={{ backgroundColor: '#52c41a', transform: 'scale(0.8)' }}
|
||||
/> </span>
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
@@ -379,13 +493,12 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 视频容器 */}
|
||||
{/* ✅ 关键:videoDevice 绝不随MQTT更新,视频永不闪烁 */}
|
||||
<div style={{ width: '100%', height: 160, borderRadius: 8, position: 'relative', overflow: 'hidden', background: '#000' }}>
|
||||
{isUAV ? (
|
||||
<DroneVideoPlayer
|
||||
device={realtimeDevice}
|
||||
device={videoDevice}
|
||||
height={160}
|
||||
|
||||
showSourceSelect={false}
|
||||
videoSource={videoSource}
|
||||
onSourceChange={setVideoSource}
|
||||
@@ -452,10 +565,10 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
<Card title="环境与飞行条件" bordered={false} style={{ borderRadius: 12, marginBottom: 8 }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", gap: 12, alignItems: "center" }}>
|
||||
<div style={{ display: "flex", border: "1px solid #e8e8e8", borderRadius: 12, overflow: "hidden", flex: 1 }}>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>风速</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{fix2((uavState || selectedDevice)?.wind_speed)} m/s</div></div>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>温度</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{fix2((uavState || selectedDevice)?.environment_temperature)}℃</div></div>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>降雨</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{getVal((uavState || selectedDevice)?.rainfall)}</div></div>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>RTK</div><div style={{ fontSize: 14, fontWeight: 700, color: '#52c41a', marginTop: 2 }}>{(uavState || selectedDevice)?.position_state?.is_fixed === 'fixing_successful' ? '固定' : '未固定'}</div></div>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>风速</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{fix2(realtimeDevice?.wind_speed)} m/s</div></div>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>温度</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{fix2(realtimeDevice?.environment_temperature)}℃</div></div>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>降雨</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{getVal(realtimeDevice?.rainfall)}</div></div>
|
||||
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>RTK</div><div style={{ fontSize: 14, fontWeight: 700, color: '#52c41a', marginTop: 2 }}>{realtimeDevice?.position_state?.is_fixed === 'fixing_successful' ? '固定' : '未固定'}</div></div>
|
||||
</div>
|
||||
<div style={{ width: 110, padding: '12px 4px', borderRadius: 8, background: '#f6ffed', border: '1px solid #b7eb8f', textAlign: 'center', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 4 }}>
|
||||
<div className="flex items-center gap-1">
|
||||
|
||||
Reference in New Issue
Block a user