feat: 航线解析以及websocket订阅不关闭bug修复
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
* - 生产环境由网关/容器转发,此文件不生效
|
||||
*/
|
||||
const GATEWAY = process.env.GATEWAY_ORIGIN || 'http://192.168.2.214:9900';
|
||||
// WebSocket 网关地址(与 HTTP 网关相同)
|
||||
const WS_GATEWAY = GATEWAY.replace('http://', 'ws://').replace('https://', 'wss://');
|
||||
// SRS流媒体服务器地址
|
||||
const SRS_SERVER = process.env.SRS_SERVER || 'http://220.205.16.27:8024';
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,152 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Modal, Form, Select, message, Spin } from 'antd';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { waylineRouteApi } from '@/services/waylineRoute';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
interface BindDeviceModalProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
wayline: any;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
const BindDeviceModal: React.FC<BindDeviceModalProps> = ({
|
||||
visible,
|
||||
onVisibleChange,
|
||||
wayline,
|
||||
onSuccess
|
||||
}) => {
|
||||
const [form] = Form.useForm();
|
||||
const [deviceList, setDeviceList] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
// 加载设备列表
|
||||
const loadDeviceList = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 获取所有设备列表
|
||||
const res = await deviceApi.deviceList({ page: 1, limit: 1000 });
|
||||
if (res?.data) {
|
||||
setDeviceList(res.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载设备列表失败:', error);
|
||||
message.error('加载设备列表失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
loadDeviceList();
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
const values = await form.validateFields();
|
||||
if (!values.deviceSn) {
|
||||
message.error('请选择设备');
|
||||
return;
|
||||
}
|
||||
|
||||
setSubmitting(true);
|
||||
const hide = message.loading('正在绑定设备...');
|
||||
|
||||
try {
|
||||
// 调用后端接口,绑定设备并解析航线
|
||||
const res = await waylineRouteApi.bindWaylineToDevice({
|
||||
deviceSn: values.deviceSn,
|
||||
waylineId: wayline.waylineId,
|
||||
waylineName: wayline.name,
|
||||
workspaceId: wayline.workspaceId
|
||||
});
|
||||
|
||||
if (res.resp_code === 0) {
|
||||
message.success('设备绑定成功,航线解析完成');
|
||||
onSuccess?.();
|
||||
handleCancel();
|
||||
} else {
|
||||
message.error(res.resp_msg || '绑定失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('绑定设备失败:', error);
|
||||
const errorMsg = error?.response?.data?.resp_msg || error?.message || '绑定失败';
|
||||
message.error(errorMsg);
|
||||
} finally {
|
||||
hide();
|
||||
setSubmitting(false);
|
||||
}
|
||||
} catch (error) {
|
||||
// 表单验证失败
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
form.resetFields();
|
||||
onVisibleChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title="绑定设备"
|
||||
open={visible}
|
||||
onOk={handleOk}
|
||||
onCancel={handleCancel}
|
||||
confirmLoading={submitting}
|
||||
width={600}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={{
|
||||
waylineName: wayline?.name,
|
||||
waylineId: wayline?.waylineId
|
||||
}}
|
||||
>
|
||||
<Form.Item label="航线名称">
|
||||
<span>{wayline?.name}</span>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="航线ID">
|
||||
<span>{wayline?.waylineId}</span>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="选择设备"
|
||||
name="deviceSn"
|
||||
rules={[{ required: true, message: '请选择设备' }]}
|
||||
>
|
||||
<Select
|
||||
placeholder="请选择要绑定的设备"
|
||||
showSearch
|
||||
filterOption={(input, option) =>
|
||||
option?.children?.toString().toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
loading={loading}
|
||||
>
|
||||
{deviceList.map(device => (
|
||||
<Option key={device.deviceSn} value={device.deviceSn}>
|
||||
{device.deviceName || device.deviceSn}
|
||||
{device.deviceName && device.deviceSn && ` (${device.deviceSn})`}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
{deviceList.length === 0 && !loading && (
|
||||
<div style={{ textAlign: 'center', color: '#999', padding: '20px 0' }}>
|
||||
暂无可用设备
|
||||
</div>
|
||||
)}
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default BindDeviceModal;
|
||||
@@ -0,0 +1,292 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Modal, Table, Tag, Tabs, Card, Spin, message, Descriptions, Space } from 'antd';
|
||||
import {
|
||||
EnvironmentOutlined,
|
||||
ControlOutlined,
|
||||
ClockCircleOutlined,
|
||||
NumberOutlined,
|
||||
LineOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { waylineRouteApi, WaypointVO, WaypointActionVO } from '@/services/waylineRoute';
|
||||
|
||||
const { TabPane } = Tabs;
|
||||
|
||||
interface WaylineDetailModalProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
wayline: any;
|
||||
}
|
||||
|
||||
const WaylineDetailModal: React.FC<WaylineDetailModalProps> = ({
|
||||
visible,
|
||||
onVisibleChange,
|
||||
wayline
|
||||
}) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [routeDetail, setRouteDetail] = useState<any>(null);
|
||||
const [activeTab, setActiveTab] = useState('waypoints');
|
||||
|
||||
useEffect(() => {
|
||||
if (visible && wayline?.waylineId) {
|
||||
loadRouteDetail();
|
||||
}
|
||||
}, [visible, wayline]);
|
||||
|
||||
const loadRouteDetail = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 首先通过waylineId获取航线任务列表,查找对应的routeId
|
||||
const res = await waylineRouteApi.getRouteListByFileWaylineId(wayline.waylineId);
|
||||
if (res.resp_code === 0 && res.data && res.data.length > 0) {
|
||||
const routeId = res.data[0].routeId;
|
||||
const detailRes = await waylineRouteApi.getRouteDetail(routeId);
|
||||
if (detailRes.resp_code === 0) {
|
||||
setRouteDetail(detailRes.data);
|
||||
} else {
|
||||
message.error('获取航线详情失败');
|
||||
}
|
||||
} else {
|
||||
// 如果没有绑定的航线任务,提示用户
|
||||
message.info('该航迹文件尚未绑定设备,请先绑定设备');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载航线详情失败:', error);
|
||||
message.error('加载航线详情失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 航点表格列定义
|
||||
const waypointColumns = [
|
||||
{
|
||||
title: '序号',
|
||||
dataIndex: 'index',
|
||||
width: 60,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '经度',
|
||||
dataIndex: 'longitude',
|
||||
width: 120,
|
||||
render: (text: number) => text?.toFixed(6),
|
||||
},
|
||||
{
|
||||
title: '纬度',
|
||||
dataIndex: 'latitude',
|
||||
width: 120,
|
||||
render: (text: number) => text?.toFixed(6),
|
||||
},
|
||||
{
|
||||
title: '高度(m)',
|
||||
dataIndex: 'height',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '速度(m/s)',
|
||||
dataIndex: 'speed',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '航向角(°)',
|
||||
dataIndex: 'headingAngle',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '直线飞行',
|
||||
dataIndex: 'useStraightLine',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (value: boolean) => (
|
||||
<Tag color={value ? 'green' : 'blue'}>
|
||||
{value ? '是' : '否'}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// 动作表格列定义
|
||||
const actionColumns = [
|
||||
{
|
||||
title: '动作组',
|
||||
dataIndex: 'actionGroupId',
|
||||
width: 60,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '序号',
|
||||
dataIndex: 'actionIndex',
|
||||
width: 60,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '动作类型',
|
||||
dataIndex: 'actionType',
|
||||
width: 120,
|
||||
render: (text: string) => {
|
||||
const colors: Record<string, string> = {
|
||||
'fly': 'blue',
|
||||
'rotate': 'green',
|
||||
'gimbal': 'orange',
|
||||
'camera': 'purple',
|
||||
'hover': 'cyan',
|
||||
};
|
||||
return <Tag color={colors[text] || 'default'}>{text}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '触发类型',
|
||||
dataIndex: 'triggerType',
|
||||
width: 100,
|
||||
render: (text: string) => {
|
||||
const colors: Record<string, string> = {
|
||||
'trigger': 'red',
|
||||
'time': 'green',
|
||||
'distance': 'blue',
|
||||
};
|
||||
return <Tag color={colors[text] || 'default'}>{text}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '延迟时间(ms)',
|
||||
dataIndex: 'delayTime',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '悬停时间(s)',
|
||||
dataIndex: 'hoverTime',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '航向角(°)',
|
||||
dataIndex: 'aircraftHeading',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={`航迹详情 - ${wayline?.name}`}
|
||||
open={visible}
|
||||
onCancel={() => onVisibleChange(false)}
|
||||
footer={null}
|
||||
width={1000}
|
||||
style={{ top: 20 }}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
{routeDetail ? (
|
||||
<div>
|
||||
{/* 基本信息 */}
|
||||
<Card size="small" style={{ marginBottom: 16 }}>
|
||||
<Descriptions title="航线信息" size="small" column={3}>
|
||||
<Descriptions.Item label="航线名称">
|
||||
{routeDetail.routeInfo?.routeName}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="航点数量">
|
||||
<NumberOutlined style={{ marginRight: 4 }} />
|
||||
{routeDetail.totalWaypoints}个
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="动作数量">
|
||||
<ControlOutlined style={{ marginRight: 4 }} />
|
||||
{routeDetail.totalActions}个
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="总航程">
|
||||
<LineOutlined style={{ marginRight: 4 }} />
|
||||
{routeDetail.totalDistance?.toFixed(2)}米
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="预计时长">
|
||||
<ClockCircleOutlined style={{ marginRight: 4 }} />
|
||||
{routeDetail.totalDuration?.toFixed(2)}秒
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="解析状态">
|
||||
<Tag color={routeDetail.routeInfo?.parseStatus === 2 ? 'green' : 'orange'}>
|
||||
{routeDetail.routeInfo?.parseStatusDesc}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Card>
|
||||
|
||||
{/* 航点和动作详情 */}
|
||||
<Tabs activeKey={activeTab} onChange={setActiveTab}>
|
||||
<TabPane
|
||||
tab={
|
||||
<span>
|
||||
<EnvironmentOutlined />
|
||||
航点列表 ({routeDetail.waypoints?.length || 0})
|
||||
</span>
|
||||
}
|
||||
key="waypoints"
|
||||
>
|
||||
<Table
|
||||
columns={waypointColumns}
|
||||
dataSource={routeDetail.waypoints || []}
|
||||
rowKey="index"
|
||||
size="small"
|
||||
pagination={{
|
||||
pageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
scroll={{ x: 600 }}
|
||||
/>
|
||||
</TabPane>
|
||||
|
||||
<TabPane
|
||||
tab={
|
||||
<span>
|
||||
<ControlOutlined />
|
||||
动作列表 ({routeDetail.actions?.length || 0})
|
||||
</span>
|
||||
}
|
||||
key="actions"
|
||||
>
|
||||
<Table
|
||||
columns={actionColumns}
|
||||
dataSource={routeDetail.actions || []}
|
||||
rowKey={(record) => `${record.actionGroupId}-${record.actionIndex}`}
|
||||
size="small"
|
||||
pagination={{
|
||||
pageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
scroll={{ x: 700 }}
|
||||
expandable={{
|
||||
expandedRowRender: (record: WaypointActionVO) => {
|
||||
if (!record.actionParams || Object.keys(record.actionParams).length === 0) {
|
||||
return <div style={{ color: '#999' }}>无参数</div>;
|
||||
}
|
||||
return (
|
||||
<div style={{ margin: 0 }}>
|
||||
{Object.entries(record.actionParams).map(([key, value]) => (
|
||||
<Space key={key} style={{ marginBottom: 4 }}>
|
||||
<span style={{ color: '#666' }}>{key}:</span>
|
||||
<span>{String(value)}</span>
|
||||
</Space>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
rowExpandable: (record) => record.actionParams && Object.keys(record.actionParams).length > 0,
|
||||
}}
|
||||
/>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '50px 0', color: '#999' }}>
|
||||
暂无数据或该航迹文件尚未绑定设备
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default WaylineDetailModal;
|
||||
@@ -3,7 +3,7 @@ import type { ActionType } from '@ant-design/pro-components';
|
||||
import { ProTable } from '@ant-design/pro-components';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import { Space, message } from 'antd';
|
||||
import { DownloadOutlined } from '@ant-design/icons';
|
||||
import { DownloadOutlined, LinkOutlined, EyeOutlined } from '@ant-design/icons';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { downloadByUrl } from '@/utils/download';
|
||||
|
||||
@@ -15,9 +15,11 @@ interface WaylineTableProps {
|
||||
params?: Record<string, any>;
|
||||
onEdit?: (record: any) => void;
|
||||
onDelete?: (record: any) => void;
|
||||
onBindDevice?: (record: any) => void;
|
||||
onViewDetail?: (record: any) => void;
|
||||
}
|
||||
|
||||
const WaylineTable = forwardRef<WaylineTableRef, WaylineTableProps>(({ params, onEdit, onDelete }, ref) => {
|
||||
const WaylineTable = forwardRef<WaylineTableRef, WaylineTableProps>(({ params, onEdit, onDelete, onBindDevice, onViewDetail }, ref) => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
|
||||
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
|
||||
@@ -80,6 +82,12 @@ const WaylineTable = forwardRef<WaylineTableRef, WaylineTableProps>(({ params, o
|
||||
<a onClick={() => handleDownload(record)} title="下载航线文件">
|
||||
<DownloadOutlined /> 下载
|
||||
</a>
|
||||
<a onClick={() => onBindDevice?.(record)} title="绑定设备">
|
||||
<LinkOutlined /> 绑定设备
|
||||
</a>
|
||||
<a onClick={() => onViewDetail?.(record)} title="查看详情">
|
||||
<EyeOutlined /> 详情
|
||||
</a>
|
||||
<a style={{ color: '#1677ff' }} onClick={() => onDelete?.(record)}>删除</a>
|
||||
</Space>
|
||||
)
|
||||
|
||||
@@ -5,6 +5,8 @@ import { PlusOutlined } from '@ant-design/icons';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import WaylineTable, { WaylineTableRef } from './components/WaylineTable';
|
||||
import WaylineForm, { WaylineFormValues } from './components/WaylineForm';
|
||||
import BindDeviceModal from './components/BindDeviceModal';
|
||||
import WaylineDetailModal from './components/WaylineDetailModal';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
|
||||
const WaylinePage: React.FC = () => {
|
||||
@@ -13,6 +15,10 @@ const WaylinePage: React.FC = () => {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<any | null>(null);
|
||||
const [bindDeviceOpen, setBindDeviceOpen] = useState(false);
|
||||
const [selectedWayline, setSelectedWayline] = useState<any | null>(null);
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
const [detailWayline, setDetailWayline] = useState<any | null>(null);
|
||||
|
||||
const add = async (values: WaylineFormValues) => {
|
||||
const hide = message.loading('保存中...');
|
||||
@@ -60,6 +66,16 @@ const WaylinePage: React.FC = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleBindDevice = (record: any) => {
|
||||
setSelectedWayline(record);
|
||||
setBindDeviceOpen(true);
|
||||
};
|
||||
|
||||
const handleViewDetail = (record: any) => {
|
||||
setDetailWayline(record);
|
||||
setDetailOpen(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '航线管理' }}>
|
||||
<SearchBarPlus
|
||||
@@ -81,12 +97,29 @@ const WaylinePage: React.FC = () => {
|
||||
params={query}
|
||||
onEdit={(r) => { setCurrent(r); setEditOpen(true); }}
|
||||
onDelete={(r) => del(r)}
|
||||
onBindDevice={handleBindDevice}
|
||||
onViewDetail={handleViewDetail}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
<WaylineForm title="新增航线" visible={createOpen} onVisibleChange={setCreateOpen} onFinish={add} />
|
||||
|
||||
<WaylineForm title="编辑航线" visible={editOpen} onVisibleChange={setEditOpen} onFinish={edit} initialValues={current || {}} />
|
||||
|
||||
<BindDeviceModal
|
||||
visible={bindDeviceOpen}
|
||||
onVisibleChange={setBindDeviceOpen}
|
||||
wayline={selectedWayline}
|
||||
onSuccess={() => {
|
||||
tableRef.current?.reload();
|
||||
}}
|
||||
/>
|
||||
|
||||
<WaylineDetailModal
|
||||
visible={detailOpen}
|
||||
onVisibleChange={setDetailOpen}
|
||||
wayline={detailWayline}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
+18
-1
@@ -525,6 +525,23 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
}
|
||||
}, [handleMouseMove]);
|
||||
|
||||
// 关闭面板时,主动断开所有连接
|
||||
const handleClose = () => {
|
||||
// 1. 断开设备控制服务
|
||||
deviceControlWs.disconnect();
|
||||
// 2. 断开无人机SSE连接(会调用后端接口取消订阅)
|
||||
if (deviceSn) {
|
||||
disconnectDroneSSE(deviceSn);
|
||||
}
|
||||
// 3. 重置无人机数据
|
||||
resetDroneData();
|
||||
// 4. 退出DRC模式
|
||||
setDrcMode(false);
|
||||
drcModeRef.current = false;
|
||||
// 5. 调用父组件的关闭回调
|
||||
onClose();
|
||||
};
|
||||
|
||||
// 视频尺寸切换
|
||||
const handleVideoSizeToggle = () => {
|
||||
if (videoSize === 'normal') {
|
||||
@@ -665,7 +682,7 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
<span className={styles.voltage}>{flightData.vol}V</span>
|
||||
</div>
|
||||
</div>
|
||||
<button className={styles.closeBtn} onClick={onClose} onMouseDown={e => e.stopPropagation()}>
|
||||
<button className={styles.closeBtn} onClick={handleClose} onMouseDown={e => e.stopPropagation()}>
|
||||
<CloseOutlined />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
+75
-10
@@ -12,7 +12,7 @@
|
||||
top: 64px;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: 420px; // 稍微加宽一点
|
||||
width: 360px; // 减小宽度避免滚动条
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
rgba(6, 12, 20, 0.98) 0%,
|
||||
@@ -225,6 +225,50 @@
|
||||
border-left: 2px solid @cyan;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
.takeoffBtn {
|
||||
padding: 4px 10px;
|
||||
font-size: 11px;
|
||||
background: linear-gradient(135deg, rgba(255, 77, 79, 0.25), rgba(0, 255, 136, 0.25));
|
||||
border: 1px solid @neon-green;
|
||||
color: @neon-green;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
text-transform: none;
|
||||
letter-spacing: 0;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: linear-gradient(90deg, @neon-red, @neon-green);
|
||||
opacity: 0.15;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, rgba(255, 77, 79, 0.35), rgba(0, 255, 136, 0.35));
|
||||
box-shadow: 0 0 12px rgba(0, 255, 136, 0.4), 0 0 8px rgba(255, 77, 79, 0.3);
|
||||
border-color: @neon-green;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
filter: grayscale(0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.grid {
|
||||
@@ -256,30 +300,41 @@
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 12px;
|
||||
margin-top: 32px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-top: 24px;
|
||||
|
||||
.actionRow {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 12px;
|
||||
padding: 10px 12px;
|
||||
background: rgba(0, 240, 255, 0.1);
|
||||
border: 1px solid rgba(0, 240, 255, 0.3);
|
||||
color: @cyan;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
|
||||
gap: 6px;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background: rgba(0, 240, 255, 0.2);
|
||||
box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
|
||||
transform: translateY(-2px);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
|
||||
&:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(1); }
|
||||
|
||||
&.primary {
|
||||
@@ -289,6 +344,16 @@
|
||||
text-shadow: none;
|
||||
&:hover:not(:disabled) { background: rgba(0, 240, 255, 0.4); }
|
||||
}
|
||||
|
||||
&.task {
|
||||
background: rgba(255, 170, 0, 0.15);
|
||||
border-color: @neon-orange;
|
||||
color: @neon-orange;
|
||||
&:hover:not(:disabled) {
|
||||
background: rgba(255, 170, 0, 0.25);
|
||||
box-shadow: 0 0 15px rgba(255, 170, 0, 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
-13
@@ -10,6 +10,8 @@ import {
|
||||
DashboardOutlined,
|
||||
SignalFilled,
|
||||
LoadingOutlined,
|
||||
AimOutlined,
|
||||
UnorderedListOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
@@ -23,13 +25,19 @@ interface RightPanelProps {
|
||||
tourism: any;
|
||||
onClose: () => void;
|
||||
onControlClick: (device: any, realtimeData: any) => void;
|
||||
onTaskPanelOpen?: (device: any) => void; // 打开任务管理面板回调
|
||||
viewer?: any; // Cesium Viewer 实例
|
||||
Cesium?: any; // Cesium 库
|
||||
}
|
||||
|
||||
const RightPanel: React.FC<RightPanelProps> = ({
|
||||
visible,
|
||||
tourism,
|
||||
onClose,
|
||||
onControlClick
|
||||
onControlClick,
|
||||
onTaskPanelOpen,
|
||||
viewer,
|
||||
Cesium
|
||||
}) => {
|
||||
const [deviceList, setDeviceList] = useState<any[]>([]);
|
||||
const [selectedDeviceSn, setSelectedDeviceSn] = useState<string>('');
|
||||
@@ -81,6 +89,16 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
if (deviceSn !== selectedDeviceSn) setSelectedDeviceSn(deviceSn);
|
||||
};
|
||||
|
||||
// 关闭面板时,主动断开SSE连接
|
||||
const handleClose = () => {
|
||||
// 先断开SSE连接
|
||||
if (selectedDeviceSn) {
|
||||
disconnectSSE(selectedDeviceSn);
|
||||
}
|
||||
// 然后调用父组件的关闭回调
|
||||
onClose();
|
||||
};
|
||||
|
||||
const selectedDevice = deviceList.find((d) => d.deviceSn === selectedDeviceSn);
|
||||
const dockData = realtimeData?.rawData?.dockData;
|
||||
const battery = realtimeData?.battery ?? 0;
|
||||
@@ -192,7 +210,7 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
</div>
|
||||
<div className={styles.subTitle}>{deviceList.length} DEVICES ONLINE</div>
|
||||
</div>
|
||||
<button className={styles.closeBtn} onClick={onClose}><CloseOutlined /></button>
|
||||
<button className={styles.closeBtn} onClick={handleClose}><CloseOutlined /></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -235,8 +253,17 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
|
||||
{/* Block A: 机库信息 */}
|
||||
<div className={styles.section}>
|
||||
<div className={styles.sectionHeader}>机库信息 / DOCK INFO</div>
|
||||
|
||||
<div className={styles.sectionHeader}>
|
||||
<span>机库信息 / DOCK INFO</span>
|
||||
<button
|
||||
className={styles.takeoffBtn}
|
||||
disabled={takeoffLoading || dockData?.mode_code === 1 || dockData?.drone_in_dock === 0}
|
||||
onClick={handleTakeoff}
|
||||
>
|
||||
{takeoffLoading ? <LoadingOutlined /> : <RocketOutlined />} 一键起飞
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 状态卡片 */}
|
||||
<div className={styles.statusCard}>
|
||||
<div className={styles.statusHeader}>
|
||||
@@ -273,15 +300,14 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
|
||||
{/* 操作区 */}
|
||||
<div className={styles.actions}>
|
||||
<button className={styles.primary} onClick={() => onControlClick(selectedDevice, realtimeData)}>
|
||||
<VideoCameraOutlined /> 进入操控台
|
||||
</button>
|
||||
<button
|
||||
disabled={takeoffLoading || dockData?.mode_code === 1 || dockData?.drone_in_dock === 0}
|
||||
onClick={handleTakeoff}
|
||||
>
|
||||
{takeoffLoading ? <LoadingOutlined /> : <RocketOutlined />} 一键起飞
|
||||
</button>
|
||||
<div className={styles.actionRow}>
|
||||
<button className={styles.primary} onClick={() => onControlClick(selectedDevice, realtimeData)}>
|
||||
<VideoCameraOutlined /> 进入操控台
|
||||
</button>
|
||||
<button className={styles.task} onClick={() => onTaskPanelOpen?.(selectedDevice)}>
|
||||
<UnorderedListOutlined /> 任务管理
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabPane>
|
||||
@@ -337,6 +363,7 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
)}
|
||||
</Spin>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
+512
@@ -0,0 +1,512 @@
|
||||
@cyan: #00f0ff;
|
||||
@neon-green: #00ff88;
|
||||
@neon-orange: #ffaa00;
|
||||
@neon-red: #ff4d4f;
|
||||
|
||||
.taskPanel {
|
||||
position: absolute;
|
||||
bottom: 160px;
|
||||
left: 20px;
|
||||
width: 360px;
|
||||
max-height: 500px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
rgba(6, 12, 20, 0.96) 0%,
|
||||
rgba(10, 25, 40, 0.94) 100%
|
||||
);
|
||||
backdrop-filter: blur(12px);
|
||||
border: 1px solid rgba(0, 240, 255, 0.2);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 20px rgba(0, 240, 255, 0.1);
|
||||
color: #fff;
|
||||
z-index: 1001;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
&.visible {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px 14px;
|
||||
background: rgba(0, 20, 40, 0.5);
|
||||
border-bottom: 1px solid rgba(0, 240, 255, 0.15);
|
||||
border-radius: 8px 8px 0 0;
|
||||
cursor: move;
|
||||
user-select: none;
|
||||
flex-shrink: 0;
|
||||
|
||||
.title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: @cyan;
|
||||
|
||||
.deviceTag {
|
||||
font-size: 10px;
|
||||
font-weight: normal;
|
||||
background: rgba(0, 240, 255, 0.15);
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
}
|
||||
|
||||
.headerActions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.iconBtn, .closeBtn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
padding: 5px;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: @cyan;
|
||||
}
|
||||
}
|
||||
|
||||
.closeBtn:hover {
|
||||
background: rgba(255, 77, 79, 0.2);
|
||||
color: @neon-red;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
|
||||
:global {
|
||||
.ant-tabs-nav {
|
||||
margin: 0;
|
||||
padding: 0 12px;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
|
||||
.ant-tabs-tab {
|
||||
padding: 8px 12px;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 13px;
|
||||
|
||||
&:hover {
|
||||
color: @cyan;
|
||||
}
|
||||
|
||||
&.ant-tabs-tab-active .ant-tabs-tab-btn {
|
||||
color: @cyan;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-tabs-ink-bar {
|
||||
background: @cyan;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-tabs-content-holder {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ant-tabs-content {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.ant-tabs-tabpane {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tabContent {
|
||||
padding: 12px;
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 240, 255, 0.2);
|
||||
border-radius: 2px;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 240, 255, 0.3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 14px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.sectionTitle {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
padding-left: 8px;
|
||||
border-left: 2px solid @cyan;
|
||||
}
|
||||
|
||||
.infoGrid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 10px;
|
||||
|
||||
.infoItem {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
|
||||
.label {
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 13px;
|
||||
color: @cyan;
|
||||
font-family: 'Consolas', monospace;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.createBtn {
|
||||
background: linear-gradient(135deg, rgba(0, 240, 255, 0.2), rgba(0, 100, 255, 0.2)) !important;
|
||||
border: 1px solid rgba(0, 240, 255, 0.4) !important;
|
||||
color: @cyan !important;
|
||||
font-weight: 600;
|
||||
height: 36px;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, rgba(0, 240, 255, 0.3), rgba(0, 100, 255, 0.3)) !important;
|
||||
border-color: @cyan !important;
|
||||
box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
.taskList {
|
||||
max-height: 180px;
|
||||
overflow-y: auto;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 6px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 3px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 240, 255, 0.2);
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.taskItem {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 240, 255, 0.05);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
background: rgba(0, 240, 255, 0.1);
|
||||
border-left: 3px solid @cyan;
|
||||
}
|
||||
|
||||
.taskInfo {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.taskName {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: #fff;
|
||||
margin-bottom: 3px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.taskMeta {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
|
||||
.status {
|
||||
padding: 1px 5px;
|
||||
border-radius: 3px;
|
||||
|
||||
&.status0 {
|
||||
background: rgba(255, 170, 0, 0.2);
|
||||
color: @neon-orange;
|
||||
}
|
||||
&.status1 {
|
||||
background: rgba(0, 240, 255, 0.2);
|
||||
color: @cyan;
|
||||
}
|
||||
&.status2 {
|
||||
background: rgba(0, 255, 136, 0.2);
|
||||
color: @neon-green;
|
||||
}
|
||||
&.status3 {
|
||||
background: rgba(255, 77, 79, 0.2);
|
||||
color: @neon-red;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.taskActions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.actionBtn {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 240, 255, 0.1);
|
||||
border-color: rgba(0, 240, 255, 0.3);
|
||||
color: @cyan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.loading {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.emptyState {
|
||||
padding: 20px 0;
|
||||
|
||||
:global {
|
||||
.ant-empty-description {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.ant-empty-image svg {
|
||||
fill: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.legend {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
padding: 8px 10px;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 6px;
|
||||
|
||||
.legendItem {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
|
||||
.legendLine {
|
||||
width: 20px;
|
||||
height: 3px;
|
||||
border-radius: 2px;
|
||||
|
||||
&.blue {
|
||||
background: #1890ff;
|
||||
box-shadow: 0 0 4px rgba(24, 144, 255, 0.5);
|
||||
}
|
||||
|
||||
&.green {
|
||||
background: #52c41a;
|
||||
box-shadow: 0 0 4px rgba(82, 196, 26, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
.legendPoint {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: @neon-red;
|
||||
box-shadow: 0 0 4px rgba(255, 77, 79, 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.realtimeInfo {
|
||||
padding: 10px 12px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border-top: 1px solid rgba(0, 240, 255, 0.1);
|
||||
flex-shrink: 0;
|
||||
|
||||
.realtimeTitle {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
margin-bottom: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
|
||||
.locateBtn {
|
||||
margin-left: auto;
|
||||
background: rgba(0, 240, 255, 0.15);
|
||||
border: 1px solid rgba(0, 240, 255, 0.3);
|
||||
color: @cyan;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 240, 255, 0.3);
|
||||
border-color: @cyan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.coordsGrid {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
font-size: 11px;
|
||||
color: @cyan;
|
||||
font-family: 'Consolas', monospace;
|
||||
}
|
||||
}
|
||||
|
||||
// Select 组件样式覆盖
|
||||
:global {
|
||||
.ant-select {
|
||||
.ant-select-selector {
|
||||
background: rgba(0, 0, 0, 0.3) !important;
|
||||
border-color: rgba(0, 240, 255, 0.2) !important;
|
||||
color: #fff !important;
|
||||
height: 34px !important;
|
||||
|
||||
.ant-select-selection-placeholder {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.ant-select-selection-item {
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover .ant-select-selector {
|
||||
border-color: @cyan !important;
|
||||
}
|
||||
|
||||
&.ant-select-focused .ant-select-selector {
|
||||
border-color: @cyan !important;
|
||||
box-shadow: 0 0 8px rgba(0, 240, 255, 0.2) !important;
|
||||
}
|
||||
|
||||
.ant-select-arrow {
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.ant-select-clear {
|
||||
background: transparent;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
|
||||
&:hover {
|
||||
color: @neon-red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-select-dropdown {
|
||||
background: rgba(10, 20, 40, 0.98) !important;
|
||||
border: 1px solid rgba(0, 240, 255, 0.2);
|
||||
|
||||
.ant-select-item {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 240, 255, 0.1);
|
||||
}
|
||||
|
||||
&.ant-select-item-option-selected {
|
||||
background: rgba(0, 240, 255, 0.2);
|
||||
color: @cyan;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+777
@@ -0,0 +1,777 @@
|
||||
import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react';
|
||||
import { Button, message, Tooltip, Empty, Image, Select, Tabs } from 'antd';
|
||||
import {
|
||||
CloseOutlined,
|
||||
PlusOutlined,
|
||||
EyeOutlined,
|
||||
EnvironmentOutlined,
|
||||
PictureOutlined,
|
||||
ReloadOutlined,
|
||||
FileTextOutlined,
|
||||
SendOutlined,
|
||||
UnorderedListOutlined,
|
||||
AimOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { useDroneSSE } from '../hooks/useDroneSSE';
|
||||
import { waylineRouteApi, WaylineRouteListItemVO, WaypointVO } from '@/services/waylineRoute';
|
||||
import styles from './TaskPanel.less';
|
||||
|
||||
const { TabPane } = Tabs;
|
||||
|
||||
interface TaskPanelProps {
|
||||
visible: boolean;
|
||||
onClose: () => void;
|
||||
device: any;
|
||||
viewer?: any;
|
||||
Cesium?: any;
|
||||
}
|
||||
|
||||
// 任务数据结构(后端未实现,先定义好接口)
|
||||
interface TaskItem {
|
||||
taskId: string;
|
||||
taskName: string;
|
||||
routeId: string;
|
||||
routeName: string;
|
||||
deviceSn: string;
|
||||
status: number; // 0-待执行 1-执行中 2-已完成 3-失败
|
||||
statusDesc: string;
|
||||
createTime: string;
|
||||
images?: string[];
|
||||
}
|
||||
|
||||
const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
visible,
|
||||
onClose,
|
||||
device,
|
||||
viewer,
|
||||
Cesium,
|
||||
}) => {
|
||||
const deviceSn = device?.deviceSn;
|
||||
|
||||
// SSE hook
|
||||
const { droneData, connectDroneSSE, disconnectDroneSSE, resetDroneData } = useDroneSSE();
|
||||
|
||||
// 航线相关状态
|
||||
const [routeList, setRouteList] = useState<WaylineRouteListItemVO[]>([]);
|
||||
const [selectedRouteId, setSelectedRouteId] = useState<string | null>(null);
|
||||
const [waypoints, setWaypoints] = useState<WaypointVO[]>([]);
|
||||
const [routeLoading, setRouteLoading] = useState(false);
|
||||
|
||||
// 任务相关状态
|
||||
const [taskList, setTaskList] = useState<TaskItem[]>([]);
|
||||
const [selectedTaskId, setSelectedTaskId] = useState<string | null>(null);
|
||||
const [taskLoading, setTaskLoading] = useState(false);
|
||||
const [imagePreviewVisible, setImagePreviewVisible] = useState(false);
|
||||
const [previewImages, setPreviewImages] = useState<string[]>([]);
|
||||
|
||||
// Tab 状态
|
||||
const [activeTab, setActiveTab] = useState<string>('route');
|
||||
|
||||
// 拖拽状态
|
||||
const [position, setPosition] = useState({ x: 0, y: 0 });
|
||||
const draggingRef = useRef(false);
|
||||
const lastPosRef = useRef({ x: 0, y: 0 });
|
||||
const rafRef = useRef<number | null>(null);
|
||||
const pendingPosRef = useRef({ x: 0, y: 0 });
|
||||
|
||||
// 地图图层引用
|
||||
const waylineEntityRef = useRef<any>(null);
|
||||
const waypointEntitiesRef = useRef<any[]>([]);
|
||||
const droneEntityRef = useRef<any>(null);
|
||||
const flightTrackEntityRef = useRef<any>(null);
|
||||
const trackPositionsRef = useRef<any[]>([]);
|
||||
const hasFlownToDroneRef = useRef<boolean>(false); // 是否已经飞到过无人机位置
|
||||
const lastUpdateTimeRef = useRef<number>(0); // 上次更新时间
|
||||
const lastPositionRef = useRef<{ lon: number; lat: number; height: number } | null>(null); // 上次位置
|
||||
|
||||
// 实时位置 - 区分相对高度和海拔高度
|
||||
const realtimePosition = useMemo(() => {
|
||||
if (!droneData) return null;
|
||||
return {
|
||||
longitude: droneData.longitude,
|
||||
latitude: droneData.latitude,
|
||||
height: droneData.height, // 相对高度(相对于起飞点)
|
||||
elevation: droneData.elevation, // 海拔高度
|
||||
// 3D地图显示用的高度:直接使用相对高度 height
|
||||
altitude: droneData.height,
|
||||
heading: droneData.attitude_head,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}, [droneData]);
|
||||
|
||||
// 初始化
|
||||
useEffect(() => {
|
||||
if (visible && deviceSn) {
|
||||
connectDroneSSE(deviceSn);
|
||||
loadRoutesByDevice(deviceSn);
|
||||
loadTasksByDevice(deviceSn);
|
||||
return () => {
|
||||
disconnectDroneSSE(deviceSn);
|
||||
resetDroneData();
|
||||
clearMapLayers();
|
||||
};
|
||||
} else {
|
||||
setPosition({ x: 0, y: 0 });
|
||||
trackPositionsRef.current = [];
|
||||
hasFlownToDroneRef.current = false;
|
||||
setSelectedRouteId(null);
|
||||
setSelectedTaskId(null);
|
||||
}
|
||||
}, [visible, deviceSn]);
|
||||
|
||||
// 调试:监测 props 变化
|
||||
useEffect(() => {
|
||||
console.log('[TaskPanel] props变化:', {
|
||||
visible,
|
||||
hasViewer: !!viewer,
|
||||
hasCesium: !!Cesium,
|
||||
deviceSn,
|
||||
});
|
||||
}, [visible, viewer, Cesium, deviceSn]);
|
||||
|
||||
// 实时位置更新 - 绘制无人机和航迹(节流:1秒更新一次,或位置变化时更新)
|
||||
useEffect(() => {
|
||||
if (!visible || !viewer || !Cesium || !realtimePosition) return;
|
||||
if (viewer.isDestroyed?.()) return;
|
||||
if (!realtimePosition.longitude || !realtimePosition.latitude) return;
|
||||
|
||||
const now = Date.now();
|
||||
const currentPos = {
|
||||
lon: realtimePosition.longitude,
|
||||
lat: realtimePosition.latitude,
|
||||
height: realtimePosition.height ?? 0,
|
||||
};
|
||||
|
||||
// 检查是否需要更新:1秒内且位置没变化则跳过
|
||||
const timeSinceLastUpdate = now - lastUpdateTimeRef.current;
|
||||
const lastPos = lastPositionRef.current;
|
||||
|
||||
if (lastPos && timeSinceLastUpdate < 1000) {
|
||||
// 检查位置是否有明显变化(经纬度变化超过0.00001度,约1米;高度变化超过0.5米)
|
||||
const posChanged =
|
||||
Math.abs(currentPos.lon - lastPos.lon) > 0.00001 ||
|
||||
Math.abs(currentPos.lat - lastPos.lat) > 0.00001 ||
|
||||
Math.abs(currentPos.height - lastPos.height) > 0.5;
|
||||
|
||||
if (!posChanged) {
|
||||
return; // 位置没变化且不到1秒,跳过更新
|
||||
}
|
||||
}
|
||||
|
||||
// 更新时间和位置记录
|
||||
lastUpdateTimeRef.current = now;
|
||||
lastPositionRef.current = currentPos;
|
||||
|
||||
const displayHeight = realtimePosition.height ?? 50;
|
||||
|
||||
try {
|
||||
const pos = Cesium.Cartesian3.fromDegrees(
|
||||
realtimePosition.longitude,
|
||||
realtimePosition.latitude,
|
||||
displayHeight
|
||||
);
|
||||
|
||||
const labelText = `无人机 H:${realtimePosition.height != null ? realtimePosition.height.toFixed(0) : '--'}m`;
|
||||
|
||||
// 更新或创建无人机entity
|
||||
if (droneEntityRef.current) {
|
||||
droneEntityRef.current.position = pos;
|
||||
if (droneEntityRef.current.label) {
|
||||
droneEntityRef.current.label.text = labelText;
|
||||
}
|
||||
} else {
|
||||
droneEntityRef.current = viewer.entities.add({
|
||||
name: '无人机实时位置',
|
||||
position: pos,
|
||||
point: {
|
||||
pixelSize: 16,
|
||||
color: Cesium.Color.RED,
|
||||
outlineColor: Cesium.Color.WHITE,
|
||||
outlineWidth: 3,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
label: {
|
||||
text: labelText,
|
||||
font: '14px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||
outlineWidth: 2,
|
||||
outlineColor: Cesium.Color.BLACK,
|
||||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||
pixelOffset: new Cesium.Cartesian2(0, -20),
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
});
|
||||
console.log('[TaskPanel] 创建无人机entity');
|
||||
}
|
||||
|
||||
// 添加航迹点(只有位置变化才添加)
|
||||
trackPositionsRef.current.push(pos);
|
||||
|
||||
// 绘制飞行轨迹
|
||||
if (trackPositionsRef.current.length >= 2) {
|
||||
if (flightTrackEntityRef.current) {
|
||||
flightTrackEntityRef.current.polyline.positions = [...trackPositionsRef.current];
|
||||
} else {
|
||||
flightTrackEntityRef.current = viewer.entities.add({
|
||||
name: '飞行轨迹',
|
||||
polyline: {
|
||||
positions: [...trackPositionsRef.current],
|
||||
width: 4,
|
||||
material: new Cesium.PolylineGlowMaterialProperty({
|
||||
glowPower: 0.3,
|
||||
color: Cesium.Color.LIME,
|
||||
}),
|
||||
clampToGround: false,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
});
|
||||
console.log('[TaskPanel] 创建飞行轨迹entity');
|
||||
}
|
||||
}
|
||||
|
||||
// 强制渲染
|
||||
viewer.scene.requestRender();
|
||||
|
||||
// 首次收到位置数据时,自动飞到无人机位置
|
||||
if (!hasFlownToDroneRef.current && trackPositionsRef.current.length === 1) {
|
||||
hasFlownToDroneRef.current = true;
|
||||
flyToDrone();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[TaskPanel] 更新无人机位置出错:', error);
|
||||
}
|
||||
}, [realtimePosition, visible, viewer, Cesium]);
|
||||
|
||||
// 飞到无人机位置
|
||||
const flyToDrone = useCallback(() => {
|
||||
if (!viewer || !Cesium || !realtimePosition) {
|
||||
message.warning('暂无无人机位置数据');
|
||||
return;
|
||||
}
|
||||
if (!realtimePosition.longitude || !realtimePosition.latitude) {
|
||||
message.warning('无人机位置数据无效');
|
||||
return;
|
||||
}
|
||||
|
||||
const droneHeight = realtimePosition.height ?? 50;
|
||||
|
||||
viewer.camera.flyTo({
|
||||
destination: Cesium.Cartesian3.fromDegrees(
|
||||
realtimePosition.longitude,
|
||||
realtimePosition.latitude,
|
||||
droneHeight + 100 // 视角高度比无人机高100米
|
||||
),
|
||||
orientation: {
|
||||
heading: 0,
|
||||
pitch: Cesium.Math.toRadians(-90), // 垂直俯视
|
||||
roll: 0,
|
||||
},
|
||||
duration: 1.5,
|
||||
});
|
||||
message.success('已飞到无人机位置');
|
||||
}, [viewer, Cesium, realtimePosition]);
|
||||
|
||||
// 加载航线列表
|
||||
const loadRoutesByDevice = useCallback(async (sn: string) => {
|
||||
try {
|
||||
setRouteLoading(true);
|
||||
const res = await waylineRouteApi.getRouteListByDevice(sn);
|
||||
if (res.resp_code === 0) {
|
||||
setRouteList(res.data || []);
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('加载航线列表失败');
|
||||
} finally {
|
||||
setRouteLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 加载任务列表(后端未实现,使用模拟数据)
|
||||
const loadTasksByDevice = useCallback(async (sn: string) => {
|
||||
try {
|
||||
setTaskLoading(true);
|
||||
// TODO: 调用后端接口 - waylineRouteApi.getTaskListByDevice(sn)
|
||||
// 模拟数据
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
setTaskList([
|
||||
// 暂无任务,等后端实现
|
||||
]);
|
||||
} catch (e) {
|
||||
message.error('加载任务列表失败');
|
||||
} finally {
|
||||
setTaskLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 加载航点并绘制
|
||||
const loadWaypoints = useCallback(async (routeId: string) => {
|
||||
try {
|
||||
const res = await waylineRouteApi.getRouteWaypoints(routeId);
|
||||
if (res.resp_code === 0 && res.data?.length) {
|
||||
setWaypoints(res.data);
|
||||
if (viewer && Cesium) {
|
||||
drawWaylineOnMap(res.data);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('加载航点失败');
|
||||
}
|
||||
}, [viewer, Cesium]);
|
||||
|
||||
// 绘制航线
|
||||
const drawWaylineOnMap = useCallback((waypoints: WaypointVO[]) => {
|
||||
if (!viewer || !Cesium || !waypoints.length) return;
|
||||
|
||||
clearWaylineEntities();
|
||||
|
||||
const positions = waypoints.map(wp =>
|
||||
Cesium.Cartesian3.fromDegrees(wp.longitude, wp.latitude, wp.height || 100)
|
||||
);
|
||||
|
||||
// 计划航线(蓝色)
|
||||
waylineEntityRef.current = viewer.entities.add({
|
||||
name: '计划航线',
|
||||
polyline: {
|
||||
positions: positions,
|
||||
width: 3,
|
||||
material: new Cesium.PolylineGlowMaterialProperty({
|
||||
glowPower: 0.2,
|
||||
color: Cesium.Color.fromCssColorString('#1890ff'),
|
||||
}),
|
||||
clampToGround: false,
|
||||
},
|
||||
});
|
||||
|
||||
// 航点标记 - 只标注关键航点(首尾和间隔点)避免重叠
|
||||
const totalPoints = waypoints.length;
|
||||
// 根据航点数量决定标注间隔:超过20个点时每5个标一个,超过50个每10个标一个
|
||||
const labelInterval = totalPoints > 50 ? 10 : totalPoints > 20 ? 5 : totalPoints > 10 ? 3 : 1;
|
||||
|
||||
waypoints.forEach((wp, index) => {
|
||||
const isFirst = index === 0;
|
||||
const isLast = index === totalPoints - 1;
|
||||
const isKeyPoint = isFirst || isLast || (index % labelInterval === 0);
|
||||
|
||||
// 航点统一用蓝色系,起点用深蓝,终点用紫色,中间用浅蓝
|
||||
// 避免与无人机(红色)和飞行轨迹(绿色)混淆
|
||||
const pointColor = isFirst ? '#0050b3' : isLast ? '#722ed1' : '#1890ff';
|
||||
|
||||
const entity = viewer.entities.add({
|
||||
name: `航点${index + 1}`,
|
||||
position: Cesium.Cartesian3.fromDegrees(wp.longitude, wp.latitude, wp.height || 100),
|
||||
point: {
|
||||
pixelSize: isKeyPoint ? 8 : 5, // 关键点稍大,普通点更小
|
||||
color: Cesium.Color.fromCssColorString(pointColor),
|
||||
outlineColor: Cesium.Color.WHITE,
|
||||
outlineWidth: isKeyPoint ? 2 : 1,
|
||||
},
|
||||
label: isKeyPoint ? {
|
||||
text: isFirst ? '起' : isLast ? '终' : `${index + 1}`,
|
||||
font: '10px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||
outlineWidth: 2,
|
||||
outlineColor: Cesium.Color.BLACK,
|
||||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||
pixelOffset: new Cesium.Cartesian2(0, -10),
|
||||
scaleByDistance: new Cesium.NearFarScalar(100, 1.0, 5000, 0.5), // 远处缩小
|
||||
} : undefined, // 非关键点不显示标签
|
||||
});
|
||||
waypointEntitiesRef.current.push(entity);
|
||||
});
|
||||
|
||||
// 飞到航线
|
||||
flyToWayline(waypoints);
|
||||
}, [viewer, Cesium]);
|
||||
|
||||
// 飞到航线位置 - 垂直俯视整条航线
|
||||
const flyToWayline = useCallback((waypoints: WaypointVO[]) => {
|
||||
if (!viewer || !Cesium || !waypoints.length) return;
|
||||
|
||||
let minLon = Infinity, maxLon = -Infinity;
|
||||
let minLat = Infinity, maxLat = -Infinity;
|
||||
let maxHeight = 0;
|
||||
|
||||
waypoints.forEach(wp => {
|
||||
minLon = Math.min(minLon, wp.longitude);
|
||||
maxLon = Math.max(maxLon, wp.longitude);
|
||||
minLat = Math.min(minLat, wp.latitude);
|
||||
maxLat = Math.max(maxLat, wp.latitude);
|
||||
maxHeight = Math.max(maxHeight, wp.height || 100);
|
||||
});
|
||||
|
||||
const centerLon = (minLon + maxLon) / 2;
|
||||
const centerLat = (minLat + maxLat) / 2;
|
||||
|
||||
// 计算航线范围的对角线距离(经纬度转换为大约的米数)
|
||||
const lonSpan = maxLon - minLon;
|
||||
const latSpan = maxLat - minLat;
|
||||
// 1度经度约111km(在赤道),纬度方向约111km
|
||||
const spanMeters = Math.sqrt(
|
||||
Math.pow(lonSpan * 111000 * Math.cos(centerLat * Math.PI / 180), 2) +
|
||||
Math.pow(latSpan * 111000, 2)
|
||||
);
|
||||
|
||||
// 视角高度:航线范围的0.2倍 + 最高航点高度
|
||||
// 更贴近航线
|
||||
const viewHeight = Math.max(spanMeters * 0.2, 30) + maxHeight;
|
||||
|
||||
viewer.camera.flyTo({
|
||||
destination: Cesium.Cartesian3.fromDegrees(centerLon, centerLat, viewHeight),
|
||||
orientation: {
|
||||
heading: 0,
|
||||
pitch: Cesium.Math.toRadians(-90), // 垂直俯视,确保航迹在正下方
|
||||
roll: 0,
|
||||
},
|
||||
duration: 1.5,
|
||||
});
|
||||
}, [viewer, Cesium]);
|
||||
|
||||
// 检查 viewer 是否有效
|
||||
const isViewerValid = useCallback(() => {
|
||||
return viewer && !viewer.isDestroyed?.();
|
||||
}, [viewer]);
|
||||
|
||||
// 清除航线图层
|
||||
const clearWaylineEntities = useCallback(() => {
|
||||
if (!isViewerValid()) return;
|
||||
|
||||
if (waylineEntityRef.current) {
|
||||
try {
|
||||
viewer.entities.remove(waylineEntityRef.current);
|
||||
} catch (e) {}
|
||||
waylineEntityRef.current = null;
|
||||
}
|
||||
|
||||
waypointEntitiesRef.current.forEach(entity => {
|
||||
try {
|
||||
viewer.entities.remove(entity);
|
||||
} catch (e) {}
|
||||
});
|
||||
waypointEntitiesRef.current = [];
|
||||
}, [viewer, isViewerValid]);
|
||||
|
||||
// 清除所有图层
|
||||
const clearMapLayers = useCallback(() => {
|
||||
if (!isViewerValid()) return;
|
||||
|
||||
clearWaylineEntities();
|
||||
|
||||
if (droneEntityRef.current) {
|
||||
try {
|
||||
viewer.entities.remove(droneEntityRef.current);
|
||||
} catch (e) {}
|
||||
droneEntityRef.current = null;
|
||||
}
|
||||
|
||||
if (flightTrackEntityRef.current) {
|
||||
try {
|
||||
viewer.entities.remove(flightTrackEntityRef.current);
|
||||
} catch (e) {}
|
||||
flightTrackEntityRef.current = null;
|
||||
}
|
||||
|
||||
trackPositionsRef.current = [];
|
||||
}, [viewer, isViewerValid, clearWaylineEntities]);
|
||||
|
||||
// 选择航线
|
||||
const handleSelectRoute = useCallback((routeId: string) => {
|
||||
setSelectedRouteId(routeId);
|
||||
loadWaypoints(routeId);
|
||||
}, [loadWaypoints]);
|
||||
|
||||
// 创建任务
|
||||
const handleCreateTask = useCallback(async () => {
|
||||
if (!selectedRouteId) {
|
||||
message.warning('请先选择一条航线');
|
||||
return;
|
||||
}
|
||||
const selectedRoute = routeList.find(r => r.routeId === selectedRouteId);
|
||||
if (!selectedRoute) return;
|
||||
|
||||
// TODO: 调用后端接口创建任务
|
||||
// await waylineRouteApi.createTask({
|
||||
// routeId: selectedRouteId,
|
||||
// routeName: selectedRoute.routeName,
|
||||
// deviceSn: deviceSn,
|
||||
// });
|
||||
|
||||
message.info('创建任务功能待后端实现');
|
||||
}, [selectedRouteId, routeList, deviceSn]);
|
||||
|
||||
// 查看任务图片
|
||||
const handleViewTaskImages = useCallback(async (task: TaskItem) => {
|
||||
// TODO: 调用后端接口获取任务图片
|
||||
// const res = await waylineRouteApi.getTaskImages(task.taskId);
|
||||
// setPreviewImages(res.data || []);
|
||||
|
||||
// 模拟数据
|
||||
setPreviewImages([
|
||||
'https://via.placeholder.com/800x600?text=Task+Image+1',
|
||||
'https://via.placeholder.com/800x600?text=Task+Image+2',
|
||||
]);
|
||||
setImagePreviewVisible(true);
|
||||
}, []);
|
||||
|
||||
// 刷新
|
||||
const handleRefresh = useCallback(() => {
|
||||
if (deviceSn) {
|
||||
loadRoutesByDevice(deviceSn);
|
||||
loadTasksByDevice(deviceSn);
|
||||
message.success('刷新成功');
|
||||
}
|
||||
}, [deviceSn, loadRoutesByDevice, loadTasksByDevice]);
|
||||
|
||||
// 关闭面板时,主动断开SSE连接
|
||||
const handleClose = useCallback(() => {
|
||||
// 1. 断开无人机SSE连接(会调用后端接口取消订阅)
|
||||
if (deviceSn) {
|
||||
disconnectDroneSSE(deviceSn);
|
||||
}
|
||||
// 2. 重置无人机数据
|
||||
resetDroneData();
|
||||
// 3. 清除地图图层
|
||||
clearMapLayers();
|
||||
// 4. 调用父组件的关闭回调
|
||||
onClose();
|
||||
}, [deviceSn, disconnectDroneSSE, resetDroneData, clearMapLayers, onClose]);
|
||||
|
||||
// 拖拽
|
||||
const handleMouseDown = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
draggingRef.current = true;
|
||||
lastPosRef.current = { x: e.clientX, y: e.clientY };
|
||||
pendingPosRef.current = { ...position };
|
||||
document.body.style.userSelect = 'none';
|
||||
document.body.style.cursor = 'grabbing';
|
||||
document.addEventListener('mousemove', handleMouseMove);
|
||||
document.addEventListener('mouseup', handleMouseUp);
|
||||
};
|
||||
|
||||
const handleMouseMove = useCallback((e: MouseEvent) => {
|
||||
if (!draggingRef.current) return;
|
||||
const dx = e.clientX - lastPosRef.current.x;
|
||||
const dy = e.clientY - lastPosRef.current.y;
|
||||
lastPosRef.current = { x: e.clientX, y: e.clientY };
|
||||
pendingPosRef.current = {
|
||||
x: pendingPosRef.current.x + dx,
|
||||
y: pendingPosRef.current.y + dy
|
||||
};
|
||||
if (rafRef.current) cancelAnimationFrame(rafRef.current);
|
||||
rafRef.current = requestAnimationFrame(() => {
|
||||
setPosition({ ...pendingPosRef.current });
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleMouseUp = useCallback(() => {
|
||||
draggingRef.current = false;
|
||||
document.body.style.userSelect = '';
|
||||
document.body.style.cursor = '';
|
||||
document.removeEventListener('mousemove', handleMouseMove);
|
||||
document.removeEventListener('mouseup', handleMouseUp);
|
||||
}, [handleMouseMove]);
|
||||
|
||||
const selectedRoute = routeList.find(r => r.routeId === selectedRouteId);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${styles.taskPanel} ${visible ? styles.visible : ''}`}
|
||||
style={{ transform: visible ? `translate(${position.x}px, ${position.y}px)` : undefined }}
|
||||
>
|
||||
{/* 标题栏 */}
|
||||
<div className={styles.header} onMouseDown={handleMouseDown}>
|
||||
<div className={styles.title}>
|
||||
<FileTextOutlined />
|
||||
<span>任务管理</span>
|
||||
{deviceSn && <span className={styles.deviceTag}>{deviceSn}</span>}
|
||||
</div>
|
||||
<div className={styles.headerActions}>
|
||||
<Tooltip title="刷新">
|
||||
<button className={styles.iconBtn} onClick={handleRefresh}>
|
||||
<ReloadOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
<button className={styles.closeBtn} onClick={handleClose}>
|
||||
<CloseOutlined />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 内容区 */}
|
||||
<div className={styles.content}>
|
||||
<Tabs activeKey={activeTab} onChange={setActiveTab} className={styles.tabs}>
|
||||
{/* 航线 Tab */}
|
||||
<TabPane tab={<span><EnvironmentOutlined /> 航线</span>} key="route">
|
||||
<div className={styles.tabContent}>
|
||||
{/* 航线选择 */}
|
||||
<div className={styles.section}>
|
||||
<div className={styles.sectionTitle}>选择航线</div>
|
||||
<Select
|
||||
placeholder="请选择航线"
|
||||
style={{ width: '100%' }}
|
||||
value={selectedRouteId}
|
||||
onChange={handleSelectRoute}
|
||||
loading={routeLoading}
|
||||
allowClear
|
||||
onClear={() => {
|
||||
setSelectedRouteId(null);
|
||||
clearWaylineEntities();
|
||||
}}
|
||||
>
|
||||
{routeList.map(route => (
|
||||
<Select.Option key={route.routeId} value={route.routeId}>
|
||||
{route.routeName} ({route.waypointCount}个航点)
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 航线详情 */}
|
||||
{selectedRoute && (
|
||||
<div className={styles.section}>
|
||||
<div className={styles.sectionTitle}>航线详情</div>
|
||||
<div className={styles.infoGrid}>
|
||||
<div className={styles.infoItem}>
|
||||
<span className={styles.label}>航点数</span>
|
||||
<span className={styles.value}>{selectedRoute.waypointCount}</span>
|
||||
</div>
|
||||
<div className={styles.infoItem}>
|
||||
<span className={styles.label}>总距离</span>
|
||||
<span className={styles.value}>{(selectedRoute.totalDistance / 1000).toFixed(2)} km</span>
|
||||
</div>
|
||||
<div className={styles.infoItem}>
|
||||
<span className={styles.label}>预计时长</span>
|
||||
<span className={styles.value}>{Math.ceil(selectedRoute.totalDuration / 60)} 分钟</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 创建任务按钮 */}
|
||||
<div className={styles.section}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
block
|
||||
onClick={handleCreateTask}
|
||||
disabled={!selectedRouteId}
|
||||
className={styles.createBtn}
|
||||
>
|
||||
基于此航线创建任务
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 图例 */}
|
||||
<div className={styles.section}>
|
||||
<div className={styles.sectionTitle}>图例</div>
|
||||
<div className={styles.legend}>
|
||||
<div className={styles.legendItem}>
|
||||
<span className={`${styles.legendLine} ${styles.blue}`}></span>
|
||||
<span>计划航线</span>
|
||||
</div>
|
||||
<div className={styles.legendItem}>
|
||||
<span className={`${styles.legendLine} ${styles.green}`}></span>
|
||||
<span>飞行轨迹</span>
|
||||
</div>
|
||||
<div className={styles.legendItem}>
|
||||
<span className={styles.legendPoint}></span>
|
||||
<span>无人机</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabPane>
|
||||
|
||||
{/* 任务 Tab */}
|
||||
<TabPane tab={<span><UnorderedListOutlined /> 任务</span>} key="task">
|
||||
<div className={styles.tabContent}>
|
||||
{/* 任务列表 */}
|
||||
<div className={styles.section}>
|
||||
<div className={styles.sectionTitle}>任务列表</div>
|
||||
<div className={styles.taskList}>
|
||||
{taskLoading ? (
|
||||
<div className={styles.loading}>加载中...</div>
|
||||
) : taskList.length === 0 ? (
|
||||
<Empty
|
||||
description="暂无任务,请先创建"
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
className={styles.emptyState}
|
||||
/>
|
||||
) : (
|
||||
taskList.map(task => (
|
||||
<div
|
||||
key={task.taskId}
|
||||
className={`${styles.taskItem} ${selectedTaskId === task.taskId ? styles.selected : ''}`}
|
||||
onClick={() => setSelectedTaskId(task.taskId)}
|
||||
>
|
||||
<div className={styles.taskInfo}>
|
||||
<div className={styles.taskName}>{task.taskName}</div>
|
||||
<div className={styles.taskMeta}>
|
||||
<span className={`${styles.status} ${styles[`status${task.status}`]}`}>
|
||||
{task.statusDesc}
|
||||
</span>
|
||||
<span>{task.createTime}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.taskActions}>
|
||||
<Tooltip title="查看图片">
|
||||
<button
|
||||
className={styles.actionBtn}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleViewTaskImages(task);
|
||||
}}
|
||||
>
|
||||
<PictureOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
|
||||
{/* 实时位置 */}
|
||||
{realtimePosition && realtimePosition.longitude && (
|
||||
<div className={styles.realtimeInfo}>
|
||||
<div className={styles.realtimeTitle}>
|
||||
<EnvironmentOutlined /> 无人机实时位置
|
||||
<Tooltip title="飞到无人机位置">
|
||||
<button className={styles.locateBtn} onClick={flyToDrone}>
|
||||
<AimOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<div className={styles.coordsGrid}>
|
||||
<span>经度: {realtimePosition.longitude?.toFixed(6)}</span>
|
||||
<span>纬度: {realtimePosition.latitude?.toFixed(6)}</span>
|
||||
</div>
|
||||
<div className={styles.coordsGrid} style={{ marginTop: 4 }}>
|
||||
<span>相对高度: {realtimePosition.height != null ? `${realtimePosition.height.toFixed(1)}m` : '--'}</span>
|
||||
<span>海拔高度: {realtimePosition.elevation != null ? `${realtimePosition.elevation.toFixed(1)}m` : '--'}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 图片预览 */}
|
||||
<Image.PreviewGroup
|
||||
preview={{
|
||||
visible: imagePreviewVisible,
|
||||
onVisibleChange: (vis) => setImagePreviewVisible(vis),
|
||||
}}
|
||||
>
|
||||
{previewImages.map((src, index) => (
|
||||
<Image key={index} src={src} style={{ display: 'none' }} />
|
||||
))}
|
||||
</Image.PreviewGroup>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TaskPanel;
|
||||
+28
-9
@@ -108,22 +108,41 @@ export function useDeviceSSE(): UseDeviceSSEResult {
|
||||
const maxReconnectAttempts = 10;
|
||||
const shouldReconnectRef = useRef<boolean>(true);
|
||||
|
||||
// 核心断开逻辑,提取为纯函数以便在不同生命周期调用
|
||||
// 核心断开逻辑 - 使用 fetch DELETE 请求(正常关闭时调用)
|
||||
const performDisconnect = (deviceSn: string, sessionId: string, token: string | null) => {
|
||||
if (!deviceSn || !token) return;
|
||||
|
||||
// 尝试使用 fetch keepalive
|
||||
fetch(`/api-device/sse/device-status/${deviceSn}`, {
|
||||
const deleteUrl = `/api-device/sse/device-status/${deviceSn}`;
|
||||
|
||||
// 使用 fetch DELETE 请求(带 Authorization header)
|
||||
fetch(deleteUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'X-Client-Session-Id': sessionId,
|
||||
},
|
||||
keepalive: true,
|
||||
}).catch(err => console.error('Disconnect fetch failed:', err));
|
||||
}).then(() => {
|
||||
console.log('[DeviceSSE] DELETE 断开请求成功:', deviceSn);
|
||||
}).catch((e) => {
|
||||
console.warn('[DeviceSSE] DELETE 断开请求失败:', e);
|
||||
});
|
||||
};
|
||||
|
||||
// 备用方案:如果支持 Beacon 且后端允许 POST 处理断开 (通常 API 设计为 DELETE,Beacon 不适用,故仅作备注)
|
||||
// navigator.sendBeacon(...) 仅支持 POST
|
||||
// beforeunload 专用断开逻辑(浏览器刷新/关闭时用 sendBeacon)
|
||||
const performBeaconDisconnect = (deviceSn: string, sessionId: string) => {
|
||||
if (!deviceSn) return;
|
||||
|
||||
const beaconUrl = `/api-device/sse/device-status/${deviceSn}/disconnect`;
|
||||
|
||||
if (navigator.sendBeacon) {
|
||||
const blob = new Blob(
|
||||
[JSON.stringify({ sessionId })],
|
||||
{ type: 'application/json' }
|
||||
);
|
||||
navigator.sendBeacon(beaconUrl, blob);
|
||||
console.log('[DeviceSSE] sendBeacon 断开请求已发送:', deviceSn);
|
||||
}
|
||||
};
|
||||
|
||||
// 断开SSE连接
|
||||
@@ -323,12 +342,12 @@ export function useDeviceSSE(): UseDeviceSSEResult {
|
||||
doConnect(deviceSn);
|
||||
}, [disconnectSSE, doConnect]);
|
||||
|
||||
// 监听浏览器刷新/关闭事件 (beforeunload)
|
||||
// 监听浏览器刷新/关闭事件 (beforeunload) - 使用 sendBeacon
|
||||
useEffect(() => {
|
||||
const handleBeforeUnload = () => {
|
||||
if (currentDeviceSnRef.current) {
|
||||
const token = sessionStorage.getItem('access_token');
|
||||
performDisconnect(currentDeviceSnRef.current, clientSessionIdRef.current, token);
|
||||
// 浏览器刷新/关闭时用 sendBeacon(不需要 token,后端需要配置允许匿名访问)
|
||||
performBeaconDisconnect(currentDeviceSnRef.current, clientSessionIdRef.current);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+51
-7
@@ -108,19 +108,41 @@ export const useDroneSSE = (): UseDroneSSEReturn => {
|
||||
const maxReconnectAttempts = 10;
|
||||
const shouldReconnectRef = useRef<boolean>(true); // 是否应该自动重连
|
||||
|
||||
// 核心断开逻辑,提取为纯函数以便在不同生命周期调用
|
||||
// 核心断开逻辑 - 使用 fetch DELETE 请求(正常关闭时调用)
|
||||
const performDisconnect = (deviceSn: string, sessionId: string, token: string | null) => {
|
||||
if (!deviceSn || !token) return;
|
||||
|
||||
// 尝试使用 fetch keepalive
|
||||
fetch(`/api-device/sse/drone-telemetry/${deviceSn}`, {
|
||||
const deleteUrl = `/api-device/sse/drone-telemetry/${deviceSn}`;
|
||||
|
||||
// 使用 fetch DELETE 请求(带 Authorization header)
|
||||
fetch(deleteUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'X-Client-Session-Id': sessionId,
|
||||
},
|
||||
keepalive: true,
|
||||
}).catch(() => {});
|
||||
}).then(() => {
|
||||
console.log('[DroneSSE] DELETE 断开请求成功:', deviceSn);
|
||||
}).catch((e) => {
|
||||
console.warn('[DroneSSE] DELETE 断开请求失败:', e);
|
||||
});
|
||||
};
|
||||
|
||||
// beforeunload 专用断开逻辑(浏览器刷新/关闭时用 sendBeacon)
|
||||
const performBeaconDisconnect = (deviceSn: string, sessionId: string) => {
|
||||
if (!deviceSn) return;
|
||||
|
||||
const beaconUrl = `/api-device/sse/drone-telemetry/${deviceSn}/disconnect`;
|
||||
|
||||
if (navigator.sendBeacon) {
|
||||
const blob = new Blob(
|
||||
[JSON.stringify({ sessionId })],
|
||||
{ type: 'application/json' }
|
||||
);
|
||||
navigator.sendBeacon(beaconUrl, blob);
|
||||
console.log('[DroneSSE] sendBeacon 断开请求已发送:', deviceSn);
|
||||
}
|
||||
};
|
||||
|
||||
// 断开无人机SSE连接
|
||||
@@ -350,7 +372,23 @@ export const useDroneSSE = (): UseDroneSSEReturn => {
|
||||
dataReceivedRef.current = false;
|
||||
}, []);
|
||||
|
||||
// 组件卸载时自动断开连接
|
||||
// 监听浏览器刷新/关闭事件 (beforeunload) - 使用 sendBeacon
|
||||
useEffect(() => {
|
||||
const handleBeforeUnload = () => {
|
||||
if (currentDeviceSnRef.current) {
|
||||
// 浏览器刷新/关闭时用 sendBeacon(不需要 token,后端需要配置允许匿名访问)
|
||||
performBeaconDisconnect(currentDeviceSnRef.current, clientSessionIdRef.current);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 组件卸载时自动断开连接 (React Unmount)
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
// 清理重连定时器
|
||||
@@ -359,11 +397,17 @@ export const useDroneSSE = (): UseDroneSSEReturn => {
|
||||
reconnectTimerRef.current = null;
|
||||
}
|
||||
shouldReconnectRef.current = false;
|
||||
|
||||
// 在组件卸载时,也尝试发送断开请求
|
||||
if (currentDeviceSnRef.current) {
|
||||
disconnectDroneSSE(currentDeviceSnRef.current);
|
||||
const token = sessionStorage.getItem('access_token');
|
||||
performDisconnect(currentDeviceSnRef.current, clientSessionIdRef.current, token);
|
||||
}
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
};
|
||||
}, [disconnectDroneSSE]);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
// 状态
|
||||
|
||||
+29
@@ -3,6 +3,7 @@ import { message, Button, Tooltip } from 'antd';
|
||||
import { AppstoreOutlined } from '@ant-design/icons';
|
||||
import RightPanel from './3d/BottomPanel/RightPanel';
|
||||
import LeftControlPanel from './3d/BottomPanel/LeftControlPanel';
|
||||
import TaskPanel from './3d/BottomPanel/TaskPanel';
|
||||
import TilesetPanel from './3d/TilesetPanel';
|
||||
import { useTilesetLoader, TilesetConfig } from './3d/hooks/useTilesetLoader';
|
||||
import { getModelsByTourismId, convertToTilesetConfig } from '@/services/threeDModel';
|
||||
@@ -32,6 +33,10 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const [controlDevice, setControlDevice] = useState<any>(null);
|
||||
const [controlRealtimeData, setControlRealtimeData] = useState<any>(null);
|
||||
|
||||
// 任务管理面板状态
|
||||
const [taskPanelVisible, setTaskPanelVisible] = useState(false);
|
||||
const [taskPanelDevice, setTaskPanelDevice] = useState<any>(null);
|
||||
|
||||
// 3D Tiles 模型管理
|
||||
const [tilesetPanelVisible, setTilesetPanelVisible] = useState(false);
|
||||
const [currentTourismModels, setCurrentTourismModels] = useState<TilesetConfig[]>([]); // 当前景区的所有模型配置
|
||||
@@ -50,6 +55,8 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
// 相机飞到景区
|
||||
const flyToTourism = useCallback((tourism: any) => {
|
||||
if (!viewerRef.current || !Cesium) return;
|
||||
// 检查 viewer 是否已销毁
|
||||
if (viewerRef.current.isDestroyed?.()) return;
|
||||
|
||||
const lon = parseFloat(tourism.longitude);
|
||||
const lat = parseFloat(tourism.latitude);
|
||||
@@ -70,6 +77,8 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
// 相机飞回全球视角
|
||||
const flyToGlobal = useCallback(() => {
|
||||
if (!viewerRef.current || !Cesium) return;
|
||||
// 检查 viewer 是否已销毁
|
||||
if (viewerRef.current.isDestroyed?.()) return;
|
||||
|
||||
viewerRef.current.camera.flyTo({
|
||||
destination: Cesium.Cartesian3.fromDegrees(104.195397, 35.86166, 15000000),
|
||||
@@ -279,6 +288,8 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
// 如果有模型会自动飞到模型位置,没有模型才飞到景区位置
|
||||
if (tourism.id) {
|
||||
loadTourismModels(tourism.id).then((hasModel) => {
|
||||
// 异步回调时检查 viewer 是否还存在
|
||||
if (!viewerRef.current || viewerRef.current.isDestroyed?.()) return;
|
||||
if (!hasModel) {
|
||||
flyToTourism(tourism);
|
||||
}
|
||||
@@ -302,6 +313,12 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
setLeftPanelVisible(true);
|
||||
}, []);
|
||||
|
||||
// 处理从右侧面板点击"任务管理"
|
||||
const handleOpenTaskPanel = useCallback((device: any) => {
|
||||
setTaskPanelDevice(device);
|
||||
setTaskPanelVisible(true);
|
||||
}, []);
|
||||
|
||||
// 获取设备的视频流地址(从设备数据中获取)
|
||||
const getVideoStreamUrl = useCallback((device: any): string | undefined => {
|
||||
// 从设备配置获取视频流地址
|
||||
@@ -672,6 +689,18 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
tourism={selectedTourism}
|
||||
onClose={handleRightPanelClose}
|
||||
onControlClick={handleOpenControl}
|
||||
onTaskPanelOpen={handleOpenTaskPanel}
|
||||
viewer={viewerRef.current}
|
||||
Cesium={Cesium}
|
||||
/>
|
||||
|
||||
{/* 任务管理面板 - 左下角独立渲染 */}
|
||||
<TaskPanel
|
||||
visible={taskPanelVisible}
|
||||
onClose={() => setTaskPanelVisible(false)}
|
||||
device={taskPanelDevice}
|
||||
viewer={viewerRef.current}
|
||||
Cesium={Cesium}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -5,12 +5,32 @@
|
||||
|
||||
// SRS 服务器配置
|
||||
const SRS_CONFIG = {
|
||||
// 开发环境通过代理访问,生产环境直接访问
|
||||
baseUrl: process.env.NODE_ENV === 'development' ? '' : 'http://220.205.16.27:8024',
|
||||
// 所有环境都通过代理访问,避免跨域问题
|
||||
// 开发环境: webpack devServer 代理
|
||||
// 测试/生产环境: nginx 代理
|
||||
baseUrl: '',
|
||||
// 登录密码
|
||||
password: 'a6949674ed817fa3',
|
||||
};
|
||||
|
||||
// WebRTC ICE 服务器配置(用于 NAT 穿透)
|
||||
// 必须与 SRS 服务器配置的 STUN/TURN 一致
|
||||
const ICE_SERVERS: RTCConfiguration = {
|
||||
iceServers: [
|
||||
// 自建 STUN 服务器
|
||||
{ urls: 'stun:220.205.16.27:3478' },
|
||||
// 自建 TURN 服务器(用于复杂 NAT 环境)
|
||||
{
|
||||
urls: 'turn:220.205.16.27:3478?transport=udp',
|
||||
username: 'webrtc',
|
||||
credential: 'GoFly@2024',
|
||||
},
|
||||
// 备用 Google STUN(可选)
|
||||
{ urls: 'stun:stun.l.google.com:19302' },
|
||||
],
|
||||
iceCandidatePoolSize: 10,
|
||||
};
|
||||
|
||||
// 存储 token
|
||||
let srsToken: string | null = null;
|
||||
let tokenExpireTime: number = 0;
|
||||
@@ -113,8 +133,8 @@ export const srsApi = {
|
||||
|
||||
const url = srsApi.buildWhepUrl(streamId, options?.app);
|
||||
|
||||
// 创建 RTCPeerConnection
|
||||
const pc = new RTCPeerConnection();
|
||||
// 创建 RTCPeerConnection(配置 ICE 服务器用于 NAT 穿透)
|
||||
const pc = new RTCPeerConnection(ICE_SERVERS);
|
||||
const stream = new MediaStream();
|
||||
|
||||
// 设置接收音视频轨道
|
||||
@@ -183,16 +203,14 @@ export const srsApi = {
|
||||
try {
|
||||
// 解析 URL,提取路径部分通过代理访问(避免跨域)
|
||||
const urlObj = new URL(whepUrl);
|
||||
// 开发环境使用代理路径,生产环境使用完整 URL
|
||||
const actualUrl = process.env.NODE_ENV === 'development'
|
||||
? `${urlObj.pathname}${urlObj.search}` // 只使用路径和查询参数,通过代理访问
|
||||
: whepUrl;
|
||||
// 所有环境都使用代理路径,避免跨域问题
|
||||
const actualUrl = `${urlObj.pathname}${urlObj.search}`;
|
||||
|
||||
// 确保已登录
|
||||
const token = await srsApi.getToken();
|
||||
|
||||
// 创建 RTCPeerConnection
|
||||
const pc = new RTCPeerConnection();
|
||||
// 创建 RTCPeerConnection(配置 ICE 服务器用于 NAT 穿透)
|
||||
const pc = new RTCPeerConnection(ICE_SERVERS);
|
||||
const stream = new MediaStream();
|
||||
|
||||
// 设置接收音视频轨道
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
// 航线任务列表项
|
||||
export interface WaylineRouteListItemVO {
|
||||
routeId: string;
|
||||
routeName: string;
|
||||
fileWaylineId: string;
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
parseStatus: number;
|
||||
parseStatusDesc?: string;
|
||||
waypointCount: number;
|
||||
totalDistance: number;
|
||||
totalDuration: number;
|
||||
createTime: string;
|
||||
}
|
||||
|
||||
// 航点数据
|
||||
export interface WaypointVO {
|
||||
index: number;
|
||||
longitude: number;
|
||||
latitude: number;
|
||||
height: number;
|
||||
speed?: number;
|
||||
headingAngle?: number;
|
||||
actions?: WaypointActionVO[];
|
||||
}
|
||||
|
||||
// 轨迹点数据
|
||||
export interface TrackPointVO {
|
||||
lng: number;
|
||||
lat: number;
|
||||
alt?: number;
|
||||
height?: number;
|
||||
speed?: number;
|
||||
heading?: number;
|
||||
batteryPercent?: number;
|
||||
time?: string;
|
||||
deviationDistance?: number;
|
||||
isDeviation?: boolean;
|
||||
}
|
||||
|
||||
// 航点动作数据
|
||||
export interface WaypointActionVO {
|
||||
actionGroupId?: number;
|
||||
actionIndex?: number;
|
||||
actionType?: string;
|
||||
actionTypeDesc?: string;
|
||||
actionParams?: Record<string, any>;
|
||||
triggerType?: string;
|
||||
triggerTypeDesc?: string;
|
||||
delayTime?: number;
|
||||
payloadPositionIndex?: number;
|
||||
hoverTime?: number;
|
||||
aircraftHeading?: number;
|
||||
gimbalPitchRotateAngle?: number;
|
||||
gimbalYawRotateAngle?: number;
|
||||
focalLength?: number;
|
||||
megaphoneFilePath?: string;
|
||||
}
|
||||
|
||||
// 创建航线任务参数
|
||||
export interface CreateRouteParams {
|
||||
routeName: string;
|
||||
fileWaylineId: string;
|
||||
deviceSn: string;
|
||||
deviceName?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
// 航线任务详情
|
||||
export interface WaylineRouteDetailVO {
|
||||
routeId: string;
|
||||
routeName: string;
|
||||
fileWaylineId: string;
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
parseStatus: number;
|
||||
parseStatusDesc?: string;
|
||||
waypointCount: number;
|
||||
totalDistance: number;
|
||||
totalDuration: number;
|
||||
waypoints?: WaypointVO[];
|
||||
}
|
||||
|
||||
// 飞行轨迹数据
|
||||
export interface FlightTrackData {
|
||||
deviceSn: string;
|
||||
jobId?: string;
|
||||
routeId?: string;
|
||||
trackPoints: TrackPointVO[];
|
||||
totalPoints: number;
|
||||
duration: number;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}
|
||||
|
||||
// 航线任务详情(完整版)
|
||||
export interface RouteDetailVO {
|
||||
routeInfo: WaylineRouteListItemVO;
|
||||
waypoints: WaypointVO[];
|
||||
actions: WaypointActionVO[];
|
||||
totalWaypoints: number;
|
||||
totalActions: number;
|
||||
totalDistance: number;
|
||||
totalDuration: number;
|
||||
}
|
||||
|
||||
export const waylineRouteApi = {
|
||||
// ★ 创建航线任务(关联航迹文件和设备)
|
||||
createRoute: (params: CreateRouteParams) =>
|
||||
request('/api-device/device/route/create', { method: 'POST', data: params }),
|
||||
|
||||
// ★ 核心接口:根据设备SN获取绑定的航线任务列表(任务管理页面使用)
|
||||
getRouteListByDevice: (deviceSn: string) =>
|
||||
request(`/api-device/device/route/listByDevice/${deviceSn}`) as Promise<{ resp_code: number; data: WaylineRouteListItemVO[] }>,
|
||||
|
||||
// 获取航线任务详情(含航点)
|
||||
getRouteDetails: (routeId: string) =>
|
||||
request(`/api-device/device/route/detail/${routeId}`) as Promise<{ resp_code: number; data: WaylineRouteDetailVO }>,
|
||||
|
||||
// 获取航点列表(3D地图绑制航线使用)
|
||||
getRouteWaypoints: (routeId: string) =>
|
||||
request(`/api-device/device/route/waypoints/${routeId}`) as Promise<{ resp_code: number; data: WaypointVO[] }>,
|
||||
|
||||
// 解析航线任务
|
||||
parseRoute: (routeId: string) =>
|
||||
request(`/api-device/device/route/parse/${routeId}`, { method: 'POST' }),
|
||||
|
||||
// 批量解析航线任务
|
||||
batchParseRoutes: (routeIds: string[]) =>
|
||||
request('/api-device/device/route/parse/batch', { method: 'POST', data: routeIds }),
|
||||
|
||||
// 获取飞行轨迹
|
||||
getFlightTrack: (
|
||||
deviceSn: string,
|
||||
params?: {
|
||||
jobId?: string;
|
||||
routeId?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
limit?: number;
|
||||
}
|
||||
) =>
|
||||
request(`/api-device/device/drone/track/${deviceSn}`, { params }) as Promise<{ resp_code: number; data: FlightTrackData }>,
|
||||
|
||||
// 获取最新轨迹点
|
||||
getLatestTrackPoint: (deviceSn: string) =>
|
||||
request(`/api-device/device/drone/track/latest/${deviceSn}`) as Promise<{ resp_code: number; data: TrackPointVO }>,
|
||||
|
||||
// 删除历史轨迹
|
||||
deleteHistoryTracks: (deviceSn: string, beforeTime: string) =>
|
||||
request(`/api-device/device/drone/track/history/${deviceSn}`, {
|
||||
method: 'DELETE',
|
||||
params: { beforeTime },
|
||||
}),
|
||||
|
||||
// 统计轨迹点数量
|
||||
countTrackPoints: (
|
||||
deviceSn: string,
|
||||
params?: {
|
||||
jobId?: string;
|
||||
routeId?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}
|
||||
) =>
|
||||
request(`/api-device/device/drone/track/count/${deviceSn}`, { params }) as Promise<{ resp_code: number; data: number }>,
|
||||
|
||||
// 获取无人机设备列表(航线管理表单中选择设备使用)
|
||||
getDroneDeviceList: () =>
|
||||
request('/api-device/device/drone/list') as Promise<{ resp_code: number; data: Array<{ sn: string; deviceName: string }> }>,
|
||||
|
||||
// 获取航迹文件列表(创建航线任务时选择航迹文件使用)
|
||||
getWaylineFileList: (params?: any) =>
|
||||
request('/api-device/device/wayline', { params }) as Promise<{ resp_code: number; data: Array<{ waylineId: string; name: string }> }>,
|
||||
|
||||
// 根据航迹文件ID获取航线任务列表
|
||||
getRouteListByFileWaylineId: (fileWaylineId: string) =>
|
||||
request(`/api-device/device/route/listByFileWaylineId/${fileWaylineId}`) as Promise<{ resp_code: number; data: WaylineRouteListItemVO[] }>,
|
||||
|
||||
// 获取航线任务详情(含航点和动作)
|
||||
getRouteDetail: (routeId: string) =>
|
||||
request(`/api-device/device/route/detail/${routeId}`) as Promise<{ resp_code: number; data: RouteDetailVO }>,
|
||||
|
||||
// 绑定航迹文件到设备并解析航线
|
||||
bindWaylineToDevice: (params: {
|
||||
deviceSn: string;
|
||||
waylineId: string;
|
||||
waylineName: string;
|
||||
workspaceId?: string;
|
||||
}) =>
|
||||
request('/api-device/device/route/bindWaylineToDevice', { method: 'POST', data: params }),
|
||||
};
|
||||
Reference in New Issue
Block a user