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) =>