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, 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) => {s === 'success' ? '完成' : '执行中'} } ]; 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: , color: '#165DFF' }, { title: '作业中机器人', value: runList.length, unit: '台', desc: '作业中', icon: , color: '#165DFF' }, { title: '累计作业里程', value: '12.5', unit: 'km', trend: '较昨日 +1.2', trendColor: '#00B42A', icon: , color: '#722ED1' }, { title: '任务完成率', value: taskList.length ? Math.round((finishList.length / taskList.length) * 100) : 0, unit: '%', trend: '较昨日 +5%', trendColor: '#00B42A', icon: , color: '#00B42A' }, { title: '异常告警', value: '2', unit: '次', trend: '较昨日 -1', trendColor: '#00B42A', icon: , color: '#F53F3F' }, { title: '在线率', value: '98', unit: '%', desc: '良好', icon: , color: '#165DFF' }, ]; return (
{topCards.map((item, index) => (
{React.cloneElement(item.icon as React.ReactElement, { size: 18 })}
{item.title}
{item.value} {item.unit}
{item.trend || item.desc}
))}
机器人路径规划与监控} size="small" extra={
} bordered={false} bodyStyle={{ padding: '12px', height: 400, overflow: 'auto' }} style={cardStyle} >
{routeList.map(route => (
e.currentTarget.style.borderColor = '#165DFF'} onMouseLeave={e => e.currentTarget.style.borderColor = 'transparent'} >
{route.name}
航点: {route.points} 长度: {route.length}
))}
任务看板} bordered={false} bodyStyle={{ padding: '12px' }} style={{ ...cardStyle, height: '100%' }} >
<Badge color="#86909C" text="待执行" /> {waitList.slice(0, 3).map((item, idx) => (
{item.workName}
设备: {item.deviceName}
))}
<Badge color="#165DFF" text="进行中" /> {runList.map((item, idx) => (
{item.workName}
正在执行...
))}
<Badge color="#52C41A" text="已完成" /> {finishList.slice(0, 3).map((item, idx) => (
{item.workName}
已完成
))}
); }