航线 设备状态 装备总览界面无人机和机场实时状态接入,并且地图上就可以实时显示无人机定位,根据航向角转角度
This commit is contained in:
@@ -25,11 +25,13 @@ import utils from '@/lib/utils';
|
||||
import CesiumMap from '../Map';
|
||||
import { getUAVState } from '@/api/device';
|
||||
import { fix2, getVal } from '@/lib/utils';
|
||||
import { useMqtt } from '@/hooks/useMqtt';
|
||||
import envConfig from '../../../env';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
export default function WayLinePage({ planedevices, onRefresh, mqttDroneData }) {
|
||||
export default function WayLinePage({ planedevices, onRefresh }) {
|
||||
const fontSmall = 'clamp(10px, 0.7vw, 11px)';
|
||||
const fontNormal = 'clamp(12px, 0.75vw, 13px)';
|
||||
const fontTitle = 'clamp(14px, 0.85vw, 16px)';
|
||||
@@ -43,36 +45,150 @@ export default function WayLinePage({ planedevices, onRefresh, mqttDroneData })
|
||||
const [listDateRange, setListDateRange] = useState(null);
|
||||
const [taskList, setTaskList] = useState([]);
|
||||
const [persistentDroneData, setPersistentDroneData] = useState(null); // 持久化无人机数据
|
||||
const [persistentHostData, setPersistentHostData] = 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,
|
||||
});
|
||||
const handleMqttMessage = (topic, message) => {
|
||||
console.log('WayLinePage MQTT 消息到达 - Topic:', topic);
|
||||
console.log('WayLinePage MQTT 消息内容:', message);
|
||||
try {
|
||||
const parsedMessage = JSON.parse(message);
|
||||
console.log('WayLinePage 解析后的消息:', parsedMessage);
|
||||
|
||||
if (parsedMessage.data && parsedMessage.data.host) {
|
||||
const { host } = parsedMessage.data;
|
||||
if (host?.job_number) { return; }
|
||||
|
||||
// 判断是无人机数据还是机场数据:无人机数据有 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('WayLinePage MQTT 消息解析失败:', err);
|
||||
}
|
||||
}, [mqttDroneData]);
|
||||
};
|
||||
|
||||
// 根据选中设备动态构建MQTT主题
|
||||
const mqttTopics = React.useMemo(() => {
|
||||
if (!listDrone) {
|
||||
return [];
|
||||
}
|
||||
const topics = [];
|
||||
if (listDrone.device_sn) {
|
||||
topics.push(`thing/product/${listDrone.device_sn}/osd`);
|
||||
}
|
||||
if (listDrone.gateway_sn && listDrone.gateway_sn !== listDrone.device_sn) {
|
||||
topics.push(`thing/product/${listDrone.gateway_sn}/osd`);
|
||||
}
|
||||
console.log('WayLinePage 订阅的MQTT主题:', topics);
|
||||
return topics;
|
||||
}, [listDrone]);
|
||||
|
||||
// 订阅MQTT消息
|
||||
useMqtt({
|
||||
url: envConfig.mqtt_url,
|
||||
topic: mqttTopics,
|
||||
onMessage: handleMqttMessage,
|
||||
});
|
||||
|
||||
// 优先使用持久化数据,保持显示稳定
|
||||
const mqttDerivedData = React.useMemo(() => {
|
||||
return persistentDroneData;
|
||||
}, [persistentDroneData]);
|
||||
return { ...persistentHostData, ...persistentDroneData };
|
||||
}, [persistentDroneData, persistentHostData]);
|
||||
|
||||
// 定时获取任务列表所选无人机的实时状态
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user