Files
web-Iot/src/components/devices/DeviceStatusPage.tsx

1485 lines
45 KiB
TypeScript
Raw Normal View History

import React, {
2026-05-20 15:12:51 +08:00
useState,
useEffect,
useMemo,
useRef,
useCallback,
} from 'react';
2026-05-11 16:34:44 +08:00
import {
2026-05-20 15:12:51 +08:00
Row,
Col,
Card,
Tag,
Typography,
Space,
Empty,
Descriptions,
Badge,
Progress,
Button,
Select,
message,
Modal,
2026-06-24 15:47:52 +08:00
Switch,
2026-05-11 16:34:44 +08:00
} from 'antd';
2026-05-20 15:12:51 +08:00
2026-05-11 16:34:44 +08:00
import {
2026-05-20 15:12:51 +08:00
DashboardOutlined,
GlobalOutlined,
VideoCameraOutlined,
ControlOutlined,
CameraOutlined,
ThunderboltOutlined,
EnvironmentOutlined,
DeleteOutlined,
2026-05-11 16:34:44 +08:00
} from '@ant-design/icons';
2026-05-20 15:12:51 +08:00
2026-05-27 15:08:26 +08:00
import {
getsinglePlan,
2026-05-27 15:08:26 +08:00
getsinglePlanTrack,
getFlightTaskDetail,
getUAVState,
getSiteDevice,
getSiteUAVList,
addRoute,
2026-05-27 15:08:26 +08:00
} from '../../api/device.ts';
2026-08-04 16:11:27 +08:00
import { useLocation } from 'react-router-dom';
2026-05-27 15:08:26 +08:00
2026-05-11 16:34:44 +08:00
import XboxController from './XboxController';
2026-05-25 10:30:20 +08:00
import DroneVideoPlayer from './DroneVideoPlayer';
2026-05-12 08:34:13 +08:00
import CesiumMap from '../Map.jsx';
2026-05-12 10:34:50 +08:00
import { useSelector } from 'react-redux';
import { RootState } from '@/src/store/index.ts';
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
import VideoPlayer from '../VideoPlayer.tsx';
2026-09-08 15:59:41 +08:00
import AgrtcRoomRobot from '../AgrtcRoomRobot';
2026-05-20 15:12:51 +08:00
import DeviceController from './DeviceController';
2026-05-22 08:03:30 +08:00
import { DatePicker } from 'antd';
import dayjs from 'dayjs';
import { MowerAllView } from './MowerAllView';
import { useMqtt } from '@/hooks/useMqtt';
import envConfig from '../../../env';
import { dataUrlToFile } from '@/lib/utils.ts';
2026-08-06 13:39:14 +08:00
import { PauseOutlined, PlayCircleOutlined } from '@ant-design/icons';
2026-08-12 11:29:44 +08:00
import { useTranslation } from 'react-i18next';
2026-05-22 08:03:30 +08:00
const { RangePicker } = DatePicker;
2026-05-12 11:11:30 +08:00
2026-05-12 10:34:50 +08:00
const { Text } = Typography;
2026-09-08 15:59:41 +08:00
export default function DeviceStatusPage() {
2026-08-12 11:29:44 +08:00
const { t } = useTranslation();
2026-05-20 15:12:51 +08:00
const { userInfo } = useSelector((state: RootState) => state.user);
2026-08-04 16:33:52 +08:00
const { stationId, currentStation } = useSelector((state: RootState) => state.station);
2026-06-01 15:44:02 +08:00
const [persistentDroneData, setPersistentDroneData] = useState(null); // 持久化无人机数据
const [persistentHostData, setPersistentHostData] = useState(null); // 持久化机场数据
const [devices, setDevices] = useState([]);
const [planedevices, setPlaneDevices] = useState([]);
const [devicesAll, setDevicesAll] = useState([]);
const [arrivedPoint, setArrivedPoint] = useState(null);//完成点
2026-06-24 15:47:52 +08:00
const [isLoopMode, setIsLoopMode] = useState(true);
2026-07-07 16:06:40 +08:00
const controllerRef = useRef<DeviceController | null>(null);
const isFirstConnect = useRef(true);
2026-07-07 16:06:40 +08:00
const [messageApi, contextHolder] = message.useMessage();
2026-08-06 13:39:14 +08:00
// 视频播放开关
const [isVideoPlaying, setIsVideoPlaying] = useState(false);
const toggleVideoPlay = useCallback(() => {
setIsVideoPlaying(prev => !prev);
}, []);
2026-07-07 16:06:40 +08:00
const [isControlled, setIsControlled] = useState(false);
const [hasControlRight, setHasControlRight] = useState(false);
const [connecting, setConnecting] = useState(false);
const [wsStatus, setWsStatus] = useState('disconnected');
const [wsDeviceInfo, setWsDeviceInfo] = useState({});
const [locationInfo, setLocationInfo] = useState({});
2026-07-07 16:06:40 +08:00
// 👇 加上这两个
const [queryTimeRange, setQueryTimeRange] = useState([]); // 时间范围
const [startTimestamp, setStartTimestamp] = useState(''); // 开始时间戳
const [endTimestamp, setEndTimestamp] = useState(''); // 结束时间戳
const [isModalOpen, setIsModalOpen] = useState(false);
const [modalContent, setModalContent] = useState({
title: '',
content: '',
});
const [mowerView, setMowerView] = useState('front');
const [uavState, setUavState] = useState<any>(null);
const [points, setPoints] = useState([]);
const [clearNavLine, setClearNavLine] = useState(0);
const [clearPlanLine, setClearPlanLine] = useState(0);
const timerRef = useRef<any>(null);
// 打点相关状态
const [markedPoints, setMarkedPoints] = useState([]); // 标记的点
const [completeFlag, setCompleteFlag] = useState(false); // 是否完成路径规划
const [savePath, setSavePath] = useState(null); // 保存的路径数据
const [isSaveModalVisible, setIsSaveModalVisible] = useState(false); // 保存模态框可见性
const [plotName, setPlotName] = useState(''); // 地块名称
const [isSaving, setIsSaving] = useState(false); // 是否正在保存
2026-08-25 16:54:36 +08:00
const mapRef = useRef(null);
const clearDrawRef = useRef<(() => void) | null>(null); // 地图 ref
2026-07-07 16:06:40 +08:00
2026-08-04 16:11:27 +08:00
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const urlSn = queryParams.get('sn'); // 拿到路由上的sn
2026-06-24 15:47:52 +08:00
// 开关切换回调
const handleChange = (checked: boolean) => {
setIsLoopMode(checked);
if (checked) {
console.log('当前作业方式:回字');
} else {
console.log('当前作业方式:单点');
}
};
// 获取数据
const fetchAllData = async () => {
if (!stationId) return;
try {
// 1. 同时发请求
const [deviceRes, planeRes] = await Promise.all([
2026-08-04 16:33:52 +08:00
getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1, orgId: currentStation?.orgId }),
getSiteUAVList(stationId),
]);
// 2. 处理普通设备
const devData = deviceRes?.code === 200 ? (deviceRes.rows || []) : [];
// 3. 处理无人机 + 自动补全地图需要的字段(关键改动)
let planeData = planeRes?.code === 200 ? (planeRes?.rows || []) : [];
planeData = planeData.map(item => ({
...item,
type: 'plane',
lastRunningStatus: {
longitude: item.longitude || 0,
latitude: item.latitude || 0,
},
deviceAlias: item.drone_callsign || item.device_sn
2026-08-12 11:29:44 +08:00
|| t('constants.uav'),
}));
setDevices(devData);
setPlaneDevices(planeData);
// 合并所有设备
const all = [...devData, ...planeData];
setDevicesAll(all);
} catch (err) {
console.error('数据请求失败', err);
}
};
const handleFinishEdPoint = (point) => {
setArrivedPoint(point);
}
useEffect(() => {
fetchAllData();
}, [userInfo, stationId]);
// 当前选中的设备SN
const [selectedSn, setSelectedSn] = useState('');
// 当设备列表加载后,如果没有选中的设备,默认选中第一个
useEffect(() => {
if (devicesAll?.length > 0) {
2026-08-04 16:11:27 +08:00
// 优先从url参数匹配设备
if (urlSn) {
const target = devicesAll.find(d =>
(d.device_sn || d.serialNumber) === urlSn
);
if (target) {
setSelectedSn(urlSn);
2026-08-06 13:39:14 +08:00
setIsVideoPlaying(false);
2026-08-04 16:11:27 +08:00
return;
}
}
// url无sn / 没匹配到对应设备:默认选中第一个
const firstDevice = devicesAll[0];
setSelectedSn(firstDevice.device_sn || firstDevice.serialNumber);
2026-08-06 13:39:14 +08:00
setIsVideoPlaying(false);
}
2026-08-04 16:11:27 +08:00
}, [devicesAll, urlSn]);
// 获取当前选中的无人机设备
const device = useMemo(() => {
const sn = selectedSn;
if (!sn) return null;
return devicesAll?.find(
(d) => (d.device_sn || d.serialNumber) == sn,
);
}, [devicesAll, selectedSn]);
const isUAV = useMemo(() => {
// 设备有 drone_callsign 或 gateway_sn 则是无人机
return !!(device?.drone_callsign || device?.gateway_sn);
}, [device]);
2026-06-01 15:44:02 +08:00
// 设备选择变化时,调用回调并更新内部状态
const handleDeviceSelectChange = (val) => {
setSelectedSn(val);
// 切换设备时清空之前的标记点等
setMarkedPoints([]);
setCompleteFlag(false);
setSavePath(null);
};
2026-06-01 15:44:02 +08:00
// 当MQTT数据更新时,更新持久化数据(只在有新数据时更新)
const handleMqttMessage = useCallback((topic, message) => {
2026-06-02 10:08:23 +08:00
try {
const parsedMessage = JSON.parse(message);
if (parsedMessage.data && parsedMessage.data.host) {
const { host } = parsedMessage.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('DeviceStatusPage MQTT 消息解析失败:', err);
}
}, []);
// 根据选中设备动态构建MQTT主题
const mqttTopics = useMemo(() => {
if (!isUAV || !device) {
return [];
}
const topics = [];
if (device.device_sn) {
topics.push(`thing/product/${device.device_sn}/osd`);
}
if (device.gateway_sn && device.gateway_sn !== device.device_sn) {
topics.push(`thing/product/${device.gateway_sn}/osd`);
2026-06-01 15:44:02 +08:00
}
return topics;
}, [isUAV, device]);
// 订阅MQTT消息
useMqtt({
url: envConfig.mqtt_url,
topic: mqttTopics,
onMessage: handleMqttMessage,
enabled: mqttTopics.length > 0,
});
2026-06-01 15:44:02 +08:00
// 合并无人机和机场数据
2026-06-01 15:44:02 +08:00
const currentDroneData = React.useMemo(() => {
return { ...persistentHostData, ...persistentDroneData };
}, [persistentDroneData, persistentHostData]);
// 实时位置数据(用于地图)
2026-05-20 15:12:51 +08:00
2026-05-12 10:34:50 +08:00
const runningStatus = useMemo(() => {
// 判断对象是否为空
if ((!wsDeviceInfo || Object.keys(wsDeviceInfo).length === 0) && (!locationInfo || Object.keys(locationInfo).length === 0) && !isUAV) {
return {};
}
if (isUAV) {
return {
...wsDeviceInfo,
};
}
2026-05-20 15:12:51 +08:00
const base = device?.lastRunningStatus || {};
return isUAV
? base
: {
...base,
2026-09-08 15:59:41 +08:00
...device?.locationMessage,
2026-05-20 15:12:51 +08:00
...wsDeviceInfo,
...locationInfo
2026-05-12 10:34:50 +08:00
};
}, [device, wsDeviceInfo, isUAV, locationInfo]);
2026-05-11 16:34:44 +08:00
2026-05-20 15:12:51 +08:00
const { video: robotVideo, error, ready } = useWebRTCPlayer(
2026-09-08 15:59:41 +08:00
(!isUAV && isVideoPlaying && !device?.hasHost) ? (device?.serialNumber || '') : '',
2026-08-06 13:39:14 +08:00
(!isUAV && isVideoPlaying)
? `webrtc://1.95.137.212/live/livestream/${device?.serialNumber}`
: ''
2026-05-20 15:12:51 +08:00
);
2026-08-06 13:39:14 +08:00
//const { video: robotVideo, error, ready } = useWebRTCPlayer(
// !isUAV ? device?.serialNumber : '',
// `webrtc://1.95.137.212/live/livestream/${device?.serialNumber}`,
//);
2026-08-14 09:02:52 +08:00
const getVal = (val) => val === "no_rain" ? t('devices.rainNo') : (val || '-');
const fixStatusMap: Record<string, string> = {
'no_fix': t('devices.noFix'),
'single': t('devices.single'),
'dgnss': t('devices.dgnss'),
'ins': t('devices.ins'),
'rtk_fixed': t('devices.rtkFixed'),
'rtk_float': t('devices.rtkFloat'),
'single_no_heading': t('devices.singleNoHeading'),
'dgnss_no_heading': t('devices.dgnssNoHeading'),
'rtk_fixed_no_heading': t('devices.rtkFixedNoHeading'),
'rtk_float_no_heading': t('devices.rtkFloatNoHeading'),
}
2026-05-11 16:34:44 +08:00
const realtimePosition = React.useMemo(() => {
// 1. 无人机:优先用 MQTT 实时数据
if (isUAV) {
if (currentDroneData?.longitude && currentDroneData?.latitude) {
return {
lon: currentDroneData.longitude,
lat: currentDroneData.latitude,
heading: currentDroneData.heading || 0,
};
}
return null;
}
// 2. 机器人:从 wsDeviceInfo / runningStatus 取实时经纬度
2026-09-02 15:38:05 +08:00
const robotLon = runningStatus?.longitude || wsDeviceInfo?.longitude;
const robotLat = runningStatus?.latitude || wsDeviceInfo?.latitude;
if (robotLon && robotLat) {
return {
lon: robotLon,
lat: robotLat,
//heading: -98
2026-09-02 15:38:05 +08:00
heading: runningStatus?.yaw || wsDeviceInfo?.yaw || 0,
};
}
return null;
}, [isUAV, currentDroneData, runningStatus, wsDeviceInfo]);
2026-05-12 10:34:50 +08:00
2026-05-20 15:12:51 +08:00
useEffect(() => {
const controller = new DeviceController(userInfo, messageApi);
controller.onDeviceInfoUpdate = setWsDeviceInfo;
controller.onLocationInfoUpdate = setLocationInfo;
2026-05-20 15:12:51 +08:00
controller.onControlStatusChange = setIsControlled;
controller.onHasControlRightChange = setHasControlRight;
controller.onRequestControlStatusChange = setConnecting;
controller.onWsStatusChange = setWsStatus;
controller.handleArrivedPoint = handleFinishEdPoint;
2026-05-12 10:34:50 +08:00
2026-05-20 15:12:51 +08:00
controller.onPermissionRequest = (content) => {
setModalContent(content);
setIsModalOpen(true);
2026-05-12 10:34:50 +08:00
};
2026-05-20 15:12:51 +08:00
controller.init();
2026-05-12 10:34:50 +08:00
2026-05-20 15:12:51 +08:00
controllerRef.current = controller;
2026-05-12 10:34:50 +08:00
2026-05-20 15:12:51 +08:00
return () => {
controller?.destroy();
controllerRef.current?.destroy();
2026-05-20 15:12:51 +08:00
controllerRef.current = null;
2026-06-04 15:39:46 +08:00
2026-05-20 15:12:51 +08:00
};
2026-06-04 15:39:46 +08:00
}, []);
2026-05-12 10:34:50 +08:00
useEffect(() => {
2026-07-07 16:06:40 +08:00
if (!device || !controllerRef.current || !device?.serialNumber || isUAV) {
return;
}
setWsDeviceInfo({});
setLocationInfo({});
2026-05-12 10:34:50 +08:00
if (isFirstConnect.current) {
isFirstConnect.current = false;
controllerRef.current.connectDevice(device);
} else {
controllerRef.current.switchDevice(device);
}
}, [device?.serialNumber]);
2026-05-12 10:34:50 +08:00
2026-05-27 15:08:26 +08:00
// 定时获取无人机状态
useEffect(() => {
const fetchUavState = async () => {
if (isUAV && device?.gateway_sn && device?.device_sn) {
try {
const res = await getUAVState({
sn: device.gateway_sn,
droneSn: device.device_sn
});
if (res.code === 200) {
setUavState(res.data);
}
} catch (err) {
console.error('获取无人机状态失败', err);
}
} else {
setUavState(null);
}
};
2026-06-01 15:44:02 +08:00
fetchUavState();
}, [isUAV, device]);
2026-05-27 15:08:26 +08:00
// 获取执行中任务的轨迹
useEffect(() => {
const fetchExecutingTaskTrack = async () => {
if (isUAV && device?.gateway_sn) {
try {
const todayStart = dayjs().startOf('day').unix();
const todayEnd = dayjs().endOf('day').unix();
const sns = [device.gateway_sn];
const res = await getsinglePlan({ sns, beginAt: todayStart, endAt: todayEnd });
if (res?.code === 200 && res.data) {
let combinedList = [];
Object.values(res.data).forEach((item: any) => {
if (item.list) combinedList = combinedList.concat(item.list);
});
// 筛选出执行中的任务
const executingTask = combinedList.find(t =>
['executing', 'running', 'restored'].includes(t.status)
);
if (executingTask) {
const trackRes = await getsinglePlanTrack(executingTask);
if (trackRes.code === 0 && trackRes.data.track?.points?.length) {
const trackPoints = trackRes.data.track.points.map(item => ({
lon: item.longitude || item.lon,
lat: item.latitude || item.lat
}));
setPoints(trackPoints);
} else {
setPoints([]);
}
} else {
setPoints([]);
}
} else {
setPoints([]);
}
} catch (err) {
console.error('获取执行中任务轨迹失败', err);
setPoints([]);
}
} else {
setPoints([]);
}
};
2026-05-27 15:08:26 +08:00
fetchExecutingTaskTrack();
2026-05-27 15:08:26 +08:00
}, [isUAV, device]);
2026-05-12 08:48:33 +08:00
const mapDevices = useMemo(() => {
if (!device) return null;
2026-06-01 15:44:02 +08:00
// 优先使用持久化MQTT数据,其次使用uavState
2026-09-02 15:38:05 +08:00
const lng = currentDroneData?.longitude ?? uavState?.longitude ?? runningStatus?.longitude ?? device.longitude;
const lat = currentDroneData?.latitude ?? uavState?.latitude ?? runningStatus?.latitude ?? device.latitude;
2026-05-20 15:12:51 +08:00
return {
2026-05-12 08:48:33 +08:00
...device,
lastRunningStatus: {
...device.lastRunningStatus,
longitude: lng,
latitude: lat,
2026-05-12 08:48:33 +08:00
},
longitude: lng,
latitude: lat,
2026-09-02 15:38:05 +08:00
name: device?.deviceAlias || device?.callsign || device?.deviceName || t('devices.device'),
2026-05-20 15:12:51 +08:00
type: isUAV
? 'drone'
2026-09-02 15:38:05 +08:00
: device?.productName?.includes(t('constants.mower'))
2026-05-20 15:12:51 +08:00
? 'mower'
: 'robot',
2026-05-12 08:48:33 +08:00
};
2026-06-01 15:44:02 +08:00
}, [device, isUAV, runningStatus, uavState, currentDroneData]);
const realtimeDevice = useMemo(() => {
if (!device) return null;
return {
...device,
2026-06-01 15:44:02 +08:00
...uavState,
...currentDroneData, // 持久化数据最后覆盖,确保优先显示
};
2026-06-01 15:44:02 +08:00
}, [device, uavState, currentDroneData]);
2026-05-12 10:34:50 +08:00
2026-05-20 15:12:51 +08:00
const handleGamepadUpdate = useCallback((state) => {
controllerRef.current?.sendGamepad(state);
}, []);
const handleControlModal = useCallback(() => {
controllerRef.current?.requestControl();
}, []);
const handleOk = () => {
controllerRef.current?.sendPermissionRequest(
true,
'switchResult',
);
setIsControlled(false);
2026-05-20 15:12:51 +08:00
setIsModalOpen(false);
};
const handleCancel = () => {
2026-05-20 15:12:51 +08:00
controllerRef.current?.sendPermissionRequest(
false,
'switchResult',
);
setIsControlled(true);
2026-05-20 15:12:51 +08:00
setIsModalOpen(false);
};
const fix2 = (val) => {
if (val === null || val === undefined || isNaN(val)) {
return '-';
}
return Number(val).toFixed(2);
};
// 打点功能
const handleMarkPoint = () => {
if (!realtimePosition) {
2026-08-14 09:02:52 +08:00
message.warning(t('devices.locationFail'));
return;
}
const newPoint = {
lon: Number(realtimePosition.lon),
lat: Number(realtimePosition.lat),
};
setMarkedPoints([...markedPoints, newPoint]);
2026-08-14 09:02:52 +08:00
messageApi.success(t('devices.pointMarked', { count: markedPoints.length + 1 }));
};
2026-08-25 16:54:36 +08:00
// Map click to add marked point
const handleMapMarkPoint = (point) => {
setMarkedPoints([...markedPoints, { lon: Number(point.lon), lat: Number(point.lat) }]);
messageApi.success(t('devices.pointMarked', { count: markedPoints.length + 1 }));
};
// 撤回上一个打点
const handleUndoMark = () => {
if (markedPoints.length === 0) {
message.info(t('devices.noPointsToUndo'));
return;
}
const newPoints = markedPoints.slice(0, -1);
setMarkedPoints(newPoints);
messageApi.success(t('devices.pointUndone', { count: newPoints.length }));
};
// 清空标记点
const handleClearPoints = () => {
setMarkedPoints([]);
setCompleteFlag(false);
setSavePath(null);
2026-08-25 16:54:36 +08:00
clearDrawRef.current?.();
};
2026-08-25 16:54:36 +08:00
const getPathPoints = (coords) => {
console.log("getPathPoints", coords)
//setPathPoints(coords);
if (!coords || coords.length === 0) return;
const newWps = coords.map((p, i) => ({
id: i + 1,
lon: p.lon.toFixed(6),
lat: p.lat.toFixed(6),
}));
console.log("newWps", newWps)
//setWaypoints(newWps);
};
// 完成功能 - 调用路径规划接口
const handleSave = async () => {
if (!plotName.trim()) {
2026-08-14 09:02:52 +08:00
messageApi.warning(t('devices.inputPlotName'));
return;
}
setIsSaving(true);
try {
// ✅重点:接收handleComplete返回的path数据,不再读组件savePath state
const pathResult = await handleComplete();
if (!pathResult) {
messageApi.warning(t('devices.saveFail'));
// 路径规划失败/校验不通过直接终止
return;
}
// 1. 获取地图截图
let screenshotDataUrl = null;
if (mapRef.current) {
screenshotDataUrl = await mapRef.current.captureScreenshot();
}
// 2. 创建 FormData
const formData = new FormData();
// 3. 添加文件
if (screenshotDataUrl) {
// 将 dataUrl 转换为 Blob
const file = dataUrlToFile(screenshotDataUrl, "screenshot.jpg");
console.log("blob", file)
if (file instanceof File) {
formData.append('file', file);
}
}
// 4. 添加 workRecord,直接使用函数返回的 pathResult,不读取state savePath
const workRecord = {
workName: plotName,
siteId: stationId,
orgId: currentStation?.orgId,
jsonData: pathResult, // 直接用返回值,彻底规避state异步延迟
mode: isLoopMode ? "coverage" : "single_point",//"区域还是单点"
};
console.log("workRecord", workRecord)
formData.append(
"workRecord",
new Blob([JSON.stringify(workRecord)], {
type: "application/json"
})
);
// 5. 调用保存接口
const res = await addRoute(formData);
if (res.code === 200) {
2026-08-12 11:29:44 +08:00
messageApi.success(t('common.saveSuccess'));
setIsSaveModalVisible(false);
// 重置状态
setMarkedPoints([]);
setCompleteFlag(false);
setSavePath(null);
} else {
2026-08-12 11:29:44 +08:00
messageApi.error(res.msg || t('common.saveFail'));
}
} catch (error) {
console.error('保存失败:', error);
2026-08-12 11:29:44 +08:00
messageApi.error(t('common.saveFail'));
} finally {
setIsSaving(false);
}
};
/**
* 修改handleComplete:计算完成后 return路径对象;失败返回null
*/
const handleComplete = async () => {
//如果是闭环模式
if (isLoopMode) {
if (markedPoints.length < 3) {
messageApi.warning(t('devices.minThreePoints'));
return null; //校验失败返回null
}
try {
// 准备路径规划请求参数
let positionPoints = [...markedPoints];
// =========新增:保证闭环,第一个点和最后一个点一致=========
const firstPt = positionPoints[0];
const lastPt = positionPoints[positionPoints.length - 1];
// 判断经纬度是否相等,不相等就把首点追加到末尾
if (!(firstPt.lat === lastPt.lat && firstPt.lon === lastPt.lon)) {
positionPoints.push({ ...firstPt });
}
const requestParams = {
outer: {
position: positionPoints.map(point => ({
lat: point.lat,
lng: point.lon,
})),
},
};
const path = requestParams?.outer?.position
setPoints(path);
const resultObj = {
path: path,
outer: requestParams?.outer?.position?.map(p => {
return {
lng: p.lon,
lat: p.lat
}
}),
};
setSavePath(resultObj);
setCompleteFlag(true);
messageApi.success(t('devices.pathPlanDone'));
return resultObj; // ✅返回计算好的数据给上层调用
} catch (error) {
console.error('路径规划失败:', error);
messageApi.error(t('devices.pathPlanFailRetry'));
return null;
}
} else {
// 单点模式
const positionPoints = [...markedPoints].map(item => {
return {
lng: item.lon,
lat: item.lat
}
});
setPoints(positionPoints);
const resultObj = {
path: positionPoints,
outer: [],
};
setSavePath(resultObj);
setCompleteFlag(true);
return resultObj; // ✅返回
}
};
// 打开保存模态框
const handleOpenSaveModal = () => {
//if (!completeFlag) {
// messageApi.warning(t('devices.completePathFirst'));
// return;
//}
setPlotName('');
setIsSaveModalVisible(true);
};
const realtimeType = useMemo(() => {
return isUAV ? 'plane' : 'car';
}, [isUAV]);
2026-05-12 10:34:50 +08:00
if (!device) {
2026-05-20 15:12:51 +08:00
return (
<Empty
2026-08-14 09:02:52 +08:00
description={t('video.selectDevice')}
2026-05-20 15:12:51 +08:00
style={{ marginTop: 100 }}
/>
);
2026-05-12 10:34:50 +08:00
}
2026-05-12 08:48:33 +08:00
2026-05-11 16:34:44 +08:00
return (
2026-08-03 14:38:28 +08:00
<div style={{ background: '#f5f7fa', minHeight: '100%', padding: 0 }}>
<div style={{ padding: '4px 0px 8px' }}>
2026-08-12 11:29:44 +08:00
<Typography.Title level={4} style={{ margin: 0, fontSize: 'clamp(14px, 1.2vw, 18px)' }}>{t('devices.deviceStatus')}</Typography.Title>
2026-08-03 14:38:28 +08:00
</div>
<div style={{ padding: 0 }}>
{contextHolder}
{/* 页面顶部按钮区域 */}
{!isUAV && (
<div
style={{
marginBottom: 8,
padding: '4px 0px',
background: '#f5f7fa',
borderRadius: 8,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 12,
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<Text strong>{t('devices.pathPlanning')}:</Text>
2026-09-02 15:38:05 +08:00
<Text type="secondary">{t('devices.markedPointsCount', { count: markedPoints?.length })}</Text>
2026-08-03 14:38:28 +08:00
</div>
<Space size="middle">
<Space>
2026-08-14 09:02:52 +08:00
<span>{t('devices.workMode')}</span>
2026-08-03 14:38:28 +08:00
<Switch
size="small"
checked={isLoopMode}
onChange={handleChange}
/>
2026-08-14 09:02:52 +08:00
<span>{isLoopMode ? t('devices.bowMode') : t('devices.abMode')}</span>
2026-08-03 14:38:28 +08:00
</Space>
<Button
type="primary"
onClick={handleMarkPoint}
disabled={!realtimePosition}
>
2026-08-14 09:02:52 +08:00
{t('devices.markPoint')}
2026-08-03 14:38:28 +08:00
</Button>
<Button
type="default"
onClick={handleUndoMark}
disabled={markedPoints?.length === 0}
>
{t('devices.undoMark')}
</Button>
2026-08-03 14:38:28 +08:00
<Button
type="default"
onClick={handleClearPoints}
>
2026-08-14 09:02:52 +08:00
{t('devices.clearMarks')}
2026-08-03 14:38:28 +08:00
</Button>
{/*<Button
2026-08-03 14:38:28 +08:00
type="primary"
ghost
onClick={handleComplete}
2026-09-02 15:38:05 +08:00
disabled={markedPoints?.length < 2}
2026-08-03 14:38:28 +08:00
>
2026-08-14 09:02:52 +08:00
{t('devices.complete')}
</Button>*/}
2026-08-03 14:38:28 +08:00
<Button
type="primary"
onClick={handleOpenSaveModal}
//disabled={!completeFlag}
2026-08-03 14:38:28 +08:00
>
2026-08-14 09:02:52 +08:00
{t('common.save')}
2026-08-03 14:38:28 +08:00
</Button>
</Space>
</div>
)}
2026-05-20 15:12:51 +08:00
<div
style={{
2026-06-17 11:14:14 +08:00
marginBottom: 8,
display: 'flex',
alignItems: 'center',
gap: 12,
flexWrap: 'wrap',
}}
>
2026-08-14 09:02:52 +08:00
<Text strong>{t('devices.selectDevice')}:</Text>
2026-08-03 14:38:28 +08:00
<Select
style={{ width: 380, minWidth: 280 }}
value={selectedSn}
onChange={handleDeviceSelectChange}
2026-08-03 14:38:28 +08:00
showSearch
optionFilterProp="label"
2026-08-14 09:02:52 +08:00
placeholder={t('video.selectDevice')}
allowClear={false}
2026-09-02 15:38:05 +08:00
loading={devicesAll?.length === 0}
2026-08-03 14:38:28 +08:00
options={[
{
2026-08-12 11:29:44 +08:00
label: t('devices.robot'),
title: 'robot',
2026-09-02 15:38:05 +08:00
options: devicesAll?.filter(item => !item.gateway_sn && !item.drone_callsign && item.serialNumber).map(item => ({
2026-08-03 14:38:28 +08:00
value: item.device_sn || item.serialNumber,
2026-08-14 09:02:52 +08:00
label: `${item.deviceAlias || item.deviceName || t('devices.unknownDevice')} `,
2026-08-03 14:38:28 +08:00
})),
},
{
2026-08-12 11:29:44 +08:00
label: t('constants.uav'),
title: 'uav',
2026-09-02 15:38:05 +08:00
options: devicesAll?.filter(item => item?.gateway_sn || item?.drone_callsign).map(item => ({
value: item?.device_sn,
label: `${item?.drone_callsign || item?.callsign || t('devices.unknownDrone')}`,
2026-08-03 14:38:28 +08:00
})),
},
2026-09-02 15:38:05 +08:00
].filter(group => group?.options?.length > 0)}
2026-08-03 14:38:28 +08:00
/>
2026-05-20 15:12:51 +08:00
<Tag color={isUAV ? 'cyan' : 'blue'}>
2026-08-12 11:29:44 +08:00
{isUAV ? t('constants.uav') : t('devices.robot')}
2026-08-03 14:38:28 +08:00
</Tag>
2026-05-21 17:04:21 +08:00
<Tag color={device?.onlineStatus == 1 ? 'green' : 'default'}>
2026-08-12 11:29:44 +08:00
{device?.onlineStatus === 1 ? t('devices.online') : t('devices.offline')}
</Tag>
2026-05-11 16:34:44 +08:00
2026-08-03 14:38:28 +08:00
</div>
{/* 无人机专用布局 */}
{isUAV ? (
<Row gutter={[16, 16]} align="stretch">
{/* 左侧:机场视频 + 地图 */}
<Col xs={24} lg={8}>
{/* 无人机场视频 + 机场状态 */}
<Card
title={
<>
<VideoCameraOutlined />
{t('devices.stationVideo')}
2026-08-03 14:38:28 +08:00
</>
}
variant="borderless"
2026-08-03 14:38:28 +08:00
style={{ borderRadius: 12, marginBottom: 8 }}
styles={{ body: { padding: 12 } }}
2026-08-03 14:38:28 +08:00
>
<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 />
2026-08-14 09:02:52 +08:00
{t('devices.situationMap')}
2026-08-03 14:38:28 +08:00
</>
}
extra={
<Space size={4}>
<Button
size="small"
type="primary"
icon={<DeleteOutlined />}
onClick={() => setClearNavLine((v) => v + 1)}
>
2026-08-14 09:02:52 +08:00
{t('devices.clearRealtimeTrack')}
2026-08-03 14:38:28 +08:00
</Button>
<Button
size="small"
danger
icon={<DeleteOutlined />}
onClick={() => {
setPoints([]);
setClearPlanLine((v) => v + 1);
}}
>
{t('devices.clearPlanRoute')}
2026-08-03 14:38:28 +08:00
</Button>
</Space>
}
variant="borderless"
2026-08-03 14:38:28 +08:00
style={{ borderRadius: 12 }}
styles={{ body: { padding: 12, height: 400 } }}
2026-08-03 14:38:28 +08:00
>
<CesiumMap
ref={mapRef}
devices={[mapDevices]}
points={points}
markedPoints={markedPoints}
realtimePosition={realtimePosition}
realtimeType={realtimeType}
2026-08-25 16:54:36 +08:00
onPathChange={getPathPoints}
2026-08-03 14:38:28 +08:00
drawRealTime={true}
finishPoint={arrivedPoint}
ifClearNavLine={clearNavLine}
ifClearPlanLine={clearPlanLine}
2026-08-25 16:54:36 +08:00
from="deviceStatus" onMarkPoint={handleMapMarkPoint} onClearDraw={(fn) => { clearDrawRef.current = fn; }}
/>
2026-08-03 14:38:28 +08:00
</Card>
</Col>
{/* 右侧:无人机视频 + 无人机状态 */}
<Col xs={24} lg={16}>
{/* 无人机视频 + 无人机状态 */}
<Card
title={
<>
<VideoCameraOutlined />
{t('devices.droneVideo')}
2026-08-03 14:38:28 +08:00
</>
}
variant="borderless"
2026-08-03 14:38:28 +08:00
style={{ borderRadius: 12, marginBottom: 8 }}
styles={{ body: { padding: 12 } }}
2026-08-03 14:38:28 +08:00
>
<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]} align="stretch">
<Col xs={24} lg={16}>
<Card
title={
<>
<VideoCameraOutlined />
2026-08-14 09:02:52 +08:00
{t('devices.realtimeVideoMonitor')}
2026-08-03 14:38:28 +08:00
</>
}
variant="borderless"
2026-08-03 14:38:28 +08:00
style={{ borderRadius: 12, marginBottom: 8 }}
styles={{ body: { padding: 12, height: 'calc(100vh - 220px)', minHeight: 500 } }}
2026-08-06 13:39:14 +08:00
extra={
<Button
size="small"
icon={isVideoPlaying ? <PauseOutlined /> : <PlayCircleOutlined />}
onClick={toggleVideoPlay}
>
2026-08-12 11:29:44 +08:00
{isVideoPlaying ? t('video.stop') : t('video.play')}
2026-08-06 13:39:14 +08:00
</Button>
}
2026-08-03 14:38:28 +08:00
>
<Space style={{ marginBottom: 8, }} align="start" >
2026-08-14 09:02:52 +08:00
<Button type={mowerView === 'front' ? 'primary' : 'default'} onClick={() => setMowerView('front')}>{t('devices.frontView')}</Button>
<Button type={mowerView === 'back' ? 'primary' : 'default'} onClick={() => setMowerView('back')}>{t('devices.backView')}</Button>
<Button type={mowerView === 'left' ? 'primary' : 'default'} onClick={() => setMowerView('left')}>{t('devices.leftView')}</Button>
<Button type={mowerView === 'right' ? 'primary' : 'default'} onClick={() => setMowerView('right')}>{t('devices.rightView')}</Button>
<Button type={mowerView === 'all' ? 'primary' : 'default'} onClick={() => setMowerView('all')}>{t('devices.panorama')}</Button>
2026-08-03 14:38:28 +08:00
{mowerView == "all" ? <> <div style={{
background: 'rgba(0,0,0,0.7)',
color: '#fff',
padding: '10px 12px',
borderRadius: 8,
fontSize: 11,
zIndex: 10,
backdropFilter: 'blur(4px)'
}}>
2026-08-14 09:02:52 +08:00
<div style={{ marginBottom: 6, fontWeight: 600, color: '#1890ff' }}>{t('devices.robotStatus')}</div>
2026-08-03 14:38:28 +08:00
<div style={{ display: 'flex', gap: '3px 10px', flexWrap: 'wrap' }}>
2026-09-02 15:38:05 +08:00
<span>{t('devices.rtBattery')}</span>
<span style={{ color: (runningStatus?.battery || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
{runningStatus?.battery !== undefined ? `${runningStatus?.battery}%` : '-'}
2026-08-03 14:38:28 +08:00
</span>
2026-09-02 15:38:05 +08:00
<span>{t('devices.rtVoltage')}</span>
<span>{runningStatus?.voltage !== undefined ? `${Number(runningStatus?.voltage).toFixed(2)}V` : '-'}</span>
<span>{t('devices.rtLeftMotor')}</span>
<span>{runningStatus?.leftCurrent !== undefined ? `${Number(runningStatus?.leftCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtRightMotor')}</span>
<span>{runningStatus?.rightCurrent !== undefined ? `${Number(runningStatus?.rightCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtLeftSpeed')}</span>
<span>{runningStatus?.leftMeasureSpeed !== undefined ? `${Number(runningStatus?.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtRightSpeed')}</span>
<span>{runningStatus?.rightMeasureSpeed !== undefined ? `${Number(runningStatus?.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtLeftTemp')}</span>
<span>{runningStatus?.leftMotorTemp !== undefined ? `${Number(runningStatus?.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtRightTemp')}</span>
<span>{runningStatus?.rightMotorTemp !== undefined ? `${Number(runningStatus?.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtMainTemp')}</span>
<span>{runningStatus?.chipTemp !== undefined ? `${Number(runningStatus?.chipTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtHeadingAngle')}</span>
<span>{runningStatus?.yaw !== undefined ? `${Number(runningStatus?.yaw).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtPitchAngle')}</span>
<span>{runningStatus?.pitch !== undefined ? `${Number(runningStatus?.pitch).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtHeadingStatus')}</span>
<span>{runningStatus?.headingStatus !== undefined ? `${runningStatus?.headingStatus == 1 ? t('devices.rtInitialized') : t('devices.uninitialized')}` : '-'}</span>
<span>{t('devices.rtPositioning')}</span>
2026-08-03 14:38:28 +08:00
<span>
2026-09-02 15:38:05 +08:00
{runningStatus?.qual == 0 ? t('constants.locationInvalid') :
runningStatus?.qual == 1 ? t('devices.gpsSingle') :
runningStatus?.qual == 2 ? t('devices.dgpsDiff') :
runningStatus?.qual == 4 ? t('devices.rtkFixed2') :
runningStatus?.qual == 5 ? t('devices.rtkFloat') : t('constants.locationUnknown')}
2026-08-03 14:38:28 +08:00
</span>
2026-09-02 15:38:05 +08:00
<span>{t('devices.rtSatellites')}</span>
<span>{t('devices.satelliteCount', { count: runningStatus?.satelliteCnt || 0 })}</span>
<span>{t('devices.rtMode')}</span>
2026-08-03 14:38:28 +08:00
<span>
2026-09-02 15:38:05 +08:00
{runningStatus?.controlMode == 1 ? t('devices.localMode') :
runningStatus?.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
2026-08-03 14:38:28 +08:00
</span>
</div>
</div>
</> : null}
</Space>
2026-08-03 14:38:28 +08:00
{/* 视频层:停止时不渲染 / 未播放时为空,不影响状态面板 */}
2026-09-08 15:59:41 +08:00
{isVideoPlaying && (
mowerView === 'all' ? (
2026-09-08 16:09:55 +08:00
(
2026-09-08 15:59:41 +08:00
<div style={{ width: '100%', height: '100%' }}>
<MowerAllView
serialNumber={device?.serialNumber}
robotVideo={robotVideo}
error={error}
ready={ready}
/>
</div>
2026-09-08 16:09:55 +08:00
)
2026-09-08 15:59:41 +08:00
) : mowerView === 'front' ? (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
2026-09-14 09:12:40 +08:00
{/*<AgrtcRoomRobot CHANNEL={device?.serialNumber || ''} />*/}
<AgrtcRoomRobot CHANNEL={"41-thermal"} />
</div>
2026-08-03 14:38:28 +08:00
) : (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
<VideoPlayer
deviceId={device?.serialNumber}
idx={
2026-09-08 15:59:41 +08:00
mowerView === 'back' ? 2
: mowerView === 'left' ? 3
: 4
}
className="w-full h-full object-contain"
video={robotVideo}
error={error}
ready={ready}
/>
</div>
)
)}
{/* 视频未加载 / 停止播放的占位 */}
2026-09-08 16:09:55 +08:00
{!isVideoPlaying && (
<div style={{
width: '100%', height: '100%',
display: 'flex', alignItems: 'center', justifyContent: 'center',
flexDirection: 'column', gap: 12,
color: 'rgba(14, 78, 198, 0.35)',
}}>
<VideoCameraOutlined style={{ fontSize: 56, opacity: 0.6 }} />
<div style={{ fontSize: 15 }}>
2026-08-14 09:02:52 +08:00
{!isVideoPlaying ? t('devices.videoStopped') : t('video.videoLoading')}
</div>
<div style={{ fontSize: 12, opacity: 0.7 }}>
2026-08-14 09:02:52 +08:00
{!isVideoPlaying ? t('devices.clickPlayHint') : ''}
</div>
</div>
)}
{/* 单视频(非全景)模式状态叠加层:始终渲染,和视频层解耦 */}
{mowerView !== 'all' && (
<div style={{
position: 'absolute',
top: 106,
left: 20,
background: 'rgba(0,0,0,0.7)',
color: '#fff',
padding: '10px 12px',
borderRadius: 8,
fontSize: 11,
zIndex: 10,
backdropFilter: 'blur(4px)',
boxShadow: '0 4px 16px rgba(0,0,0,0.4)',
border: '1px solid rgba(24,144,255,0.2)',
}}>
2026-08-14 09:02:52 +08:00
<div style={{ marginBottom: 6, fontWeight: 600, color: '#1890ff' }}>{t('devices.robotStatus')}</div>
<div style={{ display: 'grid', gridTemplateColumns: 'auto auto', gap: '3px 10px' }}>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtBattery')}</span>
2026-09-02 15:38:05 +08:00
<span style={{ color: (runningStatus?.battery || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
{runningStatus?.battery !== undefined ? `${runningStatus?.battery}%` : '-'}
</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtVoltage')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.voltage !== undefined ? `${Number(runningStatus?.voltage).toFixed(2)}V` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtLeftMotor')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.leftCurrent !== undefined ? `${Number(runningStatus?.leftCurrent).toFixed(2)}A` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtRightMotor')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.rightCurrent !== undefined ? `${Number(runningStatus?.rightCurrent).toFixed(2)}A` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtLeftSpeed')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.leftMeasureSpeed !== undefined ? `${Number(runningStatus?.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtRightSpeed')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.rightMeasureSpeed !== undefined ? `${Number(runningStatus?.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtLeftTemp')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.leftMotorTemp !== undefined ? `${Number(runningStatus?.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtRightTemp')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.rightMotorTemp !== undefined ? `${Number(runningStatus?.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtMainTemp')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.chipTemp !== undefined ? `${Number(runningStatus?.chipTemp).toFixed(1)}℃` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtHeadingAngle')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.yaw !== undefined ? `${Number(runningStatus?.yaw).toFixed(1)}°` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtPitchAngle')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.pitch !== undefined ? `${Number(runningStatus?.pitch).toFixed(1)}°` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtHeadingStatus')}</span>
2026-09-02 15:38:05 +08:00
<span>{runningStatus?.headingStatus !== undefined ? `${runningStatus?.headingStatus == 1 ? t('devices.rtInitialized') : t('devices.uninitialized')}` : '-'}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtPositioning')}</span>
<span>
2026-09-02 15:38:05 +08:00
{runningStatus?.fix_status ? fixStatusMap[runningStatus?.fix_status] : t('constants.locationUnknown')}
</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtSatellites')}</span>
2026-09-02 15:38:05 +08:00
<span>{t('devices.satelliteCount', { count: runningStatus?.satelliteCnt || 0 })}</span>
2026-08-14 09:02:52 +08:00
<span>{t('devices.rtMode')}</span>
<span>
2026-09-02 15:38:05 +08:00
{runningStatus?.controlMode == 1 ? t('devices.localMode') :
runningStatus?.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
</span>
</div>
</div>
)
}
2026-08-03 14:38:28 +08:00
</Card>
</Col>
{/* 右边 - 占1格,上部地图,下部远程控制 */}
<Col xs={24} lg={8} style={{ display: 'flex', flexDirection: 'column', }}>
{/* 地图 */}
<Card
title={
<>
<GlobalOutlined />
2026-08-14 09:02:52 +08:00
{t('devices.situationMap')}
2026-08-03 14:38:28 +08:00
</>
}
extra={
<Space size={4}>
<Button
size="small"
type="primary"
icon={<DeleteOutlined />}
onClick={() => setClearNavLine((v) => v + 1)}
>
2026-08-14 09:02:52 +08:00
{t('devices.clearRealtimeTrack')}
2026-08-03 14:38:28 +08:00
</Button>
<Button
size="small"
danger
icon={<DeleteOutlined />}
onClick={() => {
setPoints([]);
setClearPlanLine((v) => v + 1);
}}
>
{t('devices.clearPlanRoute')}
2026-08-03 14:38:28 +08:00
</Button>
</Space>
}
variant="borderless"
2026-08-03 14:38:28 +08:00
style={{ borderRadius: 12, marginBottom: 8, flex: 1, minHeight: 280 }}
styles={{ body: { padding: 12, height: 'calc((100vh - 260px) / 2)', minHeight: 280 } }}
2026-08-03 14:38:28 +08:00
>
<CesiumMap
ref={mapRef}
devices={[mapDevices]}
points={points}
markedPoints={markedPoints}
realtimePosition={realtimePosition}
realtimeType={realtimeType}
drawRealTime={true}
finishPoint={arrivedPoint}
ifClearNavLine={clearNavLine}
ifClearPlanLine={clearPlanLine}
2026-08-25 16:54:36 +08:00
from="deviceStatus" onMarkPoint={handleMapMarkPoint} onClearDraw={(fn) => { clearDrawRef.current = fn; }}
2026-08-03 14:38:28 +08:00
/>
</Card>
{/* 远程控制面板 */}
<Card
title={
<>
<ControlOutlined />
{t('devices.remoteControl')}
2026-08-03 14:38:28 +08:00
</>
}
variant="borderless"
2026-08-03 14:38:28 +08:00
style={{ borderRadius: 12, background: '#0f172a', flex: 1, minHeight: 280, }}
styles={{
header: { color: '#fff', },
body: { display: 'flex', justifyContent: 'center', alignItems: 'center', height: 'calc(100% - 57px)' },
}}
2026-08-03 14:38:28 +08:00
>
<XboxController
onGamepadUpdate={handleGamepadUpdate}
handleControlModal={handleControlModal}
isControlled={isControlled}
hasControlRight={hasControlRight}
isConnecting={connecting}
/>
</Card>
</Col>
</Row>
)}
2026-07-08 10:25:11 +08:00
2026-08-03 14:38:28 +08:00
<Modal
open={isModalOpen}
onOk={handleOk}
onCancel={handleCancel}
2026-09-02 15:38:05 +08:00
title={modalContent?.title}
2026-08-12 11:29:44 +08:00
okText={t('common.ok')}
cancelText={t('common.cancel')}
2026-08-03 14:38:28 +08:00
>
2026-09-02 15:38:05 +08:00
<p>{modalContent?.content}</p>
2026-08-03 14:38:28 +08:00
</Modal>
{/* 保存路径模态框 */}
<Modal
open={isSaveModalVisible}
2026-08-14 09:02:52 +08:00
title={t('devices.savePathTitle')}
2026-08-03 14:38:28 +08:00
onOk={handleSave}
onCancel={() => setIsSaveModalVisible(false)}
2026-08-12 11:29:44 +08:00
okText={t('common.save')}
cancelText={t('common.cancel')}
2026-08-03 14:38:28 +08:00
confirmLoading={isSaving}
>
<div style={{ marginBottom: 16 }}>
2026-08-14 09:02:52 +08:00
<label style={{ display: 'block', marginBottom: 8 }}>{t('devices.plotNameLabel')}</label>
2026-08-03 14:38:28 +08:00
<input
type="text"
value={plotName}
onChange={(e) => setPlotName(e.target.value)}
2026-08-14 09:02:52 +08:00
placeholder={t('devices.inputPlotName')}
2026-08-03 14:38:28 +08:00
style={{
width: '100%',
padding: '8px 12px',
border: '1px solid #d9d9d9',
borderRadius: 4,
fontSize: 14,
}}
/>
</div>
2026-08-03 14:38:28 +08:00
{isSaving && (
<div style={{ textAlign: 'center', padding: '16px 0' }}>
<div style={{
display: 'inline-block',
width: 30,
height: 30,
border: '3px solid #1890ff',
borderTopColor: 'transparent',
borderRadius: '50%',
animation: 'spin 0.8s linear infinite',
}} />
2026-08-14 09:02:52 +08:00
<div style={{ marginTop: 8, color: '#666' }}>{t('devices.saving')}</div>
2026-08-03 14:38:28 +08:00
</div>
)}
<style>
{`
@keyframes spin {
to {
transform: rotate(360deg);
}
}
`}
2026-08-03 14:38:28 +08:00
</style>
</Modal>
</div>
</div >
2026-05-11 16:34:44 +08:00
);
}