有和机器人总览界面

This commit is contained in:
mmc
2026-11-12 09:59:37 +08:00
parent ce9f52fc52
commit 943d6138cd
14 changed files with 438 additions and 225 deletions

View File

@@ -3,7 +3,8 @@ import {
Layout, Card, Row, Col, Statistic, Tag, Button, Table,
Typography, Space, Progress, Badge, Timeline, message,
Select, Modal, Space as AntSpace,
Input, Tooltip
Input, Tooltip,
Empty
} from 'antd';
import {
EnvironmentOutlined, RobotOutlined, BranchesOutlined,
@@ -28,6 +29,9 @@ import AgrtcRoomRobot from '../AgrtcRoomRobot';
import CesiumMap from '../Map.jsx';
import DeviceParamModal from './DeviceParamModal';
import { getUAVState, getSiteDevice, getSiteUAVList, getsinglePlan, getRobotTaskList, getDeviceTotalData, updateDeviceAliasApi, hasPermission } from '@/api/device.ts';
import { getAlarmList } from '@/api/alarmApi.js';
import dayjs from 'dayjs';
import { useMqtt } from '@/hooks/useMqtt';
import { useSelector } from 'react-redux';
@@ -37,6 +41,8 @@ import utils from '@/lib/utils.ts';
import { useUnitFormatter } from '@/lib/units';
import { useTranslation } from 'react-i18next';
import { sendEmergencyStop } from './emergencyStopControl';
import AlarmLevelTag from '../AlarmLevelTag.tsx';
import { getDeviceTastPool } from '@/api/device.ts';
const { Content } = Layout;
const { Text, Title } = Typography;
@@ -64,6 +70,8 @@ export default function DeviceOverviewPage() {
const [realtimeMap, setRealtimeMap] = useState<any>({});
const controllerRef = useRef<DeviceController | null>(null);
const [messageApi, contextHolder] = message.useMessage();
const [taskList, setTaskList] = useState<any[]>([]);
const [alarmList, setAlarmList] = useState<any[]>([]);
// 编辑机器人弹窗相关
const [editRobotModalOpen, setEditRobotModalOpen] = useState(false);
@@ -77,15 +85,9 @@ export default function DeviceOverviewPage() {
const navigate = useNavigate();
const [robotPlayActive, setRobotPlayActive] = useState<boolean>(false);
const [taskPoolList, setTaskPoolList] = useState<any[]>([]);
const logs = [
{ time: '10:24:35', device: 'UAV-C01', type: '命令', desc: '起飞指令下发,开始作业' },
{ time: '10:21:40', device: 'RBT-01', type: '命令', desc: '开始巡检任务 P-02' },
{ time: '10:20:11', device: 'UAV-C02', type: '命令', desc: '转入待命状态' },
{ time: '10:18:05', device: 'GR-02', type: '命令', desc: '除草作业开始 G-01' },
{ time: '10:12:35', device: 'UAV-C01', type: t('constants.sourceAlert'), desc: '返航补水' },
{ time: '10:05:22', device: 'RBT-01', type: '事件', desc: '电量较低,建议回充', level: '低电量' },
];
const taskTimeline = [
{ time: '10:24:18', color: 'blue', text: t('devices.uavC01ExecuteFixed2CleaningC05'), status: '任务开始' },
{ time: '10:21:35', color: 'orange', text: t('devices.rbt01ExecuteFixed2InspectionP02'), status: '任务开始' },
@@ -94,6 +96,35 @@ export default function DeviceOverviewPage() {
{ time: '10:12:33', color: 'blue', text: t('devices.uavC01'), status: '返机补给' },
{ time: '09:58:10', color: 'green', text: t('devices.rbt02CompleteFixed2InspectionP01'), status: '任务完成' },
];
const fetchTaskPoolList = async () => {
if (!stationId) return;
try {
const params = {
userId: userInfo?.userId,
siteId: stationId,
orgId: currentStation?.orgId,
pageNum: 1,
pageSize: 10
};
const res = await getDeviceTastPool(params);
if (res.code === 200) {
const list = res.rows || [];
list.map(item => {
return {
time: dayjs(item.createTime).format('HH:mm:ss'),
color: item.taskStaus === 'EXECUTING' ? 'green' : 'blue',
text: item.workName || t('devices.unnamedTask'),
status: item.taskStaus === 'EXECUTING' ? t('devices.executing') : item.taskStaus === 'FAILED' ? t('devices.executeFail') : item.taskStaus === 'COMPLETED' ? t('devices.statusFinished') : item.taskStaus === 'CANCELED' ? t('devices.taskCanceled') : t('devices.taskStatusNew')
}
})
setTaskPoolList(list);
}
} catch (err) {
console.error('获取任务池失败:', err);
}
};
@@ -200,6 +231,8 @@ export default function DeviceOverviewPage() {
useEffect(() => {
fetchAllData();
fetchAlarmList();
fetchTaskPoolList();
}, [stationId]);
useEffect(() => {
fetchTaskStats();
@@ -241,6 +274,7 @@ export default function DeviceOverviewPage() {
try {
const robotRes = await getRobotTaskList({ siteId: String(stationId) });
if (robotRes?.code == 200 && robotRes.data) {
setTaskList(robotRes?.data?.slice(0, 5) ?? []);
const todayRobotTasks = robotRes.data.filter((t: any) => {
// 简单判断是今日的任务
if (t.createTime) {
@@ -268,6 +302,7 @@ export default function DeviceOverviewPage() {
}
};
// 当前选中设备(切换时才变)
const selectedDevice = useMemo(() => {
const sn = currentSelectedRobot || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
@@ -472,6 +507,19 @@ export default function DeviceOverviewPage() {
})
}
const fetchAlarmList = async () => {
try {
const res = await getAlarmList({ pageNum: 1, pageSize: 5, siteId: stationId });
if (res.code === 200) {
setAlarmList(res.rows?.slice(0, 5) ?? []);
}
} catch (err) {
messageApi.error(t('common.loadFailed'));
} finally {
}
};
// 顶部统计卡片
//feStatus; 1任务中 / 2空闲
@@ -685,17 +733,26 @@ export default function DeviceOverviewPage() {
<Table rowKey={(record) => record.id || record.serialNumber || record.device_sn} size="small" pagination={false}
columns={[
{ title: t('devices.fixed2EquipmentFixed2NameFixed2'), dataIndex: 'name', width: 180 },
{ title: t('common.type'), dataIndex: 'type', },
{
title: t('workOrder.currentStatus'),
dataIndex: 'onlineStatus',
width: 70,
render: (s) => {
const text = s === 1 ? t('devices.online') : t('devices.offline');
const color = s === 1 ? 'success' : 'default';
return <Tag color={color} style={{ margin: 0 }}>{text}</Tag>;
title: t('common.type'), dataIndex: 'deviceType',
render: (text, record) => {
if (record.deviceType == "U") return t('devices.uav');
if (record.deviceType == "M") return t("devices.mower");
if (record.deviceType == "I") return t("devices.robot");
return record.deviceType || record.type || t('devices.robot');
}
}, {
},
//{
// title: t('workOrder.currentStatus'),
// dataIndex: 'onlineStatus',
// width: 70,
// render: (s) => {
// const text = s === 1 ? t('devices.online') : t('devices.offline');
// const color = s === 1 ? 'success' : 'default';
// return <Tag color={color} style={{ margin: 0 }}>{text}</Tag>;
// }
//},
{
title: t('workOrder.currentStatus'), dataIndex: 'feStatus', width: 70, render: (text) => {
let color;
if (text == '1') color = 'processing';
@@ -757,19 +814,100 @@ export default function DeviceOverviewPage() {
scroll={{ x: 'max-content', y: 280 }}
/>
</Card>
<Row wrap={false} gutter={16} style={{ width: '100%' }}>
<Col flex="1 1 0">
<Card
title={<>
<SettingOutlined /> <span>{t('devices.TaskLog')}</span>
</>}
variant="borderless"
style={{ borderRadius: 8, height: '100%' }}
>
<Table
rowKey="time"
size="small"
pagination={false}
dataSource={taskList}
scroll={{ x: 'max-content' }}
columns={[
{ title: t('common.createTime'), dataIndex: 'time', width: 90, render: (v) => <span style={{ fontSize: 13 }}>{v}</span> },
{ title: t('devices.deviceId'), dataIndex: 'device', width: 100, render: (v) => <span style={{ fontSize: 13 }}>{v}</span> },
{
title: t('devices.deviceType'),
dataIndex: 'type',
width: 70,
render: (v) => {
let c = '#52c41a';
let text = ''
if (v === 'I') { c = '#fa8c16'; text = t('devices.robot') }
if (v === 'M') { c = '#1890ff'; text = t('devices.mower') }
if (v === 'U') { c = '#1890ff'; text = t('devices.uav') }
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
<span style={{ width: 10, height: 10, borderRadius: 2, background: c }} />
<span style={{ fontSize: 13 }}>{text}</span>
</div>
);
}
},
{ title: t('devices.taskName'), dataIndex: 'planName' },
]}
/>
<div style={{ textAlign: 'center', marginTop: 8 }}>
<Button type="link" size="small" style={{ fontSize: 13, color: '#1890ff' }} onClick={() => navigate('/devices/robotTask')}>
{t('devices.viewMoreLogs')}
</Button>
</div>
</Card>
</Col>
<Col flex="1 1 0">
<Card
title={<>
<SettingOutlined /> <span>{t('devices.AlertRecord')}</span>
</>}
variant="borderless"
style={{ borderRadius: 8, height: '100%' }}
extra={
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<Button size="small" style={{ borderRadius: 4, border: '1px solid #d9d9d9' }}>
{t('devices.fixed2AllLevels')}
</Button>
</div>
}
>
<Table
rowKey="time"
size="small"
pagination={false}
dataSource={alarmList}
scroll={{ x: 'max-content' }}
columns={[
{ title: t('common.time'), dataIndex: 'alertTime', width: 90, render: (v) => <span style={{ fontSize: 13 }}>{v}</span> },
{ title: t('devices.device'), dataIndex: 'deviceName', width: 100, render: (v) => <span style={{ fontSize: 13 }}>{v}</span> },
{
title: t('alerts.alarmTitle'),
dataIndex: 'alarmTitle',
width: 70,
},
{
title: t('alerts.alertLevel'), dataIndex: 'alertLevel', render: (l) => <AlarmLevelTag level={l} size="small" />
},
{ title: '', width: 70, render: (_, record) => record.level ? <Tag color="red" style={{ fontSize: 11, margin: 0 }}>{record.level}</Tag> : null }
]}
/>
<div style={{ textAlign: 'center', marginTop: 8 }}>
<Button type="link" size="small" style={{ fontSize: 13, color: '#1890ff' }} onClick={() => navigate('/alerts/all')}>
{t('devices.viewMoreLogs')}
</Button>
</div>
</Card>
</Col>
</Row>
<Card title={<><SettingOutlined /> <span >{t('devices.fixed2ControlFixed2LogDesc6Alert')}</span></>} variant="borderless" style={{ borderRadius: 8 }} extra={<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Button size="small" style={{ borderRadius: 4, border: '1px solid #d9d9d9' }}>{t('devices.fixed2AllLevels')}</Button></div>}>
<Table rowKey="time" size="small" pagination={false} dataSource={logs} scroll={{ x: 'max-content' }}
columns={[
{ title: t('common.time'), dataIndex: 'time', width: 90, render: t => <span style={{ fontSize: 13 }}>{t}</span> },
{ title: t('devices.device'), dataIndex: 'device', width: 100, render: t => <span style={{ fontSize: 13 }}>{t}</span> },
{ title: t('common.type'), dataIndex: 'type', width: 70, render: r => { let c = '#52c41a'; if (r === t('constants.sourceAlert')) c = '#fa8c16'; if (t === 'events') c = '#1890ff'; return <div style={{ display: 'flex', alignItems: 'center', gap: 4 }}><span style={{ width: 10, height: 10, borderRadius: 2, background: c }} /><span style={{ fontSize: 13 }}>{t}</span></div> } },
{ title: t('common.description'), dataIndex: 'desc', render: t => <span style={{ fontSize: 13 }}>{t}</span> },
{ title: '', width: 70, render: (_, r) => r.level ? <Tag color="red" style={{ fontSize: 11, margin: 0 }}>{r.level}</Tag> : null }
]}
/>
<div style={{ textAlign: 'center', marginTop: 8 }}><Button type="link" size="small" style={{ fontSize: 13, color: '#1890ff' }}>{t('devices.viewMoreLogs')}</Button></div>
</Card>
</Col>
<Col xs={24} lg={10}>
@@ -798,7 +936,7 @@ export default function DeviceOverviewPage() {
<Col span={12}>
<div style={{ marginBottom: 12 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 12, flexWrap: "wrap" }}>
{selectedDevice.deviceType === 'drone' || selectedDevice.deviceName?.includes(t('constants.uav')) || selectedDevice.drone_callsign ? (
{String(selectedDevice.deviceType || '').toUpperCase() === 'U' || selectedDevice.deviceName?.includes(t('constants.uav')) || selectedDevice.drone_callsign ? (
<span style={{ fontSize: 20, color: '#1890ff' }}><RocketOutlined /></span>
) : (
<span style={{ fontSize: 20, color: '#1890ff' }}><CarOutlined /></span>
@@ -995,7 +1133,7 @@ export default function DeviceOverviewPage() {
)}
</Card>
<Card title={<><ApiOutlined />{t('devices.fixed2AiActions')}</>} variant="borderless" style={{ borderRadius: 12, marginBottom: 8 }}>
{/*<Card title={<><ApiOutlined />{t('devices.fixed2AiActions')}</>} variant="borderless" style={{ borderRadius: 12, marginBottom: 8 }}>
<Row gutter={16} style={{ marginBottom: 8 }}>
<Col span={6}><div style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '6px 12px 4px', borderRadius: 12, border: '1px solid #e8e8e8' }}><div style={{ width: 30, height: 30, borderRadius: '50%', background: 'rgba(255,77,79,0.15)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#ff4d4f', fontSize: 20 }}><span role="img" aria-label="hotspot">🔥</span></div><div><div style={{ fontSize: 11, color: '#666' }}>{t('devices.hotspotSuspect')}</div><div style={{ fontSize: 22, fontWeight: 700, color: '#222' }}>2 <span style={{ fontSize: 12 }}>{t('devices.s32')}</span></div></div></div></Col>
<Col span={6}><div style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '6px 12px 4px', borderRadius: 12, border: '1px solid #e8e8e8' }}><div style={{ width: 30, height: 30, borderRadius: '50%', background: 'rgba(82,196,26,0.15)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#52c41a', fontSize: 16 }}><BranchesOutlined /></div><div><div style={{ fontSize: 11, color: '#666' }}>{t('devices.s33')}</div><div style={{ fontSize: 22, fontWeight: 700, color: '#222' }}>3 <span style={{ fontSize: 12 }}>{t('devices.s34')}</span></div></div></div></Col>
@@ -1023,7 +1161,7 @@ export default function DeviceOverviewPage() {
</div>
</Col>
</Row>
</Card>
</Card>*/}
{(selectedDevice?.productName?.includes(t('constants.uav')) || selectedDevice?.device_sn) && (
<Card title={t('devices.s60')} variant="borderless" style={{ borderRadius: 12, marginBottom: 8 }}>
@@ -1110,15 +1248,20 @@ export default function DeviceOverviewPage() {
)}
<Card title={<><ClockCircleOutlined />{t('devices.fixed2TaskSuspended2Fixed2ExecutionTime')}</>} variant="borderless" style={{ borderRadius: 12 }} extra={<div style={{ fontSize: 12, color: '#666' }}></div>}>
<Timeline mode="left">
{taskTimeline.map((item, idx) => (
<Timeline.Item key={idx} color={item.color} label={<div style={{ fontSize: 11, color: '#999' }}>{item.time}</div>}>
<div style={{ fontSize: 13 }}>{item.text}</div>
<div style={{ fontSize: 11, color: '#999' }}>{item.status}</div>
</Timeline.Item>
))}
</Timeline>
<div style={{ textAlign: 'center', marginTop: 12 }}><Button type="link">{t('devices.viewMore')}</Button></div>
{taskPoolList.length > 0 ? (
<Timeline mode="left">
{taskPoolList.map((item, idx) => (
<Timeline.Item key={idx} color={item.color} label={<div style={{ fontSize: 11, color: '#999' }}>{item.time}</div>}>
<div style={{ fontSize: 13 }}>{item.text}</div>
<div style={{ fontSize: 11, color: '#999' }}>{item.status}</div>
</Timeline.Item>
))}
</Timeline>
) : (
<Empty description={t('common.noData')} style={{ marginTop: 100 }} />
)}
<div style={{ textAlign: 'center', marginTop: 12 }}><Button type="link" onClick={() => navigate('/devices/robotTask')}>{t('devices.viewMore')}</Button></div>
</Card>
</Col>
</Row>

View File

@@ -236,7 +236,7 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
};
const renderVideo = (type: 'drone' | 'station', streamData: any, loading: boolean) => {
const isDrone = type === 'drone';
const isDrone = String(type || '').toUpperCase() === 'U' || type === 'drone';
const currentDisplayType = displayType || type;
const data = statusData;

View File

@@ -45,6 +45,8 @@ type MapEditorExtraMapProps = {
routeMode?: string;
realtimePosition?: any;
realtimeType?: string;
/** 选中机器人的实时状态颜色:green 工作中 / blue 空闲 / red 离线 */
deviceColor?: 'red' | 'green' | 'blue';
ifClearNavLine?: number;
ifClearPlanLine?: number;
focusOverlay?: any;
@@ -180,10 +182,10 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
const selectRobot = useMemo(() => {
if (!Array.isArray(robots)) return [];
return robots.filter(
robot => robot.serialNumber == selectedRobotId
);
}, [selectedRobotId, robots]);
return robots
.filter(robot => robot.serialNumber == selectedRobotId)
.map(robot => (extraMapProps?.deviceColor ? { ...robot, color: extraMapProps.deviceColor } : robot));
}, [selectedRobotId, robots, extraMapProps?.deviceColor]);
useEffect(() => {
if (extraMapProps.polyPoints?.length > 0) {
setPolyPoints(extraMapProps.polyPoints);

View File

@@ -226,7 +226,6 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
const handleFinish = (data) => {
console.log('任务完成回调', data);
setExecute(false);
setShowVideo(false); // 任务完成关闭视频
utils.message.success(t('devices.fixed2TaskSuspended2Fixed2CompletedFixed2', { deviceId: data.deviceId }));
@@ -436,6 +435,14 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
};
}, [realtimeMap, targetRobot]);
// 实时状态 → 地图设备颜色:1 工作中 green / 2 空闲 blue / 其他及无实时数据 red
const robotMapColor = useMemo(() => {
const s = Number(robotRealtimePosition?.status);
if (s === 1) return 'green';
if (s === 2) return 'blue';
return 'red';
}, [robotRealtimePosition]);
const realtimePosition = useMemo(() => {
let lon = robotRealtimePosition?.longitude;
let lat = robotRealtimePosition?.latitude;
@@ -759,6 +766,8 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
return aEmpty ? -1 : bEmpty ? 1 : 0;
});
setTaskPoolList(list);
if (list?.length == 0) setExecute(false);
}
} catch (err) {
console.error('获取任务池失败:', err);
@@ -1699,7 +1708,8 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
polyPoints,
routeMode,
realtimePosition,
realtimeDevice: targetRobot,
realtimeDevice: targetRobot ? { ...targetRobot, color: robotMapColor } : targetRobot,
deviceColor: robotMapColor,
realtimeType: 'robot',
ifClearNavLine: clearNavLine,
ifClearPlanLine: clearPlanLine,

View File

@@ -122,7 +122,7 @@ export default class DeviceController {
let msg = null;
try { msg = JSON.parse(event.data); } catch (e) { return; }
console.log('[DeviceController] 收到全量设备状态 初始状态', msg);
//console.log('[DeviceController] 收到全量设备状态 初始状态', msg);
if (msg?.type == 'mapPush') {
const list = Array.isArray(msg?.data) && msg.data.length
? msg.data
@@ -160,7 +160,7 @@ export default class DeviceController {
console.log('task finish');
this.onIsFinished?.(msg);
}
if (msg.status == "EXECUTING" || msg.status == "CANCELLED" || msg.status == "FAILED") {
if (msg.status == "EXECUTING" || msg.status == "PAUSE" || msg.status == "CANCELLED" || msg.status == "FAILED") {
this.onIsExecuting?.(true);
}
@@ -520,7 +520,7 @@ export default class DeviceController {
console.log('task finish');
this.onIsFinished?.(true);
}
if (msg.status == "EXECUTING") {
if (msg.status == "EXECUTING" || msg.status == "PAUSE") {
this.onIsExecuting?.(true);
}
@@ -545,18 +545,6 @@ export default class DeviceController {
break;
}
case 'detectionReport':
const { isSecure, obstacle } = msg.data;
if (isSecure) return;
const type = obstacle?.type;
const distance = (obstacle?.distance || 0).toFixed(2);
const types = { 0: i18n.t('constants.locationUnknown'), 1: i18n.t('devices.obstaclePerson'), 2: i18n.t('devices.obstacleVehicle'), 3: i18n.t('devices.obstacleFence'), 4: i18n.t('devices.obstaclePothole'), 5: i18n.t('devices.obstacleGrass') };
this.messageApi.warning({
key: 'obstacle-warning',
content: i18n.t('devices.obstacleDetectedReport', { obstacle: types[type] ?? i18n.t('devices.unknownObject'), distance }),
duration: 3,
});
break;
case 'route_post':
console.log('route_post:', msg);