有和机器人总览界面
This commit is contained in:
@@ -79,10 +79,11 @@ const taskStatusColor = (status) => {
|
||||
};
|
||||
|
||||
const getDeviceTypeIcon = (type) => {
|
||||
if (type?.includes?.('ROBOT') || type?.includes?.('CLEANING') || type?.includes?.('INSPECT')) {
|
||||
const _t = String(type ?? '').toUpperCase();
|
||||
if (_t == 'I' || _t == 'M' || type?.includes?.('ROBOT') || type?.includes?.('CLEANING') || type?.includes?.('INSPECT')) {
|
||||
return <RobotOutlined />;
|
||||
}
|
||||
if (type?.includes?.('DRONE') || type?.includes?.('UAV')) {
|
||||
if (_t === 'U' || type?.includes?.('DRONE') || type?.includes?.('UAV')) {
|
||||
return <RocketOutlined />;
|
||||
}
|
||||
if (type?.includes?.('CAMERA')) {
|
||||
@@ -305,6 +306,7 @@ const RealTimeMonitorPage = () => {
|
||||
serialNumber: d.device_sn,
|
||||
device_sn: d.device_sn,
|
||||
gateway_sn: d.gateway_sn,
|
||||
deviceType: 'U',
|
||||
type: 'plane',
|
||||
category: 'plane',
|
||||
typeText: t('devices.drone'),
|
||||
@@ -318,7 +320,7 @@ const RealTimeMonitorPage = () => {
|
||||
latitude: lat,
|
||||
lastRunningStatus: (lon && lat) ? { longitude: lon, latitude: lat } : undefined,
|
||||
batteryLevel: d.battery ? d.battery.capacity_percent : undefined,
|
||||
raw: Object.assign({}, d, { type: 'plane', deviceAlias: d.drone_callsign || d.device_sn })
|
||||
raw: Object.assign({}, d, { type: 'plane', deviceType: 'U', deviceAlias: d.drone_callsign || d.device_sn })
|
||||
};
|
||||
});
|
||||
}, [planeDevices, droneMqttMap]);
|
||||
@@ -328,7 +330,7 @@ const RealTimeMonitorPage = () => {
|
||||
id: d.id || idx,
|
||||
name: d.deviceAlias || d.deviceName || `设备-${d.serialNumber?.slice(-4) || idx}`,
|
||||
serialNumber: d.serialNumber,
|
||||
type: d.deviceType || 'ROBOT',
|
||||
type: d.deviceType || (d.type === 'plane' || d.type === 'drone' ? 'U' : 'I'),
|
||||
category: 'robot',
|
||||
typeText: d.deviceTypeName || d.deviceType || t('devices.robot'),
|
||||
status: d.feStatus == 1 ? t('devices.s59') : (d.feStatus == 2 ? t('devices.idle') : t('devices.offline')),
|
||||
@@ -400,8 +402,8 @@ const RealTimeMonitorPage = () => {
|
||||
id: rt.id,
|
||||
name: rt.name || rt.alias || `设备-${String(rt.id).slice(-4)}`,
|
||||
serialNumber: rt.id,
|
||||
deviceType: 'ROBOT',
|
||||
type: 'ROBOT',
|
||||
//deviceType: 'I',
|
||||
//type: 'robot',
|
||||
category: 'robot',
|
||||
typeText: '机器人',
|
||||
status: rt.status,
|
||||
@@ -434,7 +436,7 @@ const RealTimeMonitorPage = () => {
|
||||
// 仅定位设备(不打开抽屉):用于点击表格行
|
||||
const handleLocateDevice = (robot) => {
|
||||
const dev = robot;
|
||||
const isDroneDevice = dev?.type === 'plane' || !!dev?.gateway_sn;
|
||||
const isDroneDevice = dev?.type === 'plane' || !!dev?.gateway_sn || String(dev?.deviceType || '').toUpperCase() === 'U';
|
||||
|
||||
// 1. 优先使用实时经纬度(realtimeMap)
|
||||
const rt = pickRealtimeRecord(realtimeMap, dev);
|
||||
@@ -475,7 +477,7 @@ const RealTimeMonitorPage = () => {
|
||||
setSelectedDeviceSn(dev.serialNumber || dev.device_sn);
|
||||
|
||||
const isMockDevice = dev?.isMock || ['INVERTER', 'COMBINER_BOX', 'WEATHER_STATION', 'METER'].includes(dev?.type);
|
||||
const isDroneDevice = dev?.type === 'plane' || !!dev?.gateway_sn;
|
||||
const isDroneDevice = dev?.type === 'plane' || !!dev?.gateway_sn || String(dev?.deviceType || '').toUpperCase() === 'U';
|
||||
|
||||
// ---- 地图定位 ----
|
||||
handleLocateDevice(dev);
|
||||
@@ -822,7 +824,7 @@ const RealTimeMonitorPage = () => {
|
||||
messageApi.warning(t('devices.selectExecuteDevice'));
|
||||
return;
|
||||
}
|
||||
const isDroneDevice = selectedDevice?.type === 'plane' || !!selectedDevice?.gateway_sn;
|
||||
const isDroneDevice = selectedDevice?.type === 'plane' || !!selectedDevice?.gateway_sn || String(selectedDevice?.deviceType || '').toUpperCase() === 'U';
|
||||
|
||||
// 无人机:调用接口获取实时位置
|
||||
if (isDroneDevice) {
|
||||
@@ -1267,10 +1269,10 @@ const RealTimeMonitorPage = () => {
|
||||
setDeviceDrawerOpen(false); setMqttDrone(null);
|
||||
}}
|
||||
destroyOnClose
|
||||
extra={(selectedDevice?.gateway_sn || selectedDevice?.type === 'plane') ? null : <Button size="small" icon={<SyncOutlined />} onClick={() => { fetchTaskPoolList(selectedDeviceSn); }}></Button>}
|
||||
extra={(selectedDevice?.gateway_sn || selectedDevice?.type === 'plane' || String(selectedDevice?.deviceType || '').toUpperCase() === 'U') ? null : <Button size="small" icon={<SyncOutlined />} onClick={() => { fetchTaskPoolList(selectedDeviceSn); }}></Button>}
|
||||
>
|
||||
{selectedDevice ? (
|
||||
(selectedDevice?.type === 'plane' || selectedDevice?.gateway_sn) ? (
|
||||
(selectedDevice?.type === 'plane' || selectedDevice?.gateway_sn || String(selectedDevice?.deviceType || '').toUpperCase() === 'U') ? (
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
|
||||
<Card
|
||||
|
||||
@@ -185,6 +185,14 @@ const TaskMonitorPage: React.FC = () => {
|
||||
//const timer = setInterval(fetchData, 60000); // 每分钟刷新一次
|
||||
//return () => clearInterval(timer);
|
||||
}, [stationId]);
|
||||
// 实时状态 → 地图设备颜色:1 工作中 green / 2 空闲 blue / 其他(含无实时数据)red
|
||||
const getRealtimeColor = (status: any) => {
|
||||
const s = Number(status);
|
||||
if (s === 1) return 'green';
|
||||
if (s === 2) return 'blue';
|
||||
return 'red';
|
||||
};
|
||||
|
||||
const mapDevices = useMemo(() => {
|
||||
const base = [...devices];
|
||||
const knownKeys = new Set();
|
||||
@@ -192,7 +200,9 @@ const TaskMonitorPage: React.FC = () => {
|
||||
const k = d?.serialNumber ?? d?.device_sn ?? d?.id;
|
||||
if (k != null && k !== '') knownKeys.add(String(k));
|
||||
});
|
||||
const extras = (Array.isArray(realtimeMap) ? realtimeMap : [])
|
||||
// mapPush 推的是 { [设备id]: 实时记录 },同时兼容数组结构
|
||||
const rtList: any[] = Array.isArray(realtimeMap) ? realtimeMap : Object.values(realtimeMap || {});
|
||||
const extras = rtList
|
||||
.filter((rt: any) =>
|
||||
Number.isFinite(Number(rt.lng)) &&
|
||||
Number.isFinite(Number(rt.lat)) &&
|
||||
@@ -203,12 +213,8 @@ const TaskMonitorPage: React.FC = () => {
|
||||
id: rt.id,
|
||||
name: rt.name || rt.alias || `设备-${String(rt.id).slice(-4)}`,
|
||||
serialNumber: rt.id,
|
||||
deviceType: 'ROBOT',
|
||||
type: 'ROBOT',
|
||||
category: 'robot',
|
||||
typeText: '机器人',
|
||||
status: rt.status,
|
||||
onlineStatus: rt.status,
|
||||
color: getRealtimeColor(rt.status),
|
||||
longitude: rt.lng,
|
||||
latitude: rt.lat,
|
||||
heading: rt.yaw,
|
||||
@@ -222,7 +228,42 @@ const TaskMonitorPage: React.FC = () => {
|
||||
lastRunningStatus: { longitude: rt.lng, latitude: rt.lat, heading: rt.yaw, batteryLevel: rt.battery },
|
||||
raw: { ...rt },
|
||||
}));
|
||||
const all = [...base, ...extras];
|
||||
// 关键:把静态列表中已有设备的位置/状态用实时数据覆盖,
|
||||
// 否则 base 里的设备永远只有接口返回的旧坐标,地图实体不会实时动
|
||||
const rtMapDict: any = Array.isArray(realtimeMap)
|
||||
? realtimeMap.reduce((acc: any, r: any, i: number) => { acc[String(r?.id ?? i)] = r; return acc; }, {})
|
||||
: (realtimeMap || {});
|
||||
const baseOverridden = base.map((d) => {
|
||||
const k = String(d?.serialNumber ?? d?.device_sn ?? d?.id ?? "");
|
||||
const rt = rtMapDict[k];
|
||||
if (!rt) return { ...d, color: 'red' };
|
||||
return {
|
||||
...d,
|
||||
longitude: rt.lng ?? d.longitude,
|
||||
latitude: rt.lat ?? d.latitude,
|
||||
heading: rt.yaw ?? d.heading,
|
||||
batteryLevel: rt.battery ?? d.batteryLevel,
|
||||
feStatus: rt.feStatus ?? d.feStatus,
|
||||
status: rt.status ?? d.status,
|
||||
color: getRealtimeColor(rt.status),
|
||||
hasAlarm: !!rt.hasAlarm,
|
||||
taskId: rt.t ?? rt.taskId ?? d.taskId,
|
||||
updateTime: rt.updateTime ?? d.updateTime,
|
||||
locationMessage: {
|
||||
longitude: rt.lng ?? d.locationMessage?.longitude,
|
||||
latitude: rt.lat ?? d.locationMessage?.latitude,
|
||||
heading: rt.yaw ?? d.locationMessage?.heading,
|
||||
batteryLevel: rt.battery ?? d.locationMessage?.batteryLevel,
|
||||
},
|
||||
lastRunningStatus: {
|
||||
longitude: rt.lng ?? d.lastRunningStatus?.longitude,
|
||||
latitude: rt.lat ?? d.lastRunningStatus?.latitude,
|
||||
heading: rt.yaw ?? d.lastRunningStatus?.heading,
|
||||
batteryLevel: rt.battery ?? d.lastRunningStatus?.batteryLevel,
|
||||
},
|
||||
};
|
||||
});
|
||||
const all = [...baseOverridden, ...extras];
|
||||
|
||||
return all.filter((d: any) =>
|
||||
(d?.lastRunningStatus?.latitude && d?.lastRunningStatus?.longitude) ||
|
||||
@@ -230,6 +271,7 @@ const TaskMonitorPage: React.FC = () => {
|
||||
(d?.longitude && d?.latitude)
|
||||
);
|
||||
}, [devices, realtimeMap]);
|
||||
//console.log(mapDevices, "mapDevices")
|
||||
|
||||
// 计算统计数据
|
||||
const taskSummary = useMemo(() => {
|
||||
@@ -250,7 +292,7 @@ const TaskMonitorPage: React.FC = () => {
|
||||
// feStatus: 1=作业中, 2=空闲
|
||||
const working = devices.filter(d => String(d.feStatus) === '1').length;
|
||||
const idle = devices.filter(d => String(d.feStatus) === '2').length;
|
||||
console.log(realtimeMap, "realtimeMap")
|
||||
|
||||
// 告警车辆数量以实时数据里的 hasAlarm 为准
|
||||
const alarmDevices = devices.filter(d => !!pickRealtimeRecord(realtimeMap, d)?.hasAlarm);
|
||||
const alarm = alarmDevices.length;
|
||||
@@ -347,14 +389,15 @@ const TaskMonitorPage: React.FC = () => {
|
||||
{taskPoolList.slice(0, 2).map((task, idx) => (
|
||||
<div key={idx} style={{ background: '#f8faff', padding: '10px 12px', borderRadius: 8, marginBottom: 8, border: '1px solid #e6f7ff' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13, marginBottom: 4 }}>
|
||||
<span style={{ fontWeight: 500, color: '#262626' }}>{task.planName}</span>
|
||||
<span style={{ color: '#1890ff', fontWeight: 600 }}>{Math.floor(Math.random() * 40 + 60)}%</span>
|
||||
<span style={{ fontWeight: 500, color: '#262626' }}>{task.workName}</span>
|
||||
{/*<span style={{ color: '#1890ff', fontWeight: 600 }}>{task.progress}%</span>*/}
|
||||
</div>
|
||||
<Progress percent={Math.floor(Math.random() * 40 + 60)} size="small" showInfo={false} strokeColor="#1890ff" />
|
||||
<div style={{ fontSize: 11, color: '#8c8c8c', marginTop: 4 }}>
|
||||
<Clock size={10} style={{ marginRight: 4 }} />
|
||||
{dayjs(task.createTime).format('YY-MM-DD HH:mm:ss')} 下发
|
||||
{/*<Progress percent={task.progress} size="small" showInfo={false} strokeColor="#1890ff" />*/}
|
||||
<div style={{ fontSize: 11, color: '#8c8c8c', marginTop: 4, display: 'inline-flex', alignItems: 'center', gap: 4 }}>
|
||||
<Clock size={10} />
|
||||
<span>{dayjs(task.createTime).format('YY-MM-DD HH:mm:ss')} 下发</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -486,7 +529,7 @@ const TaskMonitorPage: React.FC = () => {
|
||||
<div className="vehicle-map-popup" role="dialog" aria-label="车辆详情">
|
||||
<div className="vehicle-map-popup__header">
|
||||
<div className="vehicle-map-popup__identity">
|
||||
<Avatar size={38} shape="square" icon={selectedDevice.deviceType === 'UAV' ? <RocketOutlined /> : <RobotOutlined />} style={{ background: '#e6f7ff', color: '#0788ed', borderRadius: 10 }} />
|
||||
<Avatar size={38} shape="square" icon={String(selectedDevice.deviceType || '').toUpperCase() === 'U' ? <RocketOutlined /> : <RobotOutlined />} style={{ background: '#e6f7ff', color: '#0788ed', borderRadius: 10 }} />
|
||||
<div><div className="vehicle-map-popup__title">{selectedDevice.deviceAlias || selectedDevice.deviceName || '车辆'}</div><div className="vehicle-map-popup__serial">{selectedDevice.serialNumber || '--'}</div></div>
|
||||
</div>
|
||||
<Button type="text" size="small" aria-label="关闭车辆详情" icon={<X size={18} />} onClick={() => setSelectedDeviceSerial(null)} />
|
||||
@@ -528,7 +571,7 @@ const TaskMonitorPage: React.FC = () => {
|
||||
<MonitorCard title="实时车辆状态" icon={<Activity size={18} color="#1890ff" />} height="35%">
|
||||
<List
|
||||
size="small"
|
||||
dataSource={devices.filter(d => d.deviceType !== 'CAMERA')}
|
||||
dataSource={devices.filter(d => { const dt = String(d.deviceType || '').toUpperCase(); return dt !== 'CAMERA' && dt !== 'SENSOR' && dt !== 'GATEWAY'; })}
|
||||
renderItem={(item: any) => {
|
||||
const rt = realtimeMap[item.serialNumber] || {};
|
||||
const battery = getDeviceBattery(item);
|
||||
@@ -547,7 +590,7 @@ const TaskMonitorPage: React.FC = () => {
|
||||
setFocusLocation({
|
||||
lon,
|
||||
lat,
|
||||
type: item.deviceType === 'UAV' ? 'drone' : 'robot',
|
||||
type: String(item.deviceType || '').toUpperCase() === 'U' ? 'drone' : 'robot',
|
||||
height: 1000, // 增加高度以实现飞入效果
|
||||
heading: 0,
|
||||
pitch: -45
|
||||
@@ -556,10 +599,10 @@ const TaskMonitorPage: React.FC = () => {
|
||||
}}
|
||||
aria-pressed={selectedDeviceSerial === item.serialNumber}
|
||||
tabIndex={0}
|
||||
onKeyDown={(event: any) => { if (event.key === 'Enter' || event.key === ' ') { setSelectedDeviceSerial(item.serialNumber); const pos = item.lastRunningStatus || item.locationMessage || {}; const lon = Number(pos.longitude ?? pos.lng); const lat = Number(pos.latitude ?? pos.lat); if (Number.isFinite(lon) && Number.isFinite(lat)) setFocusLocation({ lon, lat, type: item.deviceType === 'UAV' ? 'drone' : 'robot', height: 800 }); } }}
|
||||
onKeyDown={(event: any) => { if (event.key === 'Enter' || event.key === ' ') { setSelectedDeviceSerial(item.serialNumber); const pos = item.lastRunningStatus || item.locationMessage || {}; const lon = Number(pos.longitude ?? pos.lng); const lat = Number(pos.latitude ?? pos.lat); if (Number.isFinite(lon) && Number.isFinite(lat)) setFocusLocation({ lon, lat, type: String(item.deviceType || '').toUpperCase() === 'U' ? 'drone' : 'robot', height: 800 }); } }}
|
||||
>
|
||||
<div style={{ display: 'flex', gap: 12, width: '100%' }}>
|
||||
<Avatar shape="square" size={44} icon={item.deviceType === 'UAV' ? <RocketOutlined /> : <RobotOutlined />} style={{ background: '#f0f7ff', color: '#1890ff' }} />
|
||||
<Avatar shape="square" size={44} icon={String(item.deviceType || '').toUpperCase() === 'U' ? <RocketOutlined /> : <RobotOutlined />} style={{ background: '#f0f7ff', color: '#1890ff' }} />
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div
|
||||
style={{
|
||||
@@ -665,7 +708,7 @@ const TaskMonitorPage: React.FC = () => {
|
||||
marginBottom: 8
|
||||
}}>
|
||||
<VideoPlayer
|
||||
deviceId={devices.find(d => d.deviceType === 'ROBOT' || d.deviceType === 'CLEANING')?.serialNumber}
|
||||
deviceId={devices.find(d => { const dt = String(d.deviceType || '').toUpperCase(); return dt === 'I' || dt === 'M'; })?.serialNumber}
|
||||
idx={videoView === 'back' ? 2 : videoView === 'left' ? 3 : videoView === 'right' ? 4 : 1}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user