This commit is contained in:
mmc
2026-05-22 10:58:57 +08:00
parent 732df65089
commit 353d1bcf5a
2 changed files with 170 additions and 132 deletions

View File

@@ -1,7 +1,7 @@
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
Tabs, Input, Switch, Divider, Tooltip, Timeline, Select, message, DatePicker
} from 'antd';
import {
PlusOutlined, ImportOutlined, NodeIndexOutlined,
@@ -22,6 +22,7 @@ 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)';
@@ -30,9 +31,18 @@ export default function WayLinePage({ planedevices }) {
const fontLarge = 'clamp(18px, 1.1vw, 24px)';
const cardStyle = { borderRadius: 12, border: 'none', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' };
const [selectedDrone, setSelectedDrone] = useState(null);
const [taskList, setTaskList] = useState([]); // 真实任务列表
const [points, setPoints] = useState([]); // 航线轨迹点
// 任务列表 独立筛选状态
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 = [
@@ -44,40 +54,62 @@ export default function WayLinePage({ planedevices }) {
{ title: '覆盖装备', value: '4 类 / 9 台', unit: '', desc: '全部在线', icon: <Satellite size={22} />, color: '#165DFF' },
];
// 获取真实任务
const getTaskList = async (drone) => {
if (!drone || !drone.device_sn) return;
// 获取任务列表数据
const getListTask = async () => {
if (!planedevices?.length) return;
try {
const data = {
sn: [drone.gateway_sn]
}
const res = await getsinglePlan(data);
if (res?.code === 0) {
setTaskList(res.data?.list || []);
}
const defaultStart = dayjs().startOf('day').valueOf();
const defaultEnd = dayjs().endOf('day').valueOf();
const [beginAt, endAt] = listDateRange?.length === 2
? [dayjs(listDateRange[0]).valueOf(), dayjs(listDateRange[1]).valueOf()]
: [defaultStart, defaultEnd];
const sns = listDrone ? [listDrone.gateway_sn] : planedevices.map(item => item.gateway_sn);
const res = await getsinglePlan({ sns, beginAt, endAt });
if (res?.code === 0) setTaskList(res.data?.list || []);
} catch (err) {
message.error('获取任务失败');
message.error('任务列表数据获取失败');
}
};
// 默认选中第一个无人机
// 获取看板任务数据
const getBoardTask = async () => {
if (!planedevices?.length) return;
try {
const defaultStart = dayjs().startOf('day').valueOf();
const defaultEnd = dayjs().endOf('day').valueOf();
const [beginAt, endAt] = boardDateRange?.length === 2
? [dayjs(boardDateRange[0]).valueOf(), dayjs(boardDateRange[1]).valueOf()]
: [defaultStart, defaultEnd];
const sns = boardDrone ? [boardDrone.gateway_sn] : planedevices.map(item => item.gateway_sn);
const res = await getsinglePlan({ sns, beginAt, endAt });
if (res?.code === 0) setBoardTaskList(res.data?.list || []);
} catch (err) {
message.error('任务看板数据获取失败');
}
};
// 初始化默认全部设备
useEffect(() => {
if (planedevices?.length) {
setSelectedDrone(planedevices[0]);
const data = planedevices.map(i => i.gateway_sn);
getTaskList(data);
setListDrone(null);
setBoardDrone(null);
}
}, [planedevices]);
// 切换无人机时刷新任务
// 各自筛选变更独立请求
useEffect(() => {
getTaskList(selectedDrone);
}, [selectedDrone]);
getListTask();
}, [listDrone, listDateRange]);
// 任务状态颜色
useEffect(() => {
getBoardTask();
}, [boardDrone, boardDateRange]);
// 任务状态标签
const getStatusTag = (status) => {
const statusMap = {
// 基础状态
success: { color: 'success', text: '执行成功' },
running: { color: 'processing', text: '执行中' },
failed: { color: 'error', text: '执行失败' },
@@ -89,15 +121,13 @@ export default function WayLinePage({ planedevices }) {
terminated: { color: 'default', text: '已终止' },
timeout: { color: 'error', text: '执行超时' },
};
const item = statusMap[status] || { color: 'default', text: status };
return <Tag color={item.color}>{item.text}</Tag>;
};
// 任务表格列
// 列表表格列
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 },
@@ -114,39 +144,38 @@ export default function WayLinePage({ planedevices }) {
render: t => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
];
// 表格行点击事件
// 表格行点击查看轨迹
const handleRowClick = async (record) => {
try {
getsinglePlanTrack(record).then(res => {
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([]);
}
})
// ======================
// 在这里写你的接口请求
// ======================
// 示例:
// const res = await getTaskDetail(record.uuid);
// if (res.code === 0) {
// message.success('获取成功');
// console.log('任务详情:', res.data);
// }
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 => ['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 (
<div className="normal-spacing" style={{ background: '#f5f7fa', minHeight: '100vh', padding: '16px' }}>
<div className="normal-spacing" style={{ background: '#f5f7fa', minHeight: '100vh', padding: '16px', paddingTop: 0 }}>
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
{topCards.map((item, index) => (
<Col xs={12} sm={8} md={4} key={index}>
@@ -191,20 +220,7 @@ export default function WayLinePage({ planedevices }) {
style={{ ...cardStyle, marginBottom: 10 }}
>
<div style={{ width: '100%', height: 420, background: '#e8f3ff url(https://picsum.photos/seed/solar_map_v2/1600/1000) center/cover', position: 'relative' }}>
{/*<svg style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', pointerEvents: 'none' }}>
<path d="M100,120 L200,80 L350,150 L500,100 L650,180" fill="none" stroke="#165DFF" strokeWidth="3" strokeDasharray="8,4" />
<path d="M220,300 Q350,220 480,350 T700,280" fill="none" stroke="#FF7D00" strokeWidth="3" />
<path d="M400,80 L550,140 L700,100" fill="none" stroke="#00B42A" strokeWidth="3" strokeDasharray="4,2" />
<circle cx="100" cy="120" r="6" fill="#165DFF" stroke="#fff" strokeWidth="2" />
<circle cx="200" cy="80" r="6" fill="#165DFF" stroke="#fff" strokeWidth="2" />
<circle cx="350" cy="150" r="6" fill="#165DFF" stroke="#fff" strokeWidth="2" />
</svg>*/}
<CesiumMap
points={points}
from="device-control"
/>
<CesiumMap points={points} from="device-control" />
<div style={{ position: 'absolute', top: 16, left: 16, background: 'rgba(255,255,255,0.92)', backdropFilter: 'blur(8px)', padding: '14px 16px', borderRadius: 10, width: 150, boxShadow: '0 4px 12px rgba(0,0,0,0.1)' }}>
<div style={{ fontSize: fontSmall, display: 'flex', flexDirection: 'column', gap: 10 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><span style={{ width: 14, height: 2, background: '#165DFF' }}></span> 无人机航线</div>
@@ -219,29 +235,37 @@ export default function WayLinePage({ planedevices }) {
</div>
</Card>
{/* 真实任务列表表格 */}
{/* 独立筛选 - 设备任务列表 */}
<Card
title={
<div className="flex justify-between w-full items-center">
<span style={{ fontSize: 14, fontWeight: 700 }}>
设备任务列表
</span>
<Select
style={{ width: 180 }}
size="small"
placeholder="选择无人机"
showSearch
allowClear
options={planedevices?.map(item => ({
value: item.device_sn,
label: item.drone_callsign || item.device_sn
}))}
value={selectedDrone?.device_sn}
onChange={(val) => {
const find = planedevices.find(i => i.device_sn === val);
setSelectedDrone(find || null);
}}
/>
<span style={{ fontSize: 14, fontWeight: 700 }}>设备任务列表</span>
<Space size={12}>
<RangePicker
size="small"
showTime
format="YYYY-MM-DD HH:mm:ss"
value={listDateRange}
onChange={(val) => setListDateRange(val)}
placeholder={['开始时间', '结束时间']}
/>
<Select
style={{ width: 180 }}
size="small"
placeholder="全部无人机"
showSearch
allowClear
options={planedevices?.map(item => ({
value: item.device_sn,
label: item.drone_callsign || item.device_sn
}))}
value={listDrone?.device_sn}
onChange={(val) => {
const find = planedevices.find(i => i.device_sn === val);
setListDrone(find || null);
}}
/>
</Space>
</div>
}
size="small"
@@ -258,11 +282,9 @@ export default function WayLinePage({ planedevices }) {
pagination={false}
scroll={{ y: 260 }}
style={{ height: '100%' }}
// 关键:行点击事件
onRow={(record) => ({
onClick: () => handleRowClick(record),
style: { cursor: 'pointer' } // 👈 就是这一行,显示小手
style: { cursor: 'pointer' }
})}
/>
</Card>
@@ -367,14 +389,12 @@ export default function WayLinePage({ planedevices }) {
</Col>
<Col span={18}>
<Row gutter={[16, 16]}>
{[
{
label: '风速',
value: `${selectedDrone?.wind_speed ?? '-'} m/s`,
value: `${listDrone?.wind_speed ?? '-'} m/s`,
icon: <Wind size={16} />,
color: '#165DFF',
// 飞行条件:≤ 5 m/s 适宜
judge: (val) => {
const speed = parseFloat(val);
if (isNaN(speed)) return { desc: '未知', color: '#86909C' };
@@ -385,10 +405,9 @@ export default function WayLinePage({ planedevices }) {
},
{
label: '温度',
value: `${selectedDrone?.environment_temperature ?? '-'}℃`,
value: `${listDrone?.environment_temperature ?? '-'}℃`,
icon: <Thermometer size={16} />,
color: '#FF7D00',
// 飞行条件:0℃ ~ 40℃ 适宜
judge: (val) => {
const temp = parseFloat(val);
if (isNaN(temp)) return { desc: '未知', color: '#86909C' };
@@ -398,15 +417,13 @@ export default function WayLinePage({ planedevices }) {
},
{
label: '降雨',
value: `${selectedDrone?.rainfall} `,
value: `${listDrone?.rainfall ?? '-'} `,
icon: <ThunderboltOutlined size={16} />,
color: '#FF7D00',
judge: (val) => {
if (val?.trim() === "no_rain") {
console.log('✅ 匹配到无雨 → 适宜');
return { desc: '适宜', color: '#52C41A' };
} else {
console.log('❌ 未匹配 → 不适宜');
return { desc: '不适宜', color: '#F53F3F' };
}
}
@@ -414,7 +431,7 @@ export default function WayLinePage({ planedevices }) {
{
label: '信号质量',
value: (() => {
const q = selectedDrone?.network_state?.quality;
const q = listDrone?.network_state?.quality;
if (q === 'good') return '优';
if (q === 'better') return '良';
if (q === 'moderate') return '中';
@@ -424,7 +441,6 @@ export default function WayLinePage({ planedevices }) {
})(),
icon: <Satellite size={16} />,
color: '#00B42A',
// 信号质量:优 / 良 → 适宜,中 → 谨慎,差/极差 → 不适宜
judge: (val) => {
if (val === '优' || val === '良' || val === '正常') return { desc: '适宜', color: '#52C41A' };
if (val === '中') return { desc: '谨慎', color: '#FF7D00' };
@@ -432,7 +448,6 @@ export default function WayLinePage({ planedevices }) {
}
},
].map((item, idx) => {
// 自动计算状态文案和颜色
const status = item.judge(item.value);
return (
<Col span={12} key={idx}>
@@ -452,13 +467,7 @@ export default function WayLinePage({ planedevices }) {
<div style={{ fontSize: fontNormal, fontWeight: 700, color: '#1D2129' }}>
{item.value}
</div>
<div
style={{
fontSize: 10,
color: status.color,
fontWeight: 500
}}
>
<div style={{ fontSize: 10, color: status.color, fontWeight: 500 }}>
{status.desc}
</div>
</div>
@@ -479,7 +488,6 @@ export default function WayLinePage({ planedevices }) {
{/* 底部内容区 */}
<Row gutter={16}>
{/* 甘特图/排班视图 */}
<Col xs={24} xl={14}>
<Card
title={<span style={{ fontSize: fontTitle, fontWeight: 700 }}>任务甘特视图 / 排班视图 <Text type="secondary" style={{ fontSize: 11, fontWeight: 400, marginLeft: 12 }}>今日 (2025-05-24)</Text></span>}
@@ -489,14 +497,12 @@ export default function WayLinePage({ planedevices }) {
style={{ ...cardStyle, height: '100%' }}
>
<div style={{ position: 'relative', border: '1px solid #F2F3F5', borderRadius: 8, padding: '16px 12px' }}>
{/* 时间轴头部 */}
<div style={{ display: 'flex', fontSize: 10, color: '#86909C', borderBottom: '1px solid #F2F3F5', paddingBottom: 10, textAlign: 'center' }}>
<div style={{ width: 140 }}></div>
<div style={{ flex: 1, display: 'flex', justifyContent: 'space-around' }}>
<span>08:00</span><span>10:00</span><span>12:00</span><span>14:00</span><span>16:00</span><span>18:00</span>
</div>
</div>
{/* 甘特条 */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}>
{[
{ 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' }] },
@@ -525,7 +531,6 @@ export default function WayLinePage({ planedevices }) {
</div>
))}
</div>
{/* 当前时间红线 */}
<div style={{ position: 'absolute', left: '38%', top: 0, bottom: 0, width: 2, background: '#F53F3F', zIndex: 1, opacity: 0.6 }}>
<div style={{ width: 6, height: 6, borderRadius: '50%', background: '#F53F3F', position: 'absolute', top: -3, left: -2 }} />
</div>
@@ -533,10 +538,39 @@ export default function WayLinePage({ planedevices }) {
</Card>
</Col>
{/* 任务看板 */}
<Col xs={24} xl={10}>
<Card
title={<span style={{ fontSize: fontTitle, fontWeight: 700 }}>工作任务看板</span>}
title={
<div className="flex justify-between items-center w-full">
<span style={{ fontSize: fontTitle, fontWeight: 700 }}>工作任务看板</span>
<Space size={8}>
<RangePicker
size="small"
showTime
format="YYYY-MM-DD HH:mm:ss"
value={boardDateRange}
onChange={(val) => setBoardDateRange(val)}
placeholder={['开始', '结束']}
/>
<Select
style={{ width: 140 }}
size="small"
placeholder="全部无人机"
showSearch
allowClear
options={planedevices?.map(item => ({
value: item.device_sn,
label: item.drone_callsign || item.device_sn
}))}
value={boardDrone?.device_sn}
onChange={(val) => {
const find = planedevices.find(i => i.device_sn === val);
setBoardDrone(find || null);
}}
/>
</Space>
</div>
}
bordered={false}
bodyStyle={{ padding: 16 }}
style={{ ...cardStyle, height: '100%' }}
@@ -544,26 +578,31 @@ export default function WayLinePage({ planedevices }) {
<Row gutter={10}>
{[
{
title: '待执行', count: 3, color: '#4E5969', bg: '#F7F8FA',
list: [
{ id: 'FL-07', name: 'AI 复检航线', device: 'UAV-A01', target: '区块 B-01-B-20' },
{ id: 'CL-05', name: '组件清洗', device: 'UAV-C01', target: '区块 C-01-C-18' },
{ id: 'RB-03', name: '围栏巡检', device: 'RBT-01', target: '围栏全线' }
]
title: '待执行', count: waitList.length, color: '#4E5969', bg: '#F7F8FA',
list: waitList.map(item => ({
id: item.sn?.slice(-5) || '',
name: item.name,
device: item.sn,
target: ''
}))
},
{
title: '执行中', count: 2, color: '#165DFF', bg: '#E8F3FF',
list: [
{ id: 'FL-03', name: '无人机巡检', device: 'UAV-A01', target: '区块 B-01-B-20', gain: '8.2%' },
{ id: 'GR-04', name: '阵列除草', device: 'GR-01', target: '区块 D-01-D-16', gain: '6.5%' }
]
title: '执行中', count: runList.length, color: '#165DFF', bg: '#E8F3FF',
list: runList.map(item => ({
id: item.sn?.slice(-5) || '',
name: item.name,
device: item.sn,
target: ''
}))
},
{
title: '已完成', count: 4, color: '#00B42A', bg: '#E8FFEA',
list: [
{ id: 'FL-01', name: '组件巡检', device: 'UAV-A01', time: '08:20', gain: '7.1%' },
{ id: 'CL-01', name: '组件清洗', device: 'UAV-C01', time: '07:45', gain: '5.9%' }
]
title: '已完成', count: finishList.length, color: '#00B42A', bg: '#E8FFEA',
list: finishList.map(item => ({
id: item.sn?.slice(-5) || '',
name: item.name,
device: item.sn,
time: item.completed_at ? dayjs(item.completed_at).format('HH:mm') : ''
}))
},
].map((col, idx) => (
<Col span={8} key={idx}>
@@ -578,7 +617,6 @@ export default function WayLinePage({ planedevices }) {
<div style={{ fontSize: 10, color: '#86909C' }}>
<div style={{ marginBottom: 2 }}>装备: {task.device || 'UAV-A01'}</div>
{task.target && <div style={{ marginBottom: 2 }}>目标: {task.target}</div>}
{task.gain && <div style={{ color: '#00B42A', fontWeight: 600 }}>预计收益: ↑ {task.gain}</div>}
{task.time && <div style={{ marginTop: 2 }}>完成时间: {task.time}</div>}
</div>
</div>