三个页面无人机mqtt显示成功
This commit is contained in:
@@ -45,11 +45,40 @@ const logs = [
|
||||
{ time: '10:05:22', device: 'RBT-01', type: '事件', desc: '电量较低,建议回充', level: '低电量' },
|
||||
];
|
||||
|
||||
export default function DeviceOverviewPage({ devices, planedevices, devicesAll, onViewStatus, selectedSn, onDeviceSelect }) {
|
||||
export default function DeviceOverviewPage({ devices, planedevices, devicesAll, onViewStatus, selectedSn, onDeviceSelect, mqttDroneData }) {
|
||||
const [zoomedVideo, setZoomedVideo] = useState(null);
|
||||
const [mowerView, setMowerView] = useState('front');
|
||||
const [videoSource, setVideoSource] = useState('drone'); // 恢复 videoSource 状态管理
|
||||
const [uavState, setUavState] = useState(null);
|
||||
const [persistentDroneData, setPersistentDroneData] = 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 sn = selectedSn || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
|
||||
@@ -111,14 +140,15 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
if (onDeviceSelect) onDeviceSelect(id);
|
||||
};
|
||||
|
||||
// 用于视频、状态展示的实时设备数据(只合并一次)
|
||||
// 用于视频、状态展示的实时设备数据(优先使用持久化MQTT数据)
|
||||
const realtimeDevice = useMemo(() => {
|
||||
if (!selectedDevice) return null;
|
||||
return {
|
||||
...selectedDevice,
|
||||
...uavState, // 无人机实时状态覆盖
|
||||
...uavState,
|
||||
...currentDroneData, // 持久化数据最后覆盖,确保优先显示
|
||||
};
|
||||
}, [selectedDevice, uavState]);
|
||||
}, [selectedDevice, uavState, currentDroneData]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
@@ -140,7 +170,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
}
|
||||
};
|
||||
|
||||
fetchUavState();
|
||||
fetchUavState();
|
||||
|
||||
|
||||
}, [isUAV, selectedDevice]);
|
||||
|
||||
@@ -58,8 +58,40 @@ export default function DeviceStatusPage({
|
||||
devicesAll,
|
||||
serialNumber,
|
||||
onDeviceChange,
|
||||
mqttDroneData,
|
||||
}) {
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const [persistentDroneData, setPersistentDroneData] = 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,
|
||||
home_distance: host.home_distance,
|
||||
air_conditioner_state: host.air_conditioner_state,
|
||||
});
|
||||
}
|
||||
}, [mqttDroneData]);
|
||||
|
||||
// 优先使用持久化数据,保持显示稳定
|
||||
const currentDroneData = React.useMemo(() => {
|
||||
return persistentDroneData;
|
||||
}, [persistentDroneData]);
|
||||
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
@@ -174,7 +206,7 @@ export default function DeviceStatusPage({
|
||||
}
|
||||
};
|
||||
|
||||
fetchUavState();
|
||||
fetchUavState();
|
||||
}, [isUAV, device]);
|
||||
|
||||
// 获取执行中任务的轨迹
|
||||
@@ -230,9 +262,9 @@ export default function DeviceStatusPage({
|
||||
const mapDevices = useMemo(() => {
|
||||
if (!device) return null;
|
||||
|
||||
// 优先使用无人机实时数据
|
||||
const lng = uavState?.longitude ?? runningStatus.longitude ?? device.longitude;
|
||||
const lat = uavState?.latitude ?? runningStatus.latitude ?? device.latitude;
|
||||
// 优先使用持久化MQTT数据,其次使用uavState
|
||||
const lng = currentDroneData?.longitude ?? uavState?.longitude ?? runningStatus.longitude ?? device.longitude;
|
||||
const lat = currentDroneData?.latitude ?? uavState?.latitude ?? runningStatus.latitude ?? device.latitude;
|
||||
|
||||
return {
|
||||
...device,
|
||||
@@ -251,14 +283,15 @@ export default function DeviceStatusPage({
|
||||
? 'mower'
|
||||
: 'robot',
|
||||
};
|
||||
}, [device, isUAV, runningStatus, uavState]);
|
||||
}, [device, isUAV, runningStatus, uavState, currentDroneData]);
|
||||
const realtimeDevice = useMemo(() => {
|
||||
if (!device) return null;
|
||||
return {
|
||||
...device,
|
||||
...uavState, // 无人机实时状态覆盖
|
||||
...uavState,
|
||||
...currentDroneData, // 持久化数据最后覆盖,确保优先显示
|
||||
};
|
||||
}, [device, uavState]);
|
||||
}, [device, uavState, currentDroneData]);
|
||||
|
||||
const handleGamepadUpdate = useCallback((state) => {
|
||||
controllerRef.current?.sendGamepad(state);
|
||||
@@ -506,26 +539,50 @@ export default function DeviceStatusPage({
|
||||
{isUAV ? (
|
||||
<Descriptions column={2} size="small" layout="vertical">
|
||||
<Descriptions.Item label={<><ThunderboltOutlined /> 电池电量</>}>
|
||||
<Progress percent={(uavState || device).capacity_percent || 0} size="small" status={((uavState || device).capacity_percent || 0) < 20 ? 'exception' : 'active'} />
|
||||
<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((uavState || device).height)} m</Text>
|
||||
<Text strong style={{ fontSize: 16 }}>{fix2((currentDroneData || uavState || device).height)} m</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="环境风速"><Text>{fix2((uavState || device).wind_speed)} m/s</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="环境温度"><Text>{fix2((uavState || device).environment_temperature)} ℃</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="降雨状态">
|
||||
<Tag color={(uavState || device).rainfall === 'no_rain' ? 'green' : 'red'}>{getVal((uavState || device).rainfall)}</Tag>
|
||||
<Tag color={(currentDroneData || uavState || device).rainfall === 'no_rain' ? 'green' : 'red'}>{getVal((currentDroneData || uavState || device).rainfall)}</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="返航距离"><Text>{fix2((currentDroneData || uavState || device).home_distance)} m</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="航向角">
|
||||
<Text>{fix2(currentDroneData?.heading)}°</Text>
|
||||
</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="返航距离"><Text>{fix2((uavState || device).home_distance)} m</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="GPS 卫星数">
|
||||
<Badge count={(uavState || device).position_state?.gps_number || 0} style={{ backgroundColor: '#1890ff' }} />
|
||||
<Badge count={(currentDroneData || uavState || device).position_state?.gps_number || 0} style={{ backgroundColor: '#1890ff' }} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="RTK 卫星数">
|
||||
<Badge count={(uavState || device).position_state?.rtk_number || 0} style={{ backgroundColor: '#52c41a' }} />
|
||||
<Badge count={(currentDroneData || uavState || device).position_state?.rtk_number || 0} style={{ backgroundColor: '#52c41a' }} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="RTK 状态" span={2}>
|
||||
<Tag color={(uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'success' : 'warning'}>
|
||||
{(uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'}
|
||||
<Tag color={(currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'success' : 'warning'}>
|
||||
{(currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
|
||||
@@ -91,7 +91,6 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
|
||||
const cameraIndex = targetCamera?.camera_index || "";
|
||||
|
||||
if (!cameraIndex) {
|
||||
utils.message.warning('未找到无人机相机配置');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import { fix2, getVal } from '@/lib/utils';
|
||||
const { Text, Title } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
export default function WayLinePage({ planedevices, onRefresh }) {
|
||||
export default function WayLinePage({ planedevices, onRefresh, mqttDroneData }) {
|
||||
const fontSmall = 'clamp(10px, 0.7vw, 11px)';
|
||||
const fontNormal = 'clamp(12px, 0.75vw, 13px)';
|
||||
const fontTitle = 'clamp(14px, 0.85vw, 16px)';
|
||||
@@ -42,9 +42,38 @@ export default function WayLinePage({ planedevices, onRefresh }) {
|
||||
const [listDroneRealtime, setListDroneRealtime] = useState(null);
|
||||
const [listDateRange, setListDateRange] = useState(null);
|
||||
const [taskList, setTaskList] = useState([]);
|
||||
const [persistentDroneData, setPersistentDroneData] = useState(null); // 持久化无人机数据
|
||||
|
||||
const listDroneTimerRef = useRef<any>(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]);
|
||||
|
||||
// 优先使用持久化数据,保持显示稳定
|
||||
const mqttDerivedData = React.useMemo(() => {
|
||||
return persistentDroneData;
|
||||
}, [persistentDroneData]);
|
||||
|
||||
// 定时获取任务列表所选无人机的实时状态
|
||||
useEffect(() => {
|
||||
const fetchRealtime = async () => {
|
||||
@@ -940,7 +969,7 @@ export default function WayLinePage({ planedevices, onRefresh }) {
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 12, color: '#86909C' }}>风速</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#1D2129' }}>{fix2((listDroneRealtime || listDrone)?.wind_speed)} m/s</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#1D2129' }}>{fix2((mqttDerivedData || listDroneRealtime || listDrone)?.wind_speed)} m/s</div>
|
||||
<div style={{ fontSize: 12, color: '#00B42A' }}>适宜</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -951,7 +980,7 @@ export default function WayLinePage({ planedevices, onRefresh }) {
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 12, color: '#86909C' }}>温度</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#1D2129' }}>{fix2((listDroneRealtime || listDrone)?.environment_temperature)}℃</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#1D2129' }}>{fix2((mqttDerivedData || listDroneRealtime || listDrone)?.environment_temperature)}℃</div>
|
||||
<div style={{ fontSize: 12, color: '#00B42A' }}>适宜</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -962,9 +991,9 @@ export default function WayLinePage({ planedevices, onRefresh }) {
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 12, color: '#86909C' }}>降水状态</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#1D2129' }}>{getVal((listDroneRealtime || listDrone)?.rainfall)}</div>
|
||||
<div style={{ fontSize: 12, color: (listDroneRealtime || listDrone)?.rainfall === 'no_rain' ? '#00B42A' : '#F53F3F' }}>
|
||||
{(listDroneRealtime || listDrone)?.rainfall === 'no_rain' ? '低风险' : '有雨'}
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#1D2129' }}>{getVal((mqttDerivedData || listDroneRealtime || listDrone)?.rainfall)}</div>
|
||||
<div style={{ fontSize: 12, color: (mqttDerivedData || listDroneRealtime || listDrone)?.rainfall === 'no_rain' ? '#00B42A' : '#F53F3F' }}>
|
||||
{(mqttDerivedData || listDroneRealtime || listDrone)?.rainfall === 'no_rain' ? '低风险' : '有雨'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -976,10 +1005,10 @@ export default function WayLinePage({ planedevices, onRefresh }) {
|
||||
<div>
|
||||
<div style={{ fontSize: 12, color: '#86909C' }}>GNSS质量</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#1D2129' }}>
|
||||
{(listDroneRealtime || listDrone)?.position_state?.rtk_number ?? 0} RTK
|
||||
{(mqttDerivedData || listDroneRealtime || listDrone)?.position_state?.rtk_number ?? 0} RTK
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: (listDroneRealtime || listDrone)?.position_state?.is_fixed === 'fixing_successful' ? '#00B42A' : '#FF7D00' }}>
|
||||
{(listDroneRealtime || listDrone)?.position_state?.is_fixed === 'fixing_successful' ? '已固定' : '未固定'}
|
||||
<div style={{ fontSize: 12, color: (mqttDerivedData || listDroneRealtime || listDrone)?.position_state?.is_fixed === 'fixing_successful' ? '#00B42A' : '#FF7D00' }}>
|
||||
{(mqttDerivedData || listDroneRealtime || listDrone)?.position_state?.is_fixed === 'fixing_successful' ? '已固定' : '未固定'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user