航线任务

This commit is contained in:
mmc
2026-05-11 15:48:14 +08:00
parent fa1056f51e
commit 86880ac786
7 changed files with 891 additions and 8 deletions

View File

@@ -0,0 +1,166 @@
import React, { useEffect, useRef } from 'react';
interface Props {
video: HTMLVideoElement;
idx: number;
title: string;
className?: string;
noCrop?: boolean;
}
const VideoCanvas: React.FC<Props> = ({ video, idx, title, className, noCrop }) => {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
const rafRef = useRef<number | null>(null);
const stopRender = () => {
if (rafRef.current) {
cancelAnimationFrame(rafRef.current);
rafRef.current = null;
}
clearCanvas();
};
const clearCanvas = () => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext('2d');
if (!ctx) return;
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, canvas.width, canvas.height);
};
// 🔥 绘制汽车影像辅助线
const drawGuideLines = (ctx: CanvasRenderingContext2D, canvas: HTMLCanvasElement) => {
const w = canvas.width;
const h = canvas.height;
ctx.save();
ctx.lineWidth = 2;
ctx.strokeStyle = 'rgba(0, 229, 255, 0.7)';
ctx.globalAlpha = 0.8;
// 根据视角画不同辅助线
if (title.includes('前') || title.includes('front')) {
// 前视角引导线(梯形)
ctx.beginPath();
ctx.moveTo(w * 0.25, h);
ctx.lineTo(w * 0.45, h * 0.3);
ctx.moveTo(w * 0.75, h);
ctx.lineTo(w * 0.55, h * 0.3);
ctx.stroke();
// 中线
ctx.beginPath();
ctx.setLineDash([5, 5]);
ctx.moveTo(w / 2, h);
ctx.lineTo(w / 2, h * 0.3);
ctx.stroke();
ctx.setLineDash([]);
}
if (title.includes('后') || title.includes('back')) {
// 后视角倒车线(扇形/倒车轨迹)
ctx.beginPath();
ctx.moveTo(w * 0.3, h * 0.7);
ctx.lineTo(w * 0.15, h * 0.3);
ctx.moveTo(w * 0.7, h * 0.7);
ctx.lineTo(w * 0.85, h * 0.3);
ctx.stroke();
// 倒车底线
ctx.beginPath();
ctx.moveTo(w * 0.2, h * 0.8);
ctx.lineTo(w * 0.8, h * 0.8);
ctx.stroke();
}
if (title.includes('左') || title.includes('left')) {
// 左侧线
ctx.beginPath();
ctx.moveTo(w * 0.8, h);
ctx.lineTo(w * 0.8, 0);
ctx.moveTo(w * 0.7, h);
ctx.lineTo(w * 0.7, 0);
ctx.stroke();
}
if (title.includes('右') || title.includes('right')) {
// 右侧线
ctx.beginPath();
ctx.moveTo(w * 0.2, h);
ctx.lineTo(w * 0.2, 0);
ctx.moveTo(w * 0.3, h);
ctx.lineTo(w * 0.3, 0);
ctx.stroke();
}
ctx.restore();
};
const startDraw = () => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext('2d');
if (!ctx) return;
clearCanvas();
const render = () => {
if (video.readyState >= 2) {
const vw = video.videoWidth;
const vh = video.videoHeight;
let sx = 0;
let sy = 0;
let sw = vw;
let sh = vh;
if (!noCrop) {
sw = vw / 2;
sh = vh / 2;
switch (idx) {
case 2: sx = sw; break;
case 3: sy = sh; break;
case 4: sx = sw; sy = sh; break;
}
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
// 🔥 绘制辅助线
//drawGuideLines(ctx, canvas);
}
rafRef.current = requestAnimationFrame(render);
};
render();
};
useEffect(() => {
stopRender();
if (!video) return;
startDraw();
return stopRender;
}, [video, idx, title]);
return (
<div className={`${idx == 1 ? 'flex flex-grow' : ''}relative w-full h-full rounded bg-black ${className}`}>
<canvas
ref={canvasRef}
//width={640}
//height={360}
className="w-full h-full"
/>
<div className="absolute inset-0 pointer-events-none">
<div className="absolute top-5 left-12 px-2 py-0.5 bg-black/60 rounded text-[10px] text-cyan-400">
{title}
</div>
<div className="absolute top-5 right-12 text-cyan-400 text-[8px] flex items-center gap-1">
<span className="w-1.5 h-1.5 rounded-full bg-cyan-400 animate-pulse" />
LIVE
</div>
</div>
</div>
);
};
export default VideoCanvas;

View File

@@ -0,0 +1,50 @@
import React, { useState, useEffect } from 'react';
import Empty from './Empty';
import VideoCanvas from './VideoCanvas';
interface VideoPlayerProps {
deviceId: string;
idx: number;
title?: string;
className?: string;
noCrop?: boolean;
video?: HTMLVideoElement;
error?: boolean;
ready?: boolean;
}
const VideoPlayer: React.FC<VideoPlayerProps> = ({
deviceId,
idx,
title,
className = '',
noCrop,
video, error, ready
}) => {
const viewTitles = ['前视图', '后视图', '左视图', '右视图'];
const currentTitle = title || viewTitles[idx - 1];
if (!deviceId || error) {
return <Empty message="视频源连接失败" />;
}
if (!ready || !video) {
return <Empty message="视频加载中..." />;
}
return (
<VideoCanvas
key={`canvas-${deviceId}-${idx}`}
video={video}
idx={idx}
title={currentTitle}
className={className}
noCrop={noCrop}
/>
);
};
export default VideoPlayer;

View File

@@ -45,7 +45,6 @@ const logs = [
// 设备总览组件
export default function DeviceOverviewPage({ devices, planedevices, devicesAll }) {
console.log(devicesAll, "devicesAll")
const [selectedDevice, setSelectedDevice] = useState(null);
const [planeVideo, setPlaneVideo] = useState('');
@@ -191,7 +190,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll }
/>
</Card>
<Card title={<><SettingOutlined /> <span style={{ color: '#1890ff' }}>控制日志 / 告警记录</span></>} bordered={false} style={{ borderRadius: 12 }} extra={<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Button size="small" style={{ borderRadius: 8, border: '1px solid #d9d9d9' }}>全部级别 ▼</Button></div>}>
<Card title={<><SettingOutlined /> <span >控制日志 / 告警记录</span></>} bordered={false} style={{ borderRadius: 12 }} extra={<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Button size="small" style={{ borderRadius: 8, border: '1px solid #d9d9d9' }}>全部级别 ▼</Button></div>}>
<Table rowKey="time" size="small" pagination={false} dataSource={logs} scroll={{ x: 'max-content' }}
columns={[
{ title: '时间', dataIndex: 'time', width: 100, render: t => <span style={{ fontSize: 14 }}>{t}</span> },
@@ -241,10 +240,13 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll }
<span style={{ color: '#52c41a' }}><ThunderboltOutlined /></span>
<span style={{ fontSize: 12 }}>电量 {fix2(selectedDevice.capacity_percent || 100)}%</span>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{ fontSize: 12 }}>温度</span>
<span style={{ color: '#faad14' }}>{fix2(selectedDevice.environment_temperature || 25)}℃</span>
</div>
{selectedDevice.environment_temperature && (
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{ fontSize: 12 }}>温度</span>
<span style={{ color: '#faad14' }}>{fix2(selectedDevice.environment_temperature || 25)}℃</span>
</div>
)}
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, marginBottom: 12, maxHeight: "160px", overflow: "auto", scrollbarWidth: 'thin', scrollbarColor: '#ccc transparent' }}>
@@ -382,7 +384,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll }
{/* 条件渲染:机器人显示其余信息(此处以任务详情为例) */}
{(!selectedDevice?.productName?.includes('无人机') && !selectedDevice?.device_sn) && (
<Card title="机器人作业状态" bordered={false} style={{ borderRadius: 12, marginBottom: 16 }}>
<Card title={<><RobotOutlined /> 机器人作业状态</>} bordered={false} style={{ borderRadius: 12, marginBottom: 16 }}>
<Row gutter={16}>
<Col span={8}>
<Statistic title="累计里程" value={128.5} suffix="km" valueStyle={{ fontSize: 20 }} />

View File

@@ -0,0 +1,356 @@
import React, { useState } from 'react';
import {
Row, Col, Card, Button, Space, Table, Tag, Typography, Progress, Badge,
Tabs, Input, Switch, Divider, Tooltip, Timeline
} from 'antd';
import {
PlusOutlined, ImportOutlined, NodeIndexOutlined, SafetyCertificateOutlined,
SaveOutlined, FullscreenOutlined, EnvironmentOutlined, RobotOutlined,
BranchesOutlined, CloudOutlined, ThunderboltOutlined, CheckCircleOutlined,
InfoCircleOutlined, ClockCircleOutlined, RiseOutlined, FallOutlined,
SettingOutlined, WarningOutlined, ArrowRightOutlined, CloudSyncOutlined
} from '@ant-design/icons';
const { Text, Title } = Typography;
export default function WayLinePage() {
const [activeMainTab, setActiveTab] = useState('wayline');
const cardStyle = { borderRadius: 8, border: 'none', boxShadow: '0 2px 8px rgba(0,0,0,0.05)' };
// 模拟数据
const topCards = [
{ title: '今日航线计划', value: '18', unit: '条', trend: '较昨日 +2', color: '#165DFF', icon: <NodeIndexOutlined /> },
{ title: '执行中任务', value: '6', unit: '个', desc: '进行中', color: '#165DFF', icon: <NodeIndexOutlined /> },
{ title: '待审批任务', value: '4', unit: '个', trend: '较昨日 -1', color: '#FF7D00', icon: <SafetyCertificateOutlined /> },
{ title: '任务完成率', value: '92', unit: '%', trend: '较昨日 +6%', color: '#00B42A', icon: <CheckCircleOutlined /> },
{ title: 'AI 优化收益', value: '+7.8', unit: '%', trend: '较昨日 +1.2%', color: '#722ED1', icon: <RiseOutlined /> },
{ title: '覆盖装备', value: '4类 / 9台', unit: '', desc: '全部在线', color: '#165DFF', icon: <RobotOutlined /> },
];
return (
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '16px 24px' }}>
{/* 顶部统计卡片 */}
<Row gutter={12} style={{ marginBottom: 16 }}>
{topCards.map((item, index) => (
<Col span={4} key={index}>
<Card bordered={false} bodyStyle={{ padding: 16 }} style={cardStyle}>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<div style={{ width: 40, height: 40, background: `${item.color}15`, borderRadius: 8, display: 'flex', justifyContent: 'center', alignItems: 'center', color: item.color, fontSize: 20 }}>
{item.icon}
</div>
<div>
<div style={{ fontSize: 12, color: '#86909C' }}>{item.title}</div>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4 }}>
<span style={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }}>{item.value}</span>
<span style={{ fontSize: 12, color: '#4E5969' }}>{item.unit}</span>
</div>
<div style={{ fontSize: 11, color: item.trend?.includes('+') ? '#00B42A' : '#F53F3F' }}>
{item.trend || item.desc}
</div>
</div>
</div>
</Card>
</Col>
))}
</Row>
{/* 中间主要内容区 */}
<Row gutter={12} style={{ marginBottom: 16 }}>
{/* 左侧:航线编辑与路径规划 */}
<Col span={14}>
<Card
title={<span style={{ fontSize: 14, fontWeight: 700 }}>航线编辑与路径规划</span>}
extra={
<Space>
<Button size="small" icon={<PlusOutlined />}>新增航线</Button>
<Button size="small" icon={<ImportOutlined />}>导入模板</Button>
<Button size="small" icon={<NodeIndexOutlined />}>路径优化</Button>
<Button size="small" icon={<SafetyCertificateOutlined />}>风险检查</Button>
<Button size="small" icon={<SaveOutlined />}>保存草稿</Button>
<Button size="small" icon={<FullscreenOutlined />} />
</Space>
}
bordered={false}
bodyStyle={{ padding: 0, position: 'relative' }}
style={{ ...cardStyle, marginBottom: "16px" }}
>
{/* 模拟地图区域 */}
<div style={{ width: '100%', height: 500, background: '#e8f3ff url(https://picsum.photos/seed/solarfarm_map/1200/800) center/cover', position: 'relative' }}>
{/* 左侧图例 */}
<div style={{ position: 'absolute', top: 16, left: 16, background: 'rgba(255,255,255,0.9)', padding: 12, borderRadius: 4, width: 140 }}>
<div style={{ fontSize: 12, display: 'flex', flexDirection: 'column', gap: 8 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><span style={{ width: 12, height: 2, background: '#165DFF' }}></span> 无人机航线</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><span style={{ width: 12, height: 2, background: '#FF7D00' }}></span> 巡检机器人路线</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><span style={{ width: 12, height: 2, background: '#00B42A' }}></span> 除草路线</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><span style={{ width: 12, height: 2, background: '#13C2C2' }}></span> 清洗航线</div>
<Divider style={{ margin: '4px 0' }} />
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><div style={{ width: 16, height: 16, background: '#165DFF', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center', color: '#fff', fontSize: 10 }}>H</div> 无人机机场</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>< ThunderboltOutlined style={{ color: '#00B42A' }} /> 充电点</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><CloudSyncOutlined style={{ color: '#165DFF' }} /> 补水点</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><WarningOutlined style={{ color: '#F53F3F' }} /> 禁飞区</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><div style={{ width: 12, height: 12, border: '1px dashed #F53F3F' }} /> 高优先级巡检区</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><div style={{ width: 12, height: 12, background: 'rgba(255,125,0,0.3)' }} /> 障碍物区域</div>
</div>
</div>
{/* 地图上的模拟标注 */}
<div style={{ position: 'absolute', top: '20%', left: '20%', color: '#fff', textAlign: 'center' }}>
<div style={{ background: '#165DFF', borderRadius: '50%', width: 24, height: 24, display: 'inline-flex', justifyContent: 'center', alignItems: 'center' }}>H</div>
<div style={{ fontSize: 10, background: 'rgba(0,0,0,0.5)', padding: '0 4px' }}>无人机机场 A01</div>
</div>
<div style={{ position: 'absolute', top: '40%', left: '50%', border: '2px dashed #F53F3F', width: 120, height: 80, display: 'flex', justifyContent: 'center', alignItems: 'center', color: '#fff' }}>
<div style={{ fontSize: 10, background: 'rgba(0,0,0,0.5)', padding: '0 4px' }}>高优先级巡检区 B-12</div>
</div>
</div>
</Card>
<Card
title={<span style={{ fontSize: 14, fontWeight: 700 }}>航点列表 <Text type="secondary" style={{ fontSize: 11, fontWeight: 400 }}>航线:FL-03 (无人机热斑巡检)</Text></span>}
extra={<PlusOutlined style={{ cursor: 'pointer' }} />}
bordered={false}
bodyStyle={{ padding: 0 }}
style={cardStyle}
>
<Table
size="small"
pagination={false}
scroll={{ y: 240 }}
dataSource={[
{ key: '1', point: 'WP-01', coord: '30.32921, 120.12345', action: '起飞', height: 35, speed: 6.0, stay: 0, remark: '从机场起飞' },
{ key: '2', point: 'WP-02', coord: '区块 B-01', action: '拍摄', height: 35, speed: 6.0, stay: 2, remark: '组件可见光' },
{ key: '3', point: 'WP-03', coord: '区块 B-05', action: '热成像', height: 35, speed: 6.0, stay: 3, remark: '热斑检测' },
{ key: '4', point: 'WP-04', coord: '区块 B-09', action: '悬停', height: 35, speed: 0.0, stay: 10, remark: '重点检查' },
{ key: '5', point: 'WP-05', coord: '区块 B-12', action: '热成像', height: 35, speed: 6.0, stay: 3, remark: '高优先区' },
{ key: '6', point: 'WP-06', coord: '区块 B-16', action: '拍摄', height: 35, speed: 6.0, stay: 2, remark: '组件可见光' },
{ key: '7', point: 'WP-07', coord: '区块 B-20', action: '悬停', height: 35, speed: 0.0, stay: 10, remark: '末端确认' },
{ key: '8', point: 'WP-08', coord: '30.32910, 120.12380', action: '返航', height: 35, speed: 6.0, stay: 0, remark: '返回机场' },
]}
columns={[
{ title: '航点', dataIndex: 'point', width: 60 },
{ title: '坐标/区域', dataIndex: 'coord', width: 100, ellipsis: true },
{ title: '动作', dataIndex: 'action', width: 60 },
{ title: '高度(m)', dataIndex: 'height', width: 60 },
{ title: '速度(m/s)', dataIndex: 'speed', width: 80 },
{ title: '停留(s)', dataIndex: 'stay', width: 60 },
{ title: '备注', dataIndex: 'remark', ellipsis: true },
]}
/>
</Card>
</Col>
{/* 右侧:任务编排、参数与天气 */}
<Col span={10}>
<Card
title={<span style={{ fontSize: 14, fontWeight: 700 }}>任务编排与 AI 建议</span>}
bordered={false}
bodyStyle={{ padding: 12 }}
style={{ ...cardStyle, marginBottom: 12 }}
>
<Table
size="small"
pagination={false}
dataSource={[
{ key: '1', id: 'FL-03', device: 'UAV-A01', type: '无人机热斑巡检', level: '高', time: '10:00 - 11:20', duration: '1h20m', status: '建议执行' },
{ key: '2', id: 'RB-02', device: 'RBT-01', type: '围栏巡检', level: '高', time: '11:30 - 12:30', duration: '1h00m', status: '建议执行' },
{ key: '3', id: 'CL-05', device: 'UAV-C01', type: '组件清洗', level: '中', time: '14:00 - 16:00', duration: '2h00m', status: '等待执行' },
{ key: '4', id: 'GR-04', device: 'GR-01', type: '阵列除草', level: '中', time: '09:30 - 11:30', duration: '2h00m', status: '建议执行' },
{ key: '5', id: 'FL-07', device: 'UAV-A01', type: 'AI 复检航线', level: '低', time: '16:30 - 17:10', duration: '0h40m', status: '待审批' },
]}
columns={[
{ title: '任务编号', dataIndex: 'id', width: 80, render: (t) => <Text style={{ color: '#165DFF' }}>{t}</Text> },
{ title: '装备', dataIndex: 'device' },
{ title: '类型', dataIndex: 'type', ellipsis: true },
{ title: '优先级', dataIndex: 'level', render: (l) => <span style={{ color: l === '高' ? '#F53F3F' : l === '中' ? '#FF7D00' : '#86909C' }}>▲ {l}</span> },
{ title: '建议时间', dataIndex: 'time' },
{ title: '预计时长', dataIndex: 'duration' },
{ title: '状态', dataIndex: 'status', render: (s) => <Text style={{ color: s.includes('建议') ? '#165DFF' : '#86909C' }}>{s}</Text> },
]}
/>
<div style={{ background: '#F2F3F5', padding: '8px 12px', borderRadius: 4, marginTop: 12, display: 'flex', gap: 12, fontSize: 12 }}>
<span style={{ fontWeight: 700 }}>AI 建议:</span>
<Space split={<Divider type="vertical" />}>
<span><CheckCircleOutlined style={{ color: '#165DFF' }} /> 推荐优先执行 FL-03 航线</span>
<span><ClockCircleOutlined style={{ color: '#165DFF' }} /> 14:00-16:00 风速最佳</span>
<span><WarningOutlined style={{ color: '#FF7D00' }} /> 区块 B-12 存在高温风险</span>
</Space>
</div>
<Row gutter={12} style={{ marginTop: 12 }}>
<Col span={8}><Button type="primary" block style={{ background: '#165DFF' }}>一键排程</Button></Col>
<Col span={8}><Button type="primary" block style={{ background: '#165DFF' }}>智能分配</Button></Col>
<Col span={8}><Button type="primary" block style={{ background: '#165DFF' }}>生成工单</Button></Col>
</Row>
</Card>
<Card
title={<span style={{ fontSize: 14, fontWeight: 700 }}>航线参数 / 作业参数</span>}
extra={<Text type="secondary" style={{ fontSize: 12 }}>当前航线:FL-03</Text>}
bordered={false}
bodyStyle={{ padding: 12 }}
style={{ ...cardStyle, marginBottom: 12 }}
>
<Row gutter={[24, 12]}>
{[
{ 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) => (
<Col span={6} key={idx}>
<div style={{ fontSize: 11, color: '#86909C', marginBottom: 4 }}>{item.label}</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
<Input size="small" defaultValue={item.value} style={{ width: 40, height: 22, padding: '0 4px', fontSize: 12 }} />
<span style={{ fontSize: 11 }}>{item.unit}</span>
</div>
</Col>
))}
</Row>
<Divider style={{ margin: '12px 0' }} />
<Space size="large">
<Space>
<span style={{ fontSize: 12 }}>避障开关</span>
<Switch size="small" defaultChecked />
</Space>
<Space>
<span style={{ fontSize: 12 }}>夜航限制</span>
<Switch size="small" />
</Space>
</Space>
</Card>
<Card
title={<span style={{ fontSize: 14, fontWeight: 700 }}>天气窗口与执行约束</span>}
bordered={false}
bodyStyle={{ padding: 12 }}
style={cardStyle}
>
<Row gutter={12} align="middle">
<Col span={5}>
<div style={{ textAlign: 'center', background: '#F6FFED', padding: '8px 4px', borderRadius: 4, border: '1px solid #B7EB8F' }}>
<div style={{ fontSize: 11, color: '#52C41A', fontWeight: 700 }}>适宜执行</div>
<div style={{ width: 16, height: 16, background: '#52C41A', borderRadius: '50%', margin: '4px auto', display: 'flex', justifyContent: 'center', alignItems: 'center', color: '#fff', fontSize: 10 }}><CheckCircleOutlined /></div>
<div style={{ fontSize: 10, color: '#86909C' }}>适宜执行</div>
</div>
</Col>
{[
{ label: '风速', value: '2.8 m/s', desc: '适宜', icon: <CloudSyncOutlined />, color: '#165DFF' },
{ label: '温度', value: '28℃', desc: '适宜', icon: < ThunderboltOutlined />, color: '#FF7D00' },
{ label: '降水概率', value: '10%', desc: '极低', icon: <CloudOutlined />, color: '#165DFF' },
{ label: 'GNSS质量', value: '良好', desc: '适宜', icon: <EnvironmentOutlined />, color: '#00B42A' },
].map((item, idx) => (
<Col span={4.5} key={idx} style={{ flex: 1 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div style={{ color: item.color, fontSize: 16 }}>{item.icon}</div>
<div>
<div style={{ fontSize: 10, color: '#86909C' }}>{item.label}</div>
<div style={{ fontSize: 12, fontWeight: 700 }}>{item.value}</div>
<div style={{ fontSize: 10, color: '#86909C' }}>{item.desc}</div>
</div>
</div>
</Col>
))}
</Row>
<div style={{ marginTop: 12, display: 'flex', justifyContent: 'space-between', fontSize: 11, color: '#86909C' }}>
<span><InfoCircleOutlined style={{ color: '#FF7D00' }} /> 16:30 后风速升高,建议提前完成任务</span>
<span><ClockCircleOutlined style={{ color: '#165DFF' }} /> 预计 14:00-16:00 为最佳执行窗口</span>
</div>
</Card>
</Col>
</Row>
{/* 底部内容区 */}
<Row gutter={12}>
{/* 甘特图/排班视图 */}
<Col span={14}>
<Card
title={<span style={{ fontSize: 14, fontWeight: 700 }}>任务甘特视图 / 排班视图 <Text type="secondary" style={{ fontSize: 11, fontWeight: 400 }}>今日 (2025-05-24)</Text></span>}
extra={<SettingOutlined style={{ cursor: 'pointer' }} />}
bordered={false}
bodyStyle={{ padding: 12 }}
style={{ ...cardStyle, height: '100%' }} // 👈 高度 100%
>
<div style={{ height: 260, position: 'relative', border: '1px solid #F2F3F5', borderRadius: 4, padding: 8 }}>
{/* 模拟时间轴头部 */}
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 10, color: '#86909C', borderBottom: '1px solid #F2F3F5', paddingBottom: 4 }}>
<div style={{ width: 100 }}></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: 12, marginTop: 12 }}>
{[
{ label: '无人机机场 A01 (UAV-A01)', tasks: [{ start: '25%', width: '15%', title: 'FL-03 巡检', color: '#165DFF' }, { start: '70%', width: '10%', title: 'FL-07 复检', color: '#165DFF' }] },
{ label: '巡检机器人 RBT-01', tasks: [{ start: '40%', width: '15%', title: 'RB-02 巡检', color: '#FF7D00' }] },
{ label: '除草机器人 GR-01', tasks: [{ start: '10%', width: '25%', title: 'GR-04 阵列除草', color: '#00B42A' }] },
{ label: '清洗无人机 UAV-C01', tasks: [{ start: '60%', width: '20%', title: 'CL-05 组件清洗', color: '#13C2C2' }] },
].map((row, idx) => (
<div key={idx} style={{ display: 'flex', alignItems: 'center' }}>
<div style={{ width: 100, fontSize: 10, color: '#4E5969' }}>{row.label}</div>
<div style={{ flex: 1, height: 32, background: '#F7F8FA', borderRadius: 4, position: 'relative' }}>
{row.tasks.map((task, tidx) => (
<div key={tidx} style={{ position: 'absolute', left: task.start, width: task.width, height: '100%', background: task.color, opacity: 0.8, borderRadius: 4, color: '#fff', fontSize: 9, padding: '2px 4px', display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
<div>{task.title}</div>
<div>10:00-11:20</div>
</div>
))}
</div>
</div>
))}
</div>
{/* 垂直当前时间红线 */}
<div style={{ position: 'absolute', left: '35%', top: 0, bottom: 0, width: 1, background: '#F53F3F', zIndex: 1 }} />
</div>
</Card>
</Col>
{/* 任务看板 */}
<Col span={10}>
<Card
title={<span style={{ fontSize: 14, fontWeight: 700 }}>工作任务看板</span>}
bordered={false}
bodyStyle={{ padding: 12 }}
style={{ ...cardStyle, height: '100%', display: 'flex', flexDirection: 'column' }} // 👈 高度 100%
>
<div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}> {/* 👈 自动撑满 */}
<Row gutter={8}>
{[
{ title: '待执行 (3)', bg: '#F7F8FA', list: [{ id: 'FL-07', name: 'AI 复检航线', device: 'UAV-A01', handler: '王工' }, { id: 'CL-05', name: '组件清洗', device: 'UAV-C01', handler: '李工' }] },
{ title: '执行中 (2)', bg: '#E8F3FF', list: [{ id: 'FL-03', name: '无人机热斑巡检', device: 'UAV-A01', handler: '王工', gain: '+8.2%' }, { id: 'GR-04', name: '阵列除草', device: 'GR-01', handler: '赵工' }] },
{ title: '已完成 (4)', bg: '#E8FFEA', list: [{ id: 'FL-01', name: '组件巡检', device: 'UAV-A01', handler: '王工', gain: '+7.1%', time: '08:20' }, { id: 'CL-01', name: '组件清洗', device: 'UAV-C01', handler: '李工', gain: '+5.9%', time: '07:45' }] },
].map((col, idx) => (
<Col span={8} key={idx}>
<div style={{ background: col.bg, borderRadius: 4, padding: 8, height: '100%', minHeight: 260 }}>
<div style={{ fontSize: 12, fontWeight: 700, marginBottom: 8 }}>{col.title}</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{col.list.map((task, tidx) => (
<div key={tidx} style={{ background: '#fff', borderRadius: 4, padding: 8, boxShadow: '0 1px 2px rgba(0,0,0,0.05)' }}>
<div style={{ fontSize: 11, fontWeight: 700, color: '#165DFF' }}>{task.id} {task.name}</div>
<div style={{ fontSize: 10, color: '#86909C', marginTop: 4 }}>装备: {task.device} | 负责人: {task.handler}</div>
{task.gain && <div style={{ fontSize: 10, color: '#00B42A', marginTop: 4 }}>预计收益: {task.gain}</div>}
{task.time && <div style={{ fontSize: 10, color: '#86909C', marginTop: 2 }}>完成时间: {task.time}</div>}
</div>
))}
</div>
</div>
</Col>
))}
</Row>
</div>
<div style={{ textAlign: 'right', marginTop: 8 }}>
<Button type="link" size="small">查看全部 <ArrowRightOutlined /></Button>
</div>
</Card>
</Col>
</Row>
</div>
);
}

View File

@@ -0,0 +1,220 @@
import React, { useEffect, useState, useRef } from 'react';
const XboxController = ({ onGamepadUpdate, handleControlModal, isControlled }) => {
const [gamepadState, setGamepadState] = useState<{
buttons: boolean[];
axes: number[];
connected: boolean;
}>({
buttons: new Array(17).fill(false),
axes: [0, 0, 0, 0],
connected: false,
});
const requestRef = useRef<number>(null);
const DEAD_ZONE = 0.08;
const normalizeAxis = (v: number) =>
Math.abs(v) < DEAD_ZONE ? 0 : Number(v.toFixed(2));
const lastSendRef = useRef(0);
const SEND_INTERVAL = 1000 / 10; // 20Hz
const lastPayloadRef = useRef('');
const updateGamepad = () => {
const gp = navigator.getGamepads()[0];
if (gp) {
const state = {
buttons: gp.buttons.map(b => b.pressed),
axes: gp.axes.map(normalizeAxis),
connected: true,
ts: Date.now(),
};
setGamepadState(state);
const payload = JSON.stringify({
buttons: state.buttons,
axes: state.axes,
});
const now = performance.now();
if (
now - lastSendRef.current > SEND_INTERVAL
// payload !== lastPayloadRef.current
) {
onGamepadUpdate(state); // ✅ 只有这里才发
lastSendRef.current = now;
lastPayloadRef.current = payload;
}
}
if (!gp) {
// 不要在这里停 RAF
requestRef.current = requestAnimationFrame(updateGamepad);
return;
}
requestRef.current = requestAnimationFrame(updateGamepad);
};
useEffect(() => {
requestRef.current = requestAnimationFrame(updateGamepad);
const onFocus = () => {
// 页面重新获得焦点 → 立刻重拉一次
requestRef.current = requestAnimationFrame(updateGamepad);
};
window.addEventListener('focus', onFocus);
return () => {
if (requestRef.current) cancelAnimationFrame(requestRef.current);
window.removeEventListener('focus', onFocus);
};
}, []); // ✅ 空依赖
useEffect(() => {
setTimeout(() => {
window.focus();
navigator.getGamepads(); // 🔥 强制触发一次
}, 0);
}, [/* 页面切换依赖 */]);
useEffect(() => {
const handleConnect = (e: GamepadEvent) => {
console.log('🎮 Gamepad connected:', e.gamepad.id);
setGamepadState(prev => ({ ...prev, connected: true }));
};
const handleDisconnect = (e: GamepadEvent) => {
console.log('❌ Gamepad disconnected');
handleControlModal({ control: false });
setGamepadState(prev => ({ ...prev, connected: false }));
};
window.addEventListener('gamepadconnected', handleConnect);
window.addEventListener('gamepaddisconnected', handleDisconnect);
return () => {
window.removeEventListener('gamepadconnected', handleConnect);
window.removeEventListener('gamepaddisconnected', handleDisconnect);
};
}, []);
// UI mapping for Xbox Gamepad
// Buttons: 0:A, 1:B, 2:X, 3:Y, 4:LB, 5:RB, 6:LT, 7:RT, 8:Back, 9:Start, 10:LS, 11:RS, 12:Up, 13:Down, 14:Left, 15:Right
const { buttons, axes, connected } = gamepadState;
const getAxisStyle = (axisX: number, axisY: number) => ({
transform: `translate(${axisX * 6}px, ${axisY * 6}px)`,
});
return (
<div className="relative w-full aspect-[4/3] flex items-center justify-center "
onClick={() => {
if (connected && !isControlled) {
// 这里写点击后要执行的逻辑,比如打开权限请求弹窗
console.log("点击了无控制权限,发起权限请求");
// 示例:调用你代码中已有的权限请求弹窗逻辑
handleControlModal({ control: true, type: "switchPermission" });
}
}}>
{/* Gamepad Status Badge */}
<div
className={`absolute top-0 right-0 px-2 py-0.5 rounded text-[8px] font-bold tracking-widest border
${connected
? (isControlled
? 'bg-cyan-500/20 text-cyan-400 border-cyan-500/30' // 控制中:青色样式
: 'bg-red-500/20 text-red-400 border-red-500/30') // 无控制权限:红色样式
: 'bg-slate-800 text-slate-500 border-white/5'}`} // 无控制器连接:灰色样式
>
{connected ? isControlled ? '控制中' : '重新选中设备获取控制权限' : '无控制器连接'}
</div>
<svg viewBox="0 0 400 300" className="w-full h-full drop-shadow-[0_0_20px_rgba(34,211,238,0.15)]">
{/* Main Body */}
<path
d="M100 80 Q50 80 40 130 L30 220 Q25 270 80 280 L140 250 L260 250 L320 280 Q375 270 370 220 L360 130 Q350 80 300 80 Z"
fill="#1e293b"
stroke={connected ? "#22d3ee" : "#334155"}
strokeWidth="3"
transform="scale(1, 1.08)"
transformOrigin="200px 180px"
/>
{/* Triggers & Bumpers */}
<rect x="70" y="50" width="50" height="25" rx="5" fill={buttons[4] ? "#22d3ee" : "#0f172a"} stroke="#22d3ee" strokeWidth="1" opacity={buttons[4] ? 1 : 0.3} />
<rect x="280" y="50" width="50" height="25" rx="5" fill={buttons[5] ? "#22d3ee" : "#0f172a"} stroke="#22d3ee" strokeWidth="1" opacity={buttons[5] ? 1 : 0.3} />
{/* LT / RT Indicators */}
<path d="M80 30 L110 30 Q115 45 95 50 L80 50 Z" fill={buttons[6] ? "#22d3ee" : "transparent"} stroke="#22d3ee" strokeWidth="1" opacity={buttons[6] ? 1 : 0.2} />
<path d="M320 30 L290 30 Q285 45 305 50 L320 50 Z" fill={buttons[7] ? "#22d3ee" : "transparent"} stroke="#22d3ee" strokeWidth="1" opacity={buttons[7] ? 1 : 0.2} />
{/* Left Stick Area */}
<circle cx="120" cy="140" r="35" fill="#0f172a" stroke="#22d3ee" strokeWidth="1" strokeDasharray="2 2" />
<g style={getAxisStyle(axes[0] || 0, axes[1] || 0)}>
<circle cx="120" cy="140" r="28" fill="#1e293b" stroke="#22d3ee" strokeWidth="2" />
<circle cx="120" cy="140" r="12" fill={buttons[10] ? "#22d3ee" : "transparent"} stroke="#22d3ee" strokeWidth="1" />
</g>
{/* Right Stick Area */}
<g transform="translate(0, 20)">
<circle
cx="280"
cy="200"
r="35"
fill="#0f172a"
stroke="#22d3ee"
strokeWidth="1"
strokeDasharray="2 2"
/>
<g style={getAxisStyle(axes[2] || 0, axes[3] || 0)}>
<circle
cx="280"
cy="200"
r="28"
fill="#1e293b"
stroke="#22d3ee"
strokeWidth="2"
/>
<circle
cx="280"
cy="200"
r="12"
fill={buttons[11] ? "#22d3ee" : "transparent"}
stroke="#22d3ee"
strokeWidth="1"
/>
</g>
</g>
{/* D-Pad */}
<g transform="translate(130, 220)">
<path d="M0 -25 L0 25 M-25 0 L25 0" stroke="#334155" strokeWidth="15" strokeLinecap="round" />
<path d="M0 -25 L0 -10" stroke={buttons[12] ? "#22d3ee" : "#64748b"} strokeWidth="12" strokeLinecap="round" />
<path d="M0 25 L0 10" stroke={buttons[13] ? "#22d3ee" : "#64748b"} strokeWidth="12" strokeLinecap="round" />
<path d="M-25 0 L-10 0" stroke={buttons[14] ? "#22d3ee" : "#64748b"} strokeWidth="12" strokeLinecap="round" />
<path d="M25 0 L10 0" stroke={buttons[15] ? "#22d3ee" : "#64748b"} strokeWidth="12" strokeLinecap="round" />
</g>
{/* Buttons (ABXY) */}
<g transform="translate(280, 140)">
<circle cx="0" cy="20" r="12" fill={buttons[0] ? "#22c55e" : "#0f172a"} stroke="#22c55e" strokeWidth="1" opacity={buttons[0] ? 1 : 0.6} /> {/* A */}
<circle cx="20" cy="0" r="12" fill={buttons[1] ? "#ef4444" : "#0f172a"} stroke="#ef4444" strokeWidth="1" opacity={buttons[1] ? 1 : 0.6} /> {/* B */}
<circle cx="-20" cy="0" r="12" fill={buttons[2] ? "#3b82f6" : "#0f172a"} stroke="#3b82f6" strokeWidth="1" opacity={buttons[2] ? 1 : 0.6} /> {/* X */}
<circle cx="0" cy="-20" r="12" fill={buttons[3] ? "#eab308" : "#0f172a"} stroke="#eab308" strokeWidth="1" opacity={buttons[3] ? 1 : 0.6} /> {/* Y */}
</g>
{/* Menu Buttons */}
<circle cx="180" cy="140" r="6" fill={buttons[8] ? "#22d3ee" : "#334155"} />
<circle cx="220" cy="140" r="6" fill={buttons[9] ? "#22d3ee" : "#334155"} />
</svg>
</div>
);
};
export default XboxController;

View File

@@ -0,0 +1,86 @@
import { useEffect, useRef, useState } from 'react';
declare const JSWebrtc: any;
// 🔥 修复:url 变成必传,deviceId + url 共同作为唯一标识
export function useWebRTCPlayer(deviceId: string, url: string) {
const videoRef = useRef<HTMLVideoElement | null>(null);
const playerRef = useRef<any>(null);
const readyRef = useRef(false);
const [ready, setReady] = useState(false);
const [error, setError] = useState(false);
// 统一销毁
const destroyPlayer = () => {
if (playerRef.current) {
try { playerRef.current.destroy(); } catch { }
playerRef.current = null;
}
if (videoRef.current) {
try {
videoRef.current.pause();
videoRef.current.srcObject = null;
} catch { }
videoRef.current = null;
}
readyRef.current = false;
setReady(false);
setError(false);
};
// 🔥 修复依赖:[deviceId, url]
useEffect(() => {
if (!deviceId || !url) {
destroyPlayer();
return;
}
destroyPlayer();
// 每个 Hook 创建独立 video
const v = document.createElement('video');
v.autoplay = true;
v.muted = true;
v.playsInline = true;
v.style.width = '100%';
v.style.height = '100%';
v.style.objectFit = 'contain';
videoRef.current = v;
const token = localStorage.getItem('videotoken') || JSON.parse(localStorage.getItem('userInfo') || '{}')?.token;
const videoUrl = `${url}?token=${token}`;
try {
const player = new JSWebrtc.Player(videoUrl, {
video: v,
autoplay: true,
onPlay: () => {
setReady(true);
setError(false);
readyRef.current = true;
},
onError: (err: any) => {
console.error('播放错误', deviceId, url, err);
setError(true);
setReady(false);
},
});
playerRef.current = player;
} catch (e) {
console.error('初始化失败', e);
setError(true);
}
return () => {
destroyPlayer();
};
}, [deviceId, url]); // 🔥 必须加 url
return {
video: videoRef.current,
ready,
error,
destroyPlayer,
};
}