增加了机器人任务模块

This commit is contained in:
mmc
2026-05-28 16:52:22 +08:00
parent ef175e7bed
commit 3f457cb2e7
2 changed files with 382 additions and 1 deletions

View File

@@ -0,0 +1,378 @@
import React, { useState, useEffect, useRef } from 'react';
import {
Row, Col, Card, Button, Space, Table, Tag, Typography, Progress, Badge,
Tabs, Input, Switch, Divider, Tooltip, Timeline, Select, message, DatePicker,
Modal, InputNumber
} from 'antd';
import {
PlusOutlined, ImportOutlined, NodeIndexOutlined,
SaveOutlined, FullscreenOutlined, EnvironmentOutlined,
BranchesOutlined, CloudOutlined, ThunderboltOutlined, CheckCircleOutlined,
InfoCircleOutlined, ClockCircleOutlined,
SettingOutlined, WarningOutlined, ArrowRightOutlined,
SearchOutlined, MoreOutlined, AimOutlined, PlayCircleOutlined
} from '@ant-design/icons';
import {
Car, Navigation, Wind, Thermometer, Droplets, Satellite,
LayoutGrid, Clock, CheckCircle2, AlertCircle, Zap, Waves,
Calendar, User, TrendingUp, Maximize2, Play, Square, X, MapPin, RotateCw
} from 'lucide-react';
import {
getWorkList, saveDeviceTask, getDeviceTask
} from '../../api/api';
import dayjs from 'dayjs';
import utils from '../../lib/utils';
import CesiumMap from '../Map';
import { fix2, getVal } from '../../lib/utils';
const { Text, Title } = Typography;
const { RangePicker } = DatePicker;
export default function RobotTaskPage({ devices, onRefresh }) {
const fontSmall = 'clamp(10px, 0.7vw, 11px)';
const fontNormal = 'clamp(12px, 0.75vw, 13px)';
const fontTitle = 'clamp(14px, 0.85vw, 16px)';
const fontLarge = 'clamp(18px, 1.1vw, 24px)';
const cardStyle = { borderRadius: 12, border: 'none', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' };
// 任务列表 独立筛选状态
const [listRobot, setListRobot] = useState(null);
const [listDateRange, setListDateRange] = useState(null);
const [taskList, setTaskList] = useState([]);
// 工作看板 独立筛选状态
const [boardRobot, setBoardRobot] = useState(null);
const [boardDateRange, setBoardDateRange] = useState(null);
const [boardTaskList, setBoardTaskList] = useState([]);
const [selectedRoute, setSelectedRoute] = useState(null);
const [focusLocation, setFocusLocation] = useState(null);
const [points, setPoints] = useState([]);
const [loading, setLoading] = useState(false);
const [createTaskModal, setCreateTaskModal] = useState(false);
const [routeSearch, setRouteSearch] = useState('');
const [routeList, setRouteList] = useState([]);
// 获取任务列表数据
const getListTask = async () => {
if (!devices?.length) return;
try {
const userId = JSON.parse(localStorage.getItem("userInfo") || '{}')?.userId;
const res = await getWorkList({ userId });
if (res.code === 200) {
setTaskList(res.data || []);
}
} catch (err) {
message.error('任务列表数据获取失败');
}
};
// 获取路线列表
const fetchRouteList = async () => {
// 这里假设有一个获取机器人路线的接口,或者从现有任务中提取
setRouteList([
{ id: 1, name: '区域 A 巡检路线', points: 12, length: '1.2km' },
{ id: 2, name: 'B 阵列除草路线', points: 24, length: '2.5km' },
{ id: 3, name: '边界防护路线', points: 8, length: '0.8km' },
]);
};
useEffect(() => {
getListTask();
fetchRouteList();
}, []);
useEffect(() => {
if (devices?.length) {
setListRobot(devices[0]);
setBoardRobot(null);
}
}, [devices]);
const taskColumns = [
{ title: '任务名称', dataIndex: 'workName', width: 200, ellipsis: true, fixed: "left" },
{ title: '设备名称', dataIndex: 'deviceName', width: 140 },
{ title: '执行人', dataIndex: 'userName', width: 100 },
{
title: '执行时间', dataIndex: 'createTime', width: 170,
render: t => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
{
title: '状态', dataIndex: 'status', width: 100,
render: (s) => <Tag color={s === 'success' ? 'success' : 'processing'}>{s === 'success' ? '完成' : '执行中'}</Tag>
}
];
const handleRowClick = (record) => {
// 定位到机器人位置或显示轨迹
if (record.longitude && record.latitude) {
setFocusLocation({
lon: record.longitude,
lat: record.latitude,
type: 'robot',
name: record.deviceName
});
}
};
const groupBoardData = () => {
const waitList = taskList.filter(item => item.status !== 'success');
const runList = taskList.filter(item => item.status === 'executing');
const finishList = taskList.filter(item => item.status === 'success');
return { waitList, runList, finishList };
};
const { waitList, runList, finishList } = groupBoardData();
const topCards = [
{ title: '今日机器人计划', value: taskList.length, unit: '条', desc: '进行中', icon: <LayoutGrid size={22} />, color: '#165DFF' },
{ title: '作业中机器人', value: runList.length, unit: '台', desc: '作业中', icon: <Car size={22} />, color: '#165DFF' },
{ title: '累计作业里程', value: '12.5', unit: 'km', trend: '较昨日 +1.2', trendColor: '#00B42A', icon: <TrendingUp size={22} />, color: '#722ED1' },
{ title: '任务完成率', value: taskList.length ? Math.round((finishList.length / taskList.length) * 100) : 0, unit: '%', trend: '较昨日 +5%', trendColor: '#00B42A', icon: <CheckCircle2 size={22} />, color: '#00B42A' },
{ title: '异常告警', value: '2', unit: '次', trend: '较昨日 -1', trendColor: '#00B42A', icon: <AlertCircle size={22} />, color: '#F53F3F' },
{ title: '在线率', value: '98', unit: '%', desc: '良好', icon: <Satellite size={22} />, color: '#165DFF' },
];
return (
<div className="normal-spacing" style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0px', paddingTop: 0 }}>
<Row gutter={[16, 16]} style={{ marginBottom: 8 }}>
{topCards.map((item, index) => (
<Col xs={12} sm={8} md={4} key={index}>
<Card bordered={false} bodyStyle={{ padding: '12px 14px' }} style={cardStyle}>
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
<div style={{ width: 36, height: 36, background: 'rgba(22, 93, 255, 0.1)', borderRadius: 10, display: 'flex', justifyContent: 'center', alignItems: 'center', color: item.color }}>
{React.cloneElement(item.icon as React.ReactElement, { size: 18 })}
</div>
<div style={{ flex: 1 }}>
<div style={{ fontSize: 13, color: '#86909C' }}>{item.title}</div>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4 }}>
<span style={{ fontSize: 'clamp(16px, 1vw, 20px)', fontWeight: 700, color: '#1D2129' }}>{item.value}</span>
<span style={{ fontSize: 9, color: '#4E5969' }}>{item.unit}</span>
</div>
<div style={{ fontSize: 9, color: item.trendColor || '#86909C', fontWeight: 500 }}>
{item.trend || item.desc}
</div>
</div>
</div>
</Card>
</Col>
))}
</Row>
<Row gutter={10} style={{ marginBottom: 10 }}>
<Col xs={24} xl={14} style={{ display: "flex", flexDirection: "column" }}>
<Card
title={<span style={{ fontSize: fontNormal, fontWeight: 700 }}>机器人路径规划与监控</span>}
size="small"
extra={
<Space size={4}>
<Button size="small" icon={<PlusOutlined />} style={{ borderRadius: 4 }}>新增路线</Button>
<Button size="small" icon={<ImportOutlined />} style={{ borderRadius: 4 }}>导入</Button>
<Button size="small" icon={<SaveOutlined />} style={{ borderRadius: 4 }}>保存</Button>
<Button size="small" icon={<Maximize2 size={12} />} />
</Space>
}
bordered={false}
bodyStyle={{ padding: 0, position: 'relative' }}
style={{ ...cardStyle, marginBottom: 10 }}
>
<div style={{ width: '100%', height: 420, background: '#e8f3ff center/cover', position: 'relative' }}>
<CesiumMap devices={devices} points={points} focusLocation={focusLocation} from="device-control" />
</div>
</Card>
<Card
title={
<div className="flex justify-between w-full items-center">
<span style={{ fontSize: 14, fontWeight: 700 }}>机器人任务列表</span>
<Space size={12}>
<RangePicker size="small" showTime format="YYYY-MM-DD HH:mm:ss" placeholder={['开始时间', '结束时间']} />
<Select
style={{ width: 180 }}
size="small"
placeholder="全部机器人"
options={devices?.map(item => ({
value: item.device_sn || item.serialNumber,
label: item.deviceAlias || item.deviceName
}))}
value={listRobot?.device_sn || listRobot?.serialNumber}
onChange={(val) => setListRobot(devices.find(i => (i.device_sn || i.serialNumber) === val))}
/>
</Space>
</div>
}
size="small"
bordered={false}
bodyStyle={{ padding: 0, display: 'flex', flexDirection: 'column', height: "calc(100% - 40px)", overflow: "auto" }}
style={{ ...cardStyle, maxHeight: "250px", flex: 1, marginBottom: 0 }}
>
<Table
size="small"
rowKey="id"
columns={taskColumns}
dataSource={taskList}
pagination={false}
onRow={(record) => ({
onClick: () => handleRowClick(record),
style: { cursor: 'pointer' }
})}
/>
</Card>
</Col>
<Col xs={24} xl={10} style={{ display: "flex", flexDirection: "column" }} >
<Card
title={<span style={{ fontSize: fontTitle, fontWeight: 700 }}>作业编排建议</span>}
bordered={false}
bodyStyle={{ padding: '12px 16px' }}
style={{ ...cardStyle, marginBottom: 8 }}
>
<Timeline mode="left">
<Timeline.Item label="09:30" color="green">
<Text strong>RBT-01 开始除草任务</Text>
<div style={{ fontSize: 12, color: '#86909C' }}>预计耗时 2 小时,当前进度 45%</div>
</Timeline.Item>
<Timeline.Item label="11:00" color="blue">
<Text strong>RBT-02 预定巡检任务</Text>
<div style={{ fontSize: 12, color: '#86909C' }}>待审批,建议执行区域 C</div>
</Timeline.Item>
<Timeline.Item label="14:00" color="gray">
<Text strong>设备例行维护</Text>
<div style={{ fontSize: 12, color: '#86909C' }}>所有割草机返回充电站</div>
</Timeline.Item>
</Timeline>
<Button type="primary" block style={{ marginTop: 16, borderRadius: 18 }}>智能生成今日计划</Button>
</Card>
<Card
title={<span style={{ fontSize: fontTitle, fontWeight: 700 }}>设备环境与状态</span>}
bordered={false}
bodyStyle={{ padding: '16px' }}
style={{ ...cardStyle, flex: 1 }}
>
<Row gutter={[16, 16]}>
<Col span={12}>
<div style={{ background: '#F7F8FA', padding: 12, borderRadius: 10 }}>
<div style={{ fontSize: 12, color: '#86909C' }}>当前温度</div>
<div style={{ fontSize: 18, fontWeight: 700 }}>24.5 ℃</div>
</div>
</Col>
<Col span={12}>
<div style={{ background: '#F7F8FA', padding: 12, borderRadius: 10 }}>
<div style={{ fontSize: 12, color: '#86909C' }}>环境湿度</div>
<div style={{ fontSize: 18, fontWeight: 700 }}>65 %</div>
</div>
</Col>
<Col span={12}>
<div style={{ background: '#F7F8FA', padding: 12, borderRadius: 10 }}>
<div style={{ fontSize: 12, color: '#86909C' }}>定位精度</div>
<div style={{ fontSize: 18, fontWeight: 700, color: '#00B42A' }}>RTK 固定</div>
</div>
</Col>
<Col span={12}>
<div style={{ background: '#F7F8FA', padding: 12, borderRadius: 10 }}>
<div style={{ fontSize: 12, color: '#86909C' }}>网络延迟</div>
<div style={{ fontSize: 18, fontWeight: 700 }}>45 ms</div>
</div>
</Col>
</Row>
<div style={{ marginTop: 20, padding: 12, background: 'rgba(255, 125, 0, 0.1)', borderRadius: 8, display: 'flex', alignItems: 'center', gap: 8 }}>
<AlertCircle size={16} style={{ color: '#FF7D00' }} />
<span style={{ fontSize: 13, color: '#FF7D00' }}>注意:区域 B 存在积水风险,建议避开</span>
</div>
</Card>
</Col>
</Row>
<Row gutter={16}>
<Col xs={24} xl={6}>
<Card
title={
<div className="flex justify-between items-center w-full">
<span style={{ fontSize: fontTitle, fontWeight: 700 }}>预设路线</span>
<Input
placeholder="搜索..."
size="small"
style={{ width: 100 }}
value={routeSearch}
onChange={e => setRouteSearch(e.target.value)}
/>
</div>
}
bordered={false}
bodyStyle={{ padding: '12px', height: 400, overflow: 'auto' }}
style={cardStyle}
>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{routeList.map(route => (
<div
key={route.id}
style={{
padding: 12,
borderRadius: 8,
background: '#F7F8FA',
cursor: 'pointer',
border: '1px solid transparent'
}}
onMouseEnter={e => e.currentTarget.style.borderColor = '#165DFF'}
onMouseLeave={e => e.currentTarget.style.borderColor = 'transparent'}
>
<div style={{ fontWeight: 600, fontSize: 14 }}>{route.name}</div>
<div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4, fontSize: 12, color: '#86909C' }}>
<span>航点: {route.points}</span>
<span>长度: {route.length}</span>
</div>
<Button type="primary" size="small" block style={{ marginTop: 8, borderRadius: 4 }} icon={<PlayCircleOutlined />}>执行路线</Button>
</div>
))}
</div>
</Card>
</Col>
<Col xs={24} xl={18}>
<Card
title={<span style={{ fontSize: fontTitle, fontWeight: 700 }}>任务看板</span>}
bordered={false}
bodyStyle={{ padding: '12px' }}
style={{ ...cardStyle, height: '100%' }}
>
<Row gutter={16}>
<Col span={8}>
<div style={{ background: '#F7F8FA', padding: 12, borderRadius: 8, height: 400 }}>
<Title level={5} style={{ fontSize: 14, marginBottom: 12 }}><Badge color="#86909C" text="待执行" /></Title>
{waitList.slice(0, 3).map((item, idx) => (
<Card key={idx} size="small" style={{ marginBottom: 8, borderRadius: 6 }}>
<div style={{ fontWeight: 600 }}>{item.workName}</div>
<div style={{ fontSize: 12, color: '#86909C' }}>设备: {item.deviceName}</div>
</Card>
))}
</div>
</Col>
<Col span={8}>
<div style={{ background: '#E8F3FF', padding: 12, borderRadius: 8, height: 400 }}>
<Title level={5} style={{ fontSize: 14, marginBottom: 12 }}><Badge color="#165DFF" text="进行中" /></Title>
{runList.map((item, idx) => (
<Card key={idx} size="small" style={{ marginBottom: 8, borderRadius: 6 }}>
<div style={{ fontWeight: 600 }}>{item.workName}</div>
<div style={{ fontSize: 12, color: '#165DFF' }}>正在执行...</div>
</Card>
))}
</div>
</Col>
<Col span={8}>
<div style={{ background: '#F6FFED', padding: 12, borderRadius: 8, height: 400 }}>
<Title level={5} style={{ fontSize: 14, marginBottom: 12 }}><Badge color="#52C41A" text="已完成" /></Title>
{finishList.slice(0, 3).map((item, idx) => (
<Card key={idx} size="small" style={{ marginBottom: 8, borderRadius: 6 }}>
<div style={{ fontWeight: 600 }}>{item.workName}</div>
<div style={{ fontSize: 12, color: '#52C41A' }}>已完成</div>
</Card>
))}
</div>
</Col>
</Row>
</Card>
</Col>
</Row>
</div>
);
}