import React, { useState, useEffect, useMemo } from 'react';
import {
Row, Col, Card, Statistic, Tag, Typography,
Space, Empty, Descriptions, Badge, Progress, Button,
Divider, Select
} from 'antd';
import {
ThunderboltOutlined, DashboardOutlined, AimOutlined,
EnvironmentOutlined, RocketOutlined, GlobalOutlined,
VideoCameraOutlined, ControlOutlined, FullscreenOutlined
} from '@ant-design/icons';
import XboxController from './XboxController';
import DroneLivePlayer from '../VolcRtcPlayer.jsx';
import { getLiveStream } from '../../api/device.ts';
import CesiumMap from '../Map.jsx';
const { Title, Text } = Typography;
// 模拟地图组件
const MockMap = ({ longitude, latitude }) => (
实时坐标
经度: {longitude || '118.78'}
纬度: {latitude || '32.06'}
);
export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceChange }) {
const [planeVideo, setPlaneVideo] = useState([]);
const [isControlled, setIsControlled] = useState(false);
// 获取选中的设备详情
const device = useMemo(() => {
const sn = serialNumber || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
if (!sn) return null;
return devicesAll?.find(d => (d.device_sn || d.serialNumber) == sn);
}, [devicesAll, serialNumber]);
// 判断是否为无人机
const isUAV = useMemo(() => {
return device && (device.device_sn);
}, [device]);
const runningStatus = device?.lastRunningStatus || {};
// 辅助函数:数字格式化
const fix2 = (val) => {
if (val === null || val === undefined || isNaN(val)) return '-';
return Number(val).toFixed(2);
};
// 辅助函数:安全取值
const getVal = (val) => val === "no_rain" ? "无" : (val || '-');
useEffect(() => {
if (!device?.gateway_sn) {
setPlaneVideo([]);
return;
}
const data = {
getway_sn: device?.gateway_sn,
drone_sn: device?.device_sn,
getway_camera_list: device?.gateway_camera_list ?? [],
drone_camera_list: device?.drone_camera_list ?? [],
video_expire: 7200,
quality_type: "adaptive",
}
getLiveStream(data).then(res => {
if (res.code == 200) {
setPlaneVideo(res.data || []);
}
})
}, [device]);
const handleGamepadUpdate = (state) => {
// console.log('Gamepad Update:', state);
};
const handleControlModal = ({ control }) => {
setIsControlled(control);
};
if (!device) {
return ;
}
// 归一化地图显示的设备列表
const mapDevices = useMemo(() => {
if (!device) return [];
// 确保地图组件能正确读取到经纬度
const normalizedDevice = {
...device,
lastRunningStatus: {
...device.lastRunningStatus,
longitude: device.lastRunningStatus?.longitude || device.longitude,
latitude: device.lastRunningStatus?.latitude || device.latitude,
},
name: device.deviceAlias || device.callsign || device.deviceName || '当前设备',
type: isUAV ? 'drone' : (device.productName?.includes('割草机') ? 'mower' : 'robot')
};
return [normalizedDevice];
}, [device, isUAV]);
return (
选择设备:
{/* 左侧:视频和地图 */}
实时视频监控 - {device.deviceAlias || device.callsign || '监控画面'}>}
bordered={false}
style={{ borderRadius: 12, marginBottom: 16 }}
bodyStyle={{ padding: 12 }}
>
1 ? '1fr 1fr' : '1fr',
gridTemplateRows: planeVideo.length > 2 ? '1fr 1fr' : '1fr',
height: 450,
background: '#000',
borderRadius: 8,
overflow: 'hidden'
}}>
{planeVideo.length > 0 ? (
planeVideo.map((stream, index) => (
{stream?.camera_position === 'indoor' ? '库内监控' : `画面 ${index + 1}`}
))
) : (
暂无实时画面
)}
位置态势图>}
bordered={false}
style={{ borderRadius: 12 }}
bodyStyle={{ padding: 12, height: 400 }}
>
{/* 右侧:状态面板和控制 */}
{isUAV ? '无人机状态' : '机器人状态'}详情>}
bordered={false}
style={{ borderRadius: 12, marginBottom: 16 }}
extra={{device.onlineStatus === 1 ? '在线' : '离线'}}
>
{isUAV ? (
/* 无人机特有面板 */
电池电量>}>
飞行高度>}>
{fix2(device.height)} m
{fix2(device.wind_speed)} m/s
{fix2(device.environment_temperature)} ℃
{getVal(device.rainfall)}
{fix2(device.home_distance)} m
{device.position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'}
) : (
/* 机器人特有面板 */
电池电量>}>
系统电压>}>
{runningStatus.voltage || '-'} V
{runningStatus?.leftCurrent || '-'} A
{runningStatus?.rightCurrent || '-'} A
{runningStatus?.leftMeasureSpeed || '-'} A
{runningStatus?.rightMeasureSpeed || '-'} A
{runningStatus?.leftMotorTemp || '-'} ℃
{runningStatus?.rightMotorTemp || '-'} ℃
{runningStatus?.chipTemp || '-'} ℃
{runningStatus?.yaw || '-'}°
{runningStatus?.pitch || '-'}°
)}
{!isUAV && (
远程控制>}
bordered={false}
style={{ borderRadius: 12, background: '#0f172a' }}
headStyle={{ color: '#fff', borderBottom: '1px solid #1e293b' }}
>
请连接 Xbox 控制器并按下任意按键以激活
)}
);
}