import React, { useState, useEffect } from 'react';
import {
Row, Col, Card, Button, Space, Table, Tag, Typography, Progress, Badge,
Tabs, Input, Switch, Divider, Tooltip, Timeline, Select, message, DatePicker
} from 'antd';
import {
PlusOutlined, ImportOutlined, NodeIndexOutlined,
SaveOutlined, FullscreenOutlined, EnvironmentOutlined,
BranchesOutlined, CloudOutlined, ThunderboltOutlined, CheckCircleOutlined,
InfoCircleOutlined, ClockCircleOutlined,
SettingOutlined, WarningOutlined, ArrowRightOutlined,
SearchOutlined, MoreOutlined, AimOutlined
} from '@ant-design/icons';
import {
Plane, Navigation, Wind, Thermometer, Droplets, Satellite,
LayoutGrid, Clock, CheckCircle2, AlertCircle, Zap, Waves,
Calendar, User, TrendingUp, Maximize2
} from 'lucide-react';
import { getsinglePlan, getsinglePlanTrack } from '@/api/device';
import dayjs from 'dayjs';
import utils from '@/lib/utils';
import CesiumMap from '../Map';
const { Text, Title } = Typography;
const { RangePicker } = DatePicker;
export default function WayLinePage({ planedevices }) {
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 [listDrone, setListDrone] = useState(null);
const [listDateRange, setListDateRange] = useState(null);
const [taskList, setTaskList] = useState([]);
// 工作看板 独立筛选状态
const [boardDrone, setBoardDrone] = useState(null);
const [boardDateRange, setBoardDateRange] = useState(null);
const [boardTaskList, setBoardTaskList] = useState([]);
const [points, setPoints] = useState([]);
// 顶部统计
const topCards = [
{ title: '今日航线计划', value: '18', unit: '条', trend: '较昨日 +2', trendColor: '#00B42A', icon: , color: '#165DFF' },
{ title: '执行中任务', value: '6', unit: '个', desc: '进行中', icon: , color: '#165DFF' },
{ title: '待审批任务', value: '4', unit: '个', trend: '较昨日 -1', trendColor: '#F53F3F', icon: , color: '#FF7D00' },
{ title: '任务完成率', value: '92', unit: '%', trend: '较昨日 +6%', trendColor: '#00B42A', icon: , color: '#00B42A' },
{ title: 'AI 优化收益', value: '+7.8', unit: '%', trend: '较昨日 +1.2%', trendColor: '#00B42A', icon: , color: '#722ED1' },
{ title: '覆盖装备', value: '4 类 / 9 台', unit: '', desc: '全部在线', icon: , color: '#165DFF' },
];
// 获取任务列表数据 【时间戳已改为秒级】
const getListTask = async () => {
if (!planedevices?.length) return;
try {
const defaultStart = dayjs().startOf('day').unix(); // 秒级
const defaultEnd = dayjs().endOf('day').unix(); // 秒级
const [beginAt, endAt] = listDateRange?.length === 2
? [dayjs(listDateRange[0]).unix(), dayjs(listDateRange[1]).unix()]
: [defaultStart, defaultEnd];
const sns = listDrone ? [listDrone.gateway_sn] : planedevices.map(item => item.gateway_sn);
const res = await getsinglePlan({ sns, beginAt, endAt });
if (res?.code === 200) {
// 处理嵌套数据结构:data: { [sn]: { list: [] } }
let combinedList = [];
if (res.data) {
Object.values(res.data).forEach((item: any) => {
if (item.list) combinedList = combinedList.concat(item.list);
});
}
setTaskList(combinedList);
}
} catch (err) {
message.error('任务列表数据获取失败');
}
};
// 获取看板任务数据 【时间戳已改为秒级】
const getBoardTask = async () => {
if (!planedevices?.length) return;
try {
const defaultStart = dayjs().startOf('day').unix(); // 秒级
const defaultEnd = dayjs().endOf('day').unix(); // 秒级
const [beginAt, endAt] = boardDateRange?.length === 2
? [dayjs(boardDateRange[0]).unix(), dayjs(boardDateRange[1]).unix()]
: [defaultStart, defaultEnd];
const sns = boardDrone ? [boardDrone.gateway_sn] : planedevices.map(item => item.gateway_sn);
const res = await getsinglePlan({ sns, beginAt, endAt });
if (res?.code === 200) {
// 处理嵌套数据结构
let combinedList = [];
if (res.data) {
Object.values(res.data).forEach((item: any) => {
if (item.list) combinedList = combinedList.concat(item.list);
});
}
setBoardTaskList(combinedList);
}
} catch (err) {
message.error('任务看板数据获取失败');
}
};
// 初始化默认全部设备
useEffect(() => {
if (planedevices?.length) {
setListDrone(planedevices[0]); // 默认显示第一个无人机
setBoardDrone(null); // 默认显示所有
}
}, [planedevices]);
// 各自筛选变更独立请求
useEffect(() => {
getListTask();
}, [listDrone, listDateRange]);
useEffect(() => {
getBoardTask();
}, [boardDrone, boardDateRange]);
// 任务状态标签
const getStatusTag = (status) => {
const statusMap = {
success: { color: 'success', text: '执行成功' },
preparing: { color: 'blue', text: '准备中' },
running: { color: 'processing', text: '执行中' },
failed: { color: 'error', text: '执行失败' },
waiting: { color: 'default', text: '待开始' },
starting_failure: { color: 'error', text: '启动失败' },
executing: { color: 'processing', text: '执行中' },
suspended: { color: 'warning', text: '已挂起' },
restored: { color: 'processing', text: '恢复执行' },
terminated: { color: 'default', text: '已终止' },
timeout: { color: 'error', text: '执行超时' },
};
const item = statusMap[status] || { color: 'default', text: status };
return {item.text};
};
// 列表表格列
const taskColumns = [
{ title: '任务名称', dataIndex: 'name', width: 260, ellipsis: true, fixed: "left" },
//{ title: '任务UUID', dataIndex: 'uuid', width: 260, ellipsis: true },
{ title: '设备SN', dataIndex: 'sn', width: 140 },
{ title: '状态', dataIndex: 'status', width: 80, render: getStatusTag },
{
title: '开始时间',
dataIndex: 'begin_at',
width: 170,
render: t => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
{
title: '结束时间',
dataIndex: 'end_at',
width: 170,
render: t => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
];
// 表格行点击查看轨迹
const handleRowClick = async (record) => {
try {
const res = await getsinglePlanTrack(record);
if (res.code === 0 && res.data.track?.points?.length) {
const points = res.data.track.points.map(item => ({
lon: item.longitude || item.lon,
lat: item.latitude || item.lat
}));
setPoints(points);
} else {
utils.message.warning("暂无航线数据");
setPoints([]);
}
} catch (err) {
message.error('请求失败');
console.error(err);
}
};
// 看板数据分组处理
const groupBoardData = () => {
// 待执行 = 准备中 + 待开始 + 已挂起 + 已终止
const waitList = boardTaskList.filter(item =>
['preparing', 'waiting', 'suspended', 'terminated'].includes(item.status)
);
// 执行中 = 运行中 + 执行中 + 恢复执行
const runList = boardTaskList.filter(item =>
['running', 'executing', 'restored'].includes(item.status)
);
// 已完成 = 执行成功
const finishList = boardTaskList.filter(item =>
['success'].includes(item.status)
);
return { waitList, runList, finishList };
};
const { waitList, runList, finishList } = groupBoardData();
return (
{topCards.map((item, index) => (
{React.cloneElement(item.icon, { size: 18 })}
{item.title}
{item.value}
{item.unit}
{item.trend || item.desc}
))}
{/* 地图卡片 */}
航线编辑与路径规划}
size="small"
extra={
} style={{ borderRadius: 4 }}>新增
} style={{ borderRadius: 4 }}>导入
} style={{ borderRadius: 4 }}>优化
} style={{ borderRadius: 4 }}>保存
} />
}
bordered={false}
bodyStyle={{ padding: 0, position: 'relative' }}
style={{ ...cardStyle, marginBottom: 10 }}
>
{/* 独立筛选 - 设备任务列表 */}
设备任务列表
setListDateRange(val)}
placeholder={['开始时间', '结束时间']}
/>
}
size="small"
extra={}
bordered={false}
bodyStyle={{ padding: 0, display: 'flex', flexDirection: 'column', flex: 1 }}
style={{ ...cardStyle, flex: 1 }}
>
({
onClick: () => handleRowClick(record),
style: { cursor: 'pointer' }
})}
/>
任务编排与 AI 建议}
bordered={false}
bodyStyle={{ padding: '12px 16px' }}
style={{ ...cardStyle, marginBottom: 16 }}
>
{t} },
{ title: '装备', dataIndex: 'device', width: 80 },
{ title: '类型', dataIndex: 'type', ellipsis: true },
{ title: '优先级', dataIndex: 'level', width: 80, render: (l) => ▲ {l} },
{ title: '建议时间', dataIndex: 'time', width: 110 },
{ title: '状态', dataIndex: 'status', width: 90, render: (s) => {s} },
]}
/>
AI 建议:
}>
推荐优先执行 FL-03 航线
14:00-16:00 风速最佳
区块 B-12 存在高温风险
航线参数 / 作业参数}
extra={当前航线:FL-03}
bordered={false}
bodyStyle={{ padding: '16px' }}
style={{ ...cardStyle, marginBottom: 16 }}
>
{[
{ label: '飞行高度', value: '35', unit: 'm' },
{ label: '速度', value: '6', unit: 'm/s' },
{ label: '航向重叠', value: '75', unit: '%' },
{ label: '旁向重叠', value: '65', unit: '%' },
{ label: '安全返航电量', value: '25', unit: '%' },
{ label: '清洗喷洒量', value: '120', unit: 'ml/㎡' },
{ label: '除草宽幅', value: '1.2', unit: 'm' },
{ label: '巡检采样频率', value: '2', unit: 'Hz' },
].map((item, idx) => (
{item.label}
{item.unit}
))}
避障开关
夜航限制
天气窗口与执行约束}
bordered={false}
bodyStyle={{ padding: '16px' }}
style={cardStyle}
>
{[
{
label: '风速',
value: `${listDrone?.wind_speed ?? '-'} m/s`,
icon: ,
color: '#165DFF',
judge: (val) => {
const speed = parseFloat(val);
if (isNaN(speed)) return { desc: '未知', color: '#86909C' };
if (speed <= 5) return { desc: '适宜', color: '#52C41A' };
if (speed <= 8) return { desc: '谨慎', color: '#FF7D00' };
return { desc: '不适宜', color: '#F53F3F' };
}
},
{
label: '温度',
value: `${listDrone?.environment_temperature ?? '-'}℃`,
icon: ,
color: '#FF7D00',
judge: (val) => {
const temp = parseFloat(val);
if (isNaN(temp)) return { desc: '未知', color: '#86909C' };
if (temp >= 0 && temp <= 40) return { desc: '适宜', color: '#52C41A' };
return { desc: '不适宜', color: '#F53F3F' };
}
},
{
label: '降雨',
value: `${listDrone?.rainfall ?? '-'} `,
icon: ,
color: '#FF7D00',
judge: (val) => {
if (val?.trim() === "no_rain") {
return { desc: '适宜', color: '#52C41A' };
} else {
return { desc: '不适宜', color: '#F53F3F' };
}
}
},
{
label: '信号质量',
value: (() => {
const q = listDrone?.network_state?.quality;
if (q === 'good') return '优';
if (q === 'better') return '良';
if (q === 'moderate') return '中';
if (q === 'poor') return '差';
if (q === 'too_pool') return '极差';
return '正常';
})(),
icon: ,
color: '#00B42A',
judge: (val) => {
if (val === '优' || val === '良' || val === '正常') return { desc: '适宜', color: '#52C41A' };
if (val === '中') return { desc: '谨慎', color: '#FF7D00' };
return { desc: '不适宜', color: '#F53F3F' };
}
},
].map((item, idx) => {
const status = item.judge(item.value);
return (
{item.icon}
{item.label}
{item.value}
{status.desc}
);
})}
16:30 后风速升高,建议提前完成任务
预计 14:00-16:00 为最佳执行窗口
{/* 底部内容区 */}
任务甘特视图 / 排班视图 今日 (2025-05-24)}
extra={}
bordered={false}
bodyStyle={{ padding: 16 }}
style={{ ...cardStyle, height: '100%' }}
>
08:0010:0012:0014:0016:0018:00
{[
{ label: '无人机机场 A01', sub: '(UAV-A01)', tasks: [{ start: '25%', width: '18%', title: 'FL-03 热斑巡检', time: '10:00-11:20', color: '#165DFF' }, { start: '75%', width: '12%', title: 'FL-07 复检', time: '16:30-17:10', color: '#165DFF' }] },
{ label: '巡检机器人 RBT-01', sub: '', tasks: [{ start: '45%', width: '15%', title: 'RB-02 围栏巡检', time: '11:30-12:30', color: '#FF7D00' }] },
{ label: '除草机器人 GR-01', sub: '', tasks: [{ start: '10%', width: '22%', title: 'GR-04 阵列除草', time: '09:30-11:30', color: '#00B42A' }] },
{ label: '清洗无人机 UAV-C01', sub: '', tasks: [{ start: '65%', width: '20%', title: 'CL-05 组件清洗', time: '14:00-16:00', color: '#13C2C2' }] },
].map((row, idx) => (
{row.tasks.map((task, tidx) => (
))}
))}
工作任务看板
setBoardDateRange(val)}
placeholder={['开始', '结束']}
/>
}
bordered={false}
bodyStyle={{ padding: 16 }}
style={{ ...cardStyle, height: '100%', maxHeight: 480, overflow: "auto" }}
>
{[
{
title: '待执行', count: waitList.length, color: '#4E5969', bg: '#F7F8FA',
list: waitList.map(item => ({
id: item.sn?.slice(-5) || '',
name: item.name,
device: item.sn,
begin_at: ''
}))
},
{
title: '执行中', count: runList.length, color: '#165DFF', bg: '#E8F3FF',
list: runList.map(item => ({
id: item.sn?.slice(-5) || '',
name: item.name,
device: item.sn,
begin_at: ''
}))
},
{
title: '已完成', count: finishList.length, color: '#00B42A', bg: '#E8FFEA',
list: finishList.map(item => ({
id: item.sn?.slice(-5) || '',
name: item.name,
device: item.sn,
begin_at: item.begin_at,
completed_at: item.completed_at
}))
},
].map((col, idx) => (
{col.title} ({col.count})
{col.list.map((task, tidx) => (
{task.name}
装备: {task.device || 'UAV-A01'}
{task.begin_at &&
开始时间: {task.begin_at}
}
{task.completed_at &&
完成时间: {task.completed_at}
}
))}
))}
{/**/}
);
}