三个页面无人机mqtt显示成功

This commit is contained in:
mmc
2026-06-01 15:44:02 +08:00
parent 480e05c0d6
commit 9a5df3658c
5 changed files with 158 additions and 33 deletions

View File

@@ -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>