@@ -23,6 +23,7 @@ import AgoraTextTest from '../AgoraRtc.tsx';
import { useWebRTCPlayer } from '../useWebRTCStream.tsx' ;
import VideoPlayer from '../VideoPlayer.tsx' ;
import DeviceController from './DeviceController' ;
import AgrtcRoomRobot from '../AgrtcRoomRobot' ;
import CesiumMap from '../Map.jsx' ;
import DeviceParamModal from './DeviceParamModal' ;
@@ -60,6 +61,9 @@ export default function DeviceOverviewPage() {
const [ taskStats , setTaskStats ] = useState ( { completed : 12 , total : 15 } ) ;
const [ deviceStatistics , setDeviceStatistics ] = useState ( null ) ;
const [ currentSelectedRobot , setCurrentSelectedRobot ] = useState ( null ) ;
const [ realtimeMap , setRealtimeMap ] = useState < any > ( { } ) ;
const controllerRef = useRef < DeviceController | null > ( null ) ;
const [ messageApi , contextHolder ] = message . useMessage ( ) ;
// 编辑机器人弹窗相关
const [ editRobotModalOpen , setEditRobotModalOpen ] = useState ( false ) ;
@@ -184,6 +188,16 @@ export default function DeviceOverviewPage() {
} ;
useEffect ( ( ) = > {
if ( ! userInfo || ! stationId ) return ;
const controller = new DeviceController ( userInfo , messageApi , stationId ) ;
controller . initMapPush ( ( rtMap : any ) = > setRealtimeMap ( rtMap || { } ) ) ;
controllerRef . current = controller ;
return ( ) = > {
if ( controllerRef . current ) controllerRef . current . closeMapPush ( ) ;
} ;
} , [ userInfo , stationId ] ) ;
useEffect ( ( ) = > {
fetchAllData ( ) ;
} , [ stationId ] ) ;
@@ -280,16 +294,25 @@ export default function DeviceOverviewPage() {
return { . . . selectedDevice } ;
} , [ selectedDevice ] ) ; // 只有切设备才变 → 视频不闪
// ======================== UI显示用( MQTT实时更新) ========================
// ======================== UI显示用( MQTT/WS 实时更新)========================
const realtimeDevice = useMemo ( ( ) = > {
if ( ! selectedDevice ) return null ;
const sn = selectedDevice . device_sn || selectedDevice . serialNumber ;
const wsData = realtimeMap [ sn ] || { } ;
setDeviceStatistics ( wsData || { } )
return {
. . . selectedDevice ,
. . . uavState ,
. . . persistentHostData ,
. . . persistentDroneData ,
. . . wsData ,
// 统一字段名
capacity_percent : wsData.battery_level || persistentDroneData ? . capacity_percent || selectedDevice . capacity_percent || 100
} ;
} , [ selectedDevice , uavState , persistentHostData , persistentDroneData ? . wind_speed ] ) ;
} , [ selectedDevice , uavState , persistentHostData , persistentDroneData , realtimeMap ] ) ;
// MQTT消息处理
const handleMqttMessage = useCallback ( ( topic , message ) = > {
@@ -454,19 +477,25 @@ export default function DeviceOverviewPage() {
//feStatus; 1任务中 / 2空闲
const dynamicTopCards = useMemo ( ( ) = > {
const totalDrones = planedevices ? . length || 0 ;
const onlineDrones = planedevices ? . filter ( d = > d . onlineStatus === 1 ) . length || 0 ;
const totalRobots = 1 ;
//const totalRobots = devicesAll?.filter(d => d.productName?.includes(t('constants.inspection'))).length || 0;
//key 0 有任务 1 无任务
const activ eRobots = 0 ;
const totalMowers = 1 ;
// const totalMowers = devicesAll?.filter(d => d.productName?.includes(t('constants.mower'))).length || 0;
const activeMowers = devices ? . filter ( d = > d . f eStatus == 1 ) . length || 0 ; // 作业中状态数量
const washDroneStandby = planedevices ? . [ 0 ] ? . modeStatistics ? . [ "0" ] || 0 ;
//key 设备状态:{"0":"空闲中","1":"现场调试","2":"远程调试","3":"固件升级中","4":"作业中"}
const onlineDrones = planedevices ? . filter ( d = > {
const rt = realtimeMap [ d . device_sn ] ;
return rt ? rt . status !== 'OFFLINE' : d . onlineStatus === 1 ;
} ) . length || 0 ;
const totalRobots = devices ? . filter ( d = > ! d . gateway_sn ) . length || 0 ;
const onlin eRobots = devices ? . filter ( d = > {
if ( d . gateway_sn ) return false ;
const rt = realtimeMap [ d . serialNumber ] ;
return rt ? rt . status !== 'OFFLINE' : d . onlin eStatus === 1 ;
} ) . length || 0 ;
const activeMowers = devices ? . filter ( d = > {
const rt = realtimeMap [ d . serialNumber ] ;
return rt ? rt . status === 'EXECUTING' : d . feStatus == 1 ;
} ) . length || 0 ;
const washDroneStandby = planedevices ? . filter ( d = > {
const rt = realtimeMap [ d . device_sn ] ;
return rt ? rt . status === 'IDLE' : true ; // 简化逻辑
} ) . length || 0 ;
// 今日任务执行统计
const completedTasks = taskStats . completed ;
@@ -485,15 +514,15 @@ export default function DeviceOverviewPage() {
{
title : t ( 'home.inspectionRobot' ) ,
icon : < RobotOutlined style = { { color : '#13c2c2' , fontSize : 24 } } / > ,
value : ` ${ total Robots} ${ t( 'devices.Units Robot' ) } ` ,
sub : ` ${ t ( 'devices.execut ing ' ) } ${ activ eRobots} ` ,
value : ` ${ online Robots} / ${ total Robots } ` ,
sub : ` ${ t ( 'devices.onl ine ' ) } ${ onlin eRobots} ` ,
color : '#13c2c2' ,
iconBg : '#E6FFFA'
} ,
{
title : t ( 'devices.mowingRobot' ) ,
icon : < CarOutlined style = { { color : '#722ED1' , fontSize : 24 } } / > ,
value : ` ${ totalMower s } ${ t ( 'devices.UnitsRobot' ) } ` ,
value : ` ${ totalRobot s } ${ t ( 'devices.UnitsRobot' ) } ` ,
sub : ` ${ t ( 'devices.executing' ) } ${ activeMowers } ` ,
color : '#722ED1' ,
iconBg : '#F9F0FF'
@@ -506,14 +535,6 @@ export default function DeviceOverviewPage() {
color : '#eb2f96' ,
iconBg : '#FFF1F3'
} ,
//{
// title: t('devices.fixed2DeviceBatteryFixed2'),
// icon: <ThunderboltOutlined style={{ color: '#52c41a', fontSize: 24 }} />,
// value: `${finalAvgBattery}%`,
// sub: '',
// color: '#52c41a',
// iconBg: '#E8FFEA'
//},
{
title : t ( 'devices.todayTaskExecute' ) ,
icon : < CheckCircleOutlined style = { { color : '#2f54eb' , fontSize : 24 } } / > ,
@@ -523,24 +544,31 @@ export default function DeviceOverviewPage() {
iconBg : '#E8F3FF'
} ,
] ;
} , [ devicesAll , planedevices , persistentDroneData , uavState , taskStats ] ) ;
} , [ devices , planedevices , realtimeMap , taskStats ] ) ;
// 设备调度列表
const dynamicScheduleList = useMemo ( ( ) = > {
return devicesAll ? . map ( ( d , index ) = > ( {
. . . d ,
id : d.deviceId || index ,
name : d.deviceAlias || d . deviceName || d . callsign || '未知设备' ,
type : d . deviceType || "割草机" ,
status : d.onlineStatus === 1 ? t ( 'devices.online' ) : t ( 'devices.offline' ) ,
mode : d.feStatus == 1 ? '作业中' : d . feStatus == 2 ? t ( 'devices.idle' ) : d . mode_code == 0 ? t ( 'devices.idle' ) : d . mode_code == 1 ? '现场调试' : d . mode_code == 2 ? '远程调试' : d . mode_code == 3 ? '固件升级中' : '作业中' ,
capacity_percent : d.capacity_percent || 100 ,
position : d.position || '站内' ,
task : d.status === 4 ? '待命' : '作业中' ,
comm : d.rssi ? ` ${ d . rssi } dBm ` : '良好' ,
return devicesAll ? . map ( ( d , index ) = > {
const sn = d . serialNumber || d . device_sn ;
const rt = realtimeMap [ sn ] || { } ;
const online = rt . status !== undefined ? ( rt . status !== 'OFFLINE' ? 1 : 0 ) : d . onlineStatus ;
} ) ) || [ ] ;
} , [ devicesAll ] ) ;
return {
. . . d ,
id : d.deviceId || index ,
name : d.deviceAlias || d . deviceName || d . callsign || '未知设备' ,
type : d . deviceType || "割草机" ,
status : online === 1 ? t ( 'devices.online' ) : t ( 'devices.offline' ) ,
onlineStatus : online ,
mode : rt.status === 'EXECUTING' ? '作业中' : rt . status === 'IDLE' ? t ( 'devices.idle' ) : ( d . feStatus == 1 ? '作业中' : d . feStatus == 2 ? t ( 'devices.idle' ) : '离线' ) ,
capacity_percent : rt.battery || d . capacity_percent || 100 ,
position : rt.position || d . position || '站内' ,
task : rt.currentTaskName || d . task || ( d . status === 4 ? '待命' : '作业中' ) ,
comm : rt.rssi ? ` ${ rt . rssi } dBm ` : ( d . rssi ? ` ${ d . rssi } dBm ` : '良好' ) ,
work_area : rt.work_area || 0
} ;
} ) || [ ] ;
} , [ devicesAll , realtimeMap ] ) ;
const handleStart = ( ) = > message . success ( t ( 'devices.fixed2TaskSuspended22' ) ) ;
const handlePause = ( ) = > message . info ( t ( 'devices.taskPaused' ) ) ;
@@ -653,7 +681,7 @@ export default function DeviceOverviewPage() {
< / div >
< / Card >
< Card title = { < > < SettingOutlined / > { t ( 'devices.fixed2EquipmentListFixed2' ) } < / > } variant = "borderless" style = { { borderRadius : 8 , marginBottom : 8 } } >
< Card title = { < > < SettingOutlined / > { t ( 'devices.fixed2EquipmentListFixed2' ) } < / > } extra = { < Button type = "text" icon = { < ReloadOutlined / > } onClick = { fetchAllData } / > } variant = "borderless" style = { { borderRadius : 8 , marginBottom : 8 } } >
< Table rowKey = { ( record ) = > record . id || record . serialNumber || record . device_sn } size = "small" pagination = { false }
columns = { [
{ title : t ( 'devices.fixed2EquipmentFixed2NameFixed2' ) , dataIndex : 'name' , width : 180 } ,
@@ -693,8 +721,9 @@ export default function DeviceOverviewPage() {
/ > ;
}
} , { title : t ( 'aiAnalysis.location' ) , dataIndex : 'position' , width : 90 } ,
//{ title: '累计作业面积', dataIndex: 'work_area', width: 110, render: v => `${Number(v || 0).toFixed(2)} ㎡` },
//{ title: t('devices.fixed2CurrentFixed2TaskSuspended2Fixed2'), dataIndex: 'task', width: 100 },
{ title : t ( 'devices.statusFixed2' ) , dataIndex : 'comm' , width : 100 , render : v = > < Badge status = { v . includes ( '-' ) ? 'warning' : 'success' } text = { v } / > } ,
{ title : t ( 'devices.statusFixed2' ) , dataIndex : 'comm' , width : 100 , render : v = > < Badge status = { v && v . includes ( '-' ) ? 'warning' : 'success' } text = { v } / > } ,
{
title : t ( 'roles.actions' ) ,
key : 'action' ,