feat: 3d控制指令
This commit is contained in:
@@ -208,7 +208,7 @@ const TourismDeviceDetail: React.FC<TourismDeviceDetailProps> = (props) => {
|
||||
// 提取每个查询结果的第一个设备
|
||||
const devices = results
|
||||
.map((res) => (res.data && res.data.length > 0 ? res.data[0] : null))
|
||||
.filter((device) => device !== null);
|
||||
.filter((device): device is any => device !== null);
|
||||
|
||||
setDeviceList(devices);
|
||||
|
||||
@@ -467,6 +467,16 @@ const TourismDeviceDetail: React.FC<TourismDeviceDetailProps> = (props) => {
|
||||
|
||||
setTakeoffLoading(true);
|
||||
try {
|
||||
console.log('发送起飞命令:', {
|
||||
deviceSn: selectedDeviceSn,
|
||||
targetLatitude: takeoffForm.targetLatitude,
|
||||
targetLongitude: takeoffForm.targetLongitude,
|
||||
targetHeight: takeoffForm.targetHeight,
|
||||
securityTakeoffHeight: takeoffForm.securityTakeoffHeight,
|
||||
rthAltitude: takeoffForm.rthAltitude,
|
||||
maxSpeed: takeoffForm.maxSpeed,
|
||||
});
|
||||
|
||||
const res = await deviceApi.takeoff({
|
||||
deviceSn: selectedDeviceSn,
|
||||
targetLatitude: takeoffForm.targetLatitude,
|
||||
@@ -477,14 +487,36 @@ const TourismDeviceDetail: React.FC<TourismDeviceDetailProps> = (props) => {
|
||||
maxSpeed: takeoffForm.maxSpeed,
|
||||
});
|
||||
|
||||
if (res.code === 0) {
|
||||
console.log('起飞命令响应:', res);
|
||||
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('起飞命令已发送,无人机将自动开机并起飞');
|
||||
setTakeoffModalVisible(false);
|
||||
} else {
|
||||
message.error(res.msg || '起飞命令发送失败');
|
||||
console.error('起飞命令失败:', res);
|
||||
message.error(msg || '起飞命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '起飞命令发送失败');
|
||||
console.error('起飞命令发送失败:', error);
|
||||
// 更详细的错误信息
|
||||
let errorMsg = '起飞命令发送失败';
|
||||
if (error.response) {
|
||||
// HTTP错误响应
|
||||
const data = error.response.data;
|
||||
// 兼容两种响应格式
|
||||
errorMsg = data?.resp_msg || data?.msg || error.response.statusText || errorMsg;
|
||||
} else if (error.message) {
|
||||
errorMsg = error.message;
|
||||
} else if (error.msg) {
|
||||
errorMsg = error.msg;
|
||||
} else if (error.resp_msg) {
|
||||
errorMsg = error.resp_msg;
|
||||
}
|
||||
message.error(errorMsg);
|
||||
} finally {
|
||||
setTakeoffLoading(false);
|
||||
}
|
||||
|
||||
+236
-67
@@ -6,9 +6,9 @@
|
||||
|
||||
.leftPanel {
|
||||
position: absolute;
|
||||
top: 64px;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
top: 64px;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: 400px;
|
||||
background: @bg-dark;
|
||||
backdrop-filter: blur(20px);
|
||||
@@ -17,13 +17,35 @@
|
||||
flex-direction: column;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
|
||||
z-index: 900;
|
||||
z-index: 900;
|
||||
box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
|
||||
|
||||
&.visible {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
// 全屏模式
|
||||
&.fullscreen {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 9999;
|
||||
transform: none;
|
||||
|
||||
.videoContainer {
|
||||
flex: 1;
|
||||
aspect-ratio: unset;
|
||||
}
|
||||
|
||||
.header, .flightDashboard, .controlsContent {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
@@ -36,7 +58,7 @@
|
||||
}
|
||||
|
||||
.header {
|
||||
padding: 16px 20px;
|
||||
padding: 12px 16px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
@@ -44,7 +66,7 @@
|
||||
background: rgba(0, 240, 255, 0.05);
|
||||
|
||||
.title {
|
||||
font-size: 16px;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
@@ -98,12 +120,132 @@
|
||||
.icon { font-size: 48px; margin-bottom: 12px; filter: drop-shadow(0 0 10px @cyan); }
|
||||
}
|
||||
|
||||
// 简化的HUD样式
|
||||
.hudTopLeft {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 8px;
|
||||
font-size: 11px;
|
||||
font-family: 'Consolas', monospace;
|
||||
pointer-events: none;
|
||||
|
||||
.statusLine {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.statusOk { color: #00ff88; }
|
||||
.statusErr { color: #ff4444; }
|
||||
|
||||
.hudTopRight {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
text-align: right;
|
||||
font-size: 14px;
|
||||
font-family: 'Consolas', monospace;
|
||||
font-weight: bold;
|
||||
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||
pointer-events: none;
|
||||
|
||||
span {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.hudBottom {
|
||||
position: absolute;
|
||||
bottom: 8px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
font-size: 11px;
|
||||
font-family: 'Consolas', monospace;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
padding: 4px 12px;
|
||||
border-radius: 4px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.hudBottomLeft {
|
||||
position: absolute;
|
||||
bottom: 8px;
|
||||
left: 8px;
|
||||
font-size: 10px;
|
||||
font-family: 'Consolas', monospace;
|
||||
color: rgba(0, 255, 255, 0.7);
|
||||
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
// 浮动控制按钮
|
||||
.floatingControls {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 8px;
|
||||
transform: translateY(-50%);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.floatBtn {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 240, 255, 0.3);
|
||||
border-color: @cyan;
|
||||
color: @cyan;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&.recording {
|
||||
background: rgba(255, 0, 0, 0.6);
|
||||
border-color: #ff4444;
|
||||
animation: recordPulse 1s infinite;
|
||||
}
|
||||
}
|
||||
|
||||
// 连接状态指示
|
||||
.connectionStatus {
|
||||
position: absolute;
|
||||
bottom: 8px;
|
||||
right: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.hudOverlay {
|
||||
position: absolute;
|
||||
top: 10px; left: 10px; right: 10px; bottom: 10px;
|
||||
pointer-events: none;
|
||||
border: 1px solid rgba(0, 240, 255, 0.3);
|
||||
|
||||
|
||||
.crosshair {
|
||||
position: absolute;
|
||||
top: 50%; left: 50%; width: 20px; height: 20px;
|
||||
@@ -115,38 +257,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 飞行仪表盘
|
||||
// 飞行仪表盘 - 更紧凑
|
||||
.flightDashboard {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
padding: 16px 20px;
|
||||
grid-template-columns: repeat(6, 1fr);
|
||||
gap: 4px;
|
||||
padding: 8px 12px;
|
||||
background: rgba(0,0,0,0.2);
|
||||
border-bottom: 1px solid rgba(255,255,255,0.05);
|
||||
|
||||
.dashItem {
|
||||
background: rgba(255,255,255,0.05);
|
||||
padding: 8px;
|
||||
padding: 6px 4px;
|
||||
border-radius: 4px;
|
||||
text-align: center;
|
||||
|
||||
.dashLabel { font-size: 10px; color: rgba(255,255,255,0.4); margin-bottom: 2px; }
|
||||
.dashValue { font-size: 14px; font-weight: bold; color: #fff; font-family: 'Consolas', monospace; }
|
||||
|
||||
.dashLabel { font-size: 9px; color: rgba(255,255,255,0.4); margin-bottom: 2px; }
|
||||
.dashValue { font-size: 12px; font-weight: bold; color: #fff; font-family: 'Consolas', monospace; }
|
||||
}
|
||||
}
|
||||
|
||||
.controlsContent {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
padding: 12px 16px;
|
||||
|
||||
.controlGroup {
|
||||
margin-bottom: 24px;
|
||||
|
||||
margin-bottom: 16px;
|
||||
|
||||
.groupTitle {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
margin-bottom: 12px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
&::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.1); margin-left: 8px; }
|
||||
@@ -154,67 +296,84 @@
|
||||
|
||||
.flightActions {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||
gap: 6px;
|
||||
|
||||
button {
|
||||
height: 36px;
|
||||
height: 32px;
|
||||
font-size: 12px;
|
||||
background: rgba(0, 240, 255, 0.1);
|
||||
border: 1px solid rgba(0, 240, 255, 0.3);
|
||||
color: @cyan;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s;
|
||||
&:hover { background: rgba(0, 240, 255, 0.2); }
|
||||
&.danger {
|
||||
background: rgba(255, 77, 79, 0.1);
|
||||
border-color: rgba(255, 77, 79, 0.3);
|
||||
color: #ff4d4f;
|
||||
&:hover { background: rgba(255, 77, 79, 0.2); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.joystickArea {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
|
||||
.joystickGroup {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background: rgba(0,0,0,0.3);
|
||||
padding: 12px 8px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255,255,255,0.05);
|
||||
// 键盘控制说明样式
|
||||
.keyboardHint {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 6px;
|
||||
padding: 12px;
|
||||
|
||||
.joystickLabel {
|
||||
font-size: 10px;
|
||||
color: rgba(255,255,255,0.4);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.keyGroup {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-bottom: 8px;
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
|
||||
.dpad {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 32px);
|
||||
grid-template-rows: repeat(3, 32px);
|
||||
gap: 4px;
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
color: #fff;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
|
||||
&:hover { background: @cyan; color: #000; box-shadow: 0 0 10px @cyan; }
|
||||
&:active { transform: scale(0.95); }
|
||||
.keyLabel {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
margin-right: 4px;
|
||||
min-width: 36px;
|
||||
}
|
||||
|
||||
&.up { grid-column: 2; grid-row: 1; }
|
||||
&.left { grid-column: 1; grid-row: 2; }
|
||||
&.right { grid-column: 3; grid-row: 2; }
|
||||
&.down { grid-column: 2; grid-row: 3; }
|
||||
}
|
||||
}
|
||||
kbd {
|
||||
display: inline-block;
|
||||
padding: 2px 6px;
|
||||
font-size: 11px;
|
||||
font-family: 'Consolas', monospace;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
min-width: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.activeKeyDisplay {
|
||||
margin-top: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.activeKey {
|
||||
background: @cyan;
|
||||
border-color: @cyan;
|
||||
color: #000;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 0 8px @cyan;
|
||||
animation: keyGlow 0.3s ease;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,3 +384,13 @@
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.4; }
|
||||
}
|
||||
|
||||
@keyframes recordPulse {
|
||||
0%, 100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.5); }
|
||||
50% { box-shadow: 0 0 10px 4px rgba(255, 0, 0, 0.3); }
|
||||
}
|
||||
|
||||
@keyframes keyGlow {
|
||||
from { transform: scale(1.2); }
|
||||
to { transform: scale(1); }
|
||||
}
|
||||
|
||||
+403
-241
@@ -2,17 +2,9 @@ import React, { useMemo, useState, useCallback, useEffect, useRef } from 'react'
|
||||
import {
|
||||
CloseOutlined,
|
||||
VideoCameraOutlined,
|
||||
ArrowUpOutlined,
|
||||
ArrowDownOutlined,
|
||||
ArrowLeftOutlined,
|
||||
ArrowRightOutlined,
|
||||
StopOutlined,
|
||||
HomeOutlined,
|
||||
CameraOutlined,
|
||||
RotateLeftOutlined,
|
||||
RotateRightOutlined,
|
||||
VerticalAlignTopOutlined,
|
||||
VerticalAlignBottomOutlined,
|
||||
CompassOutlined,
|
||||
WifiOutlined,
|
||||
LoadingOutlined,
|
||||
@@ -21,12 +13,16 @@ import {
|
||||
LinkOutlined,
|
||||
DisconnectOutlined,
|
||||
CaretRightOutlined,
|
||||
SwapOutlined,
|
||||
AimOutlined
|
||||
FullscreenOutlined,
|
||||
FullscreenExitOutlined,
|
||||
AimOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { message, Tooltip, Modal, Switch, Tag } from 'antd';
|
||||
import { message, Tooltip, Modal, Tag } from 'antd';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { deviceControlWs } from '@/services/deviceControlWs';
|
||||
import { useDroneSSE } from '../hooks/useDroneSSE';
|
||||
import WhepPlayer from './WhepPlayer';
|
||||
import styles from './LeftControlPanel.less';
|
||||
|
||||
interface LeftControlPanelProps {
|
||||
@@ -34,6 +30,8 @@ interface LeftControlPanelProps {
|
||||
onClose: () => void;
|
||||
device: any;
|
||||
realtimeData: any;
|
||||
/** 视频流完整地址(WHEP URL) */
|
||||
videoStreamUrl?: string;
|
||||
}
|
||||
|
||||
// 飞行模式映射
|
||||
@@ -52,81 +50,93 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
visible,
|
||||
onClose,
|
||||
device,
|
||||
realtimeData
|
||||
realtimeData,
|
||||
videoStreamUrl,
|
||||
}) => {
|
||||
const dockData = realtimeData?.rawData?.dockData;
|
||||
const droneData = realtimeData?.rawData?.droneData;
|
||||
const rawDroneData = realtimeData?.rawData?.droneData;
|
||||
|
||||
// 从 droneData (msg_alarm) 获取无人机实时飞行数据
|
||||
// droneData 结构: 根级别有 latitude, longitude, height, attitude_pitch 等
|
||||
// 云台数据在 payload 索引下,如 droneData["98-0-0"]
|
||||
// 获取设备SN
|
||||
const deviceSn = device?.deviceSn;
|
||||
|
||||
// 【重要】使用独立的无人机SSE连接 - 必须在 flightData useMemo 之前定义
|
||||
const {
|
||||
droneData,
|
||||
sseConnected: droneSseConnected,
|
||||
loading: droneSseLoading,
|
||||
hasData: droneHasData,
|
||||
connectDroneSSE,
|
||||
disconnectDroneSSE,
|
||||
resetDroneData,
|
||||
} = useDroneSSE();
|
||||
|
||||
// 从 droneData (独立SSE连接) 或 rawDroneData (props) 获取无人机实时飞行数据
|
||||
// 优先使用独立SSE连接的 droneData,因为它专门接收无人机遥测数据
|
||||
const flightData = useMemo(() => {
|
||||
// 调试日志 - 查看 droneData 的实际结构
|
||||
if (droneData) {
|
||||
console.log('[FlightData] droneData keys:', Object.keys(droneData));
|
||||
console.log('[FlightData] droneData.latitude:', droneData?.latitude);
|
||||
console.log('[FlightData] droneData.longitude:', droneData?.longitude);
|
||||
}
|
||||
// 优先使用独立SSE的droneData,其次使用rawDroneData
|
||||
const effectiveDroneData = droneData || rawDroneData;
|
||||
|
||||
// 获取云台payload数据 - 遍历查找带有 gimbal_pitch 的子对象
|
||||
let gimbalPayload: any = {};
|
||||
if (droneData) {
|
||||
if (effectiveDroneData) {
|
||||
// 常见的 payload 索引
|
||||
const payloadKeys = ['98-0-0', '39-0-0', '42-0-0', '43-0-0', '52-0-0', '53-0-0', '165-0-0'];
|
||||
for (const key of payloadKeys) {
|
||||
if (droneData[key] && (droneData[key].gimbal_pitch !== undefined || droneData[key].gimbal_yaw !== undefined)) {
|
||||
gimbalPayload = droneData[key];
|
||||
console.log('[FlightData] 找到云台数据在 key:', key, gimbalPayload);
|
||||
if (effectiveDroneData[key] && (effectiveDroneData[key].gimbal_pitch !== undefined || effectiveDroneData[key].gimbal_yaw !== undefined)) {
|
||||
gimbalPayload = effectiveDroneData[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 如果常见索引没找到,遍历所有数字格式的key
|
||||
if (!gimbalPayload.gimbal_pitch && !gimbalPayload.gimbal_yaw) {
|
||||
for (const key of Object.keys(droneData)) {
|
||||
if (/^\d+-\d+-\d+$/.test(key) && droneData[key]?.gimbal_pitch !== undefined) {
|
||||
gimbalPayload = droneData[key];
|
||||
console.log('[FlightData] 遍历找到云台数据在 key:', key);
|
||||
for (const key of Object.keys(effectiveDroneData)) {
|
||||
if (/^\d+-\d+-\d+$/.test(key) && effectiveDroneData[key]?.gimbal_pitch !== undefined) {
|
||||
gimbalPayload = effectiveDroneData[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const pitch = droneData?.attitude_pitch ?? 0;
|
||||
const roll = droneData?.attitude_roll ?? 0;
|
||||
const yaw = droneData?.attitude_head ?? 0;
|
||||
const hSpeed = droneData?.horizontal_speed ?? droneData?.ground_speed ?? 0;
|
||||
const vSpeed = droneData?.vertical_speed ?? 0;
|
||||
const altitude = droneData?.height ?? droneData?.elevation ?? realtimeData?.gps?.altitude ?? 0;
|
||||
const distance = droneData?.home_distance ?? 0;
|
||||
// 使用 effectiveDroneData 获取所有飞行数据
|
||||
const pitch = effectiveDroneData?.attitude_pitch ?? 0;
|
||||
const roll = effectiveDroneData?.attitude_roll ?? 0;
|
||||
const yaw = effectiveDroneData?.attitude_head ?? 0;
|
||||
const hSpeed = effectiveDroneData?.horizontal_speed ?? effectiveDroneData?.ground_speed ?? 0;
|
||||
const vSpeed = effectiveDroneData?.vertical_speed ?? 0;
|
||||
const altitude = effectiveDroneData?.height ?? effectiveDroneData?.elevation ?? realtimeData?.gps?.altitude ?? 0;
|
||||
const distance = effectiveDroneData?.home_distance ?? 0;
|
||||
|
||||
// GPS/RTK卫星数据
|
||||
const satellites = droneData?.position_state?.gps_number ?? dockData?.position_state?.gps_number ?? 0;
|
||||
const rtkSatellites = droneData?.position_state?.rtk_number ?? dockData?.position_state?.rtk_number ?? 0;
|
||||
const isFixed = droneData?.position_state?.is_fixed ?? dockData?.position_state?.is_fixed ?? 0;
|
||||
const satellites = effectiveDroneData?.position_state?.gps_number ?? dockData?.position_state?.gps_number ?? 0;
|
||||
const rtkSatellites = effectiveDroneData?.position_state?.rtk_number ?? dockData?.position_state?.rtk_number ?? 0;
|
||||
const isFixed = effectiveDroneData?.position_state?.is_fixed ?? dockData?.position_state?.is_fixed ?? 0;
|
||||
const rtkStatus = isFixed === 2 ? 'FIX' : (isFixed === 1 ? 'FLOAT' : (rtkSatellites > 0 ? 'FLOAT' : 'NONE'));
|
||||
|
||||
// 电池数据
|
||||
const batteryPercent = droneData?.battery?.capacity_percent ?? realtimeData?.battery ?? 0;
|
||||
const batteryVoltage = droneData?.battery?.voltage ?? 0;
|
||||
const batteryTemp = droneData?.battery?.temperature ?? 0;
|
||||
const remainFlightTime = droneData?.battery?.remain_flight_time ?? 0;
|
||||
// 电池数据 - 支持两种结构:直接的battery对象 或 嵌套的batteries数组
|
||||
const batteryData = effectiveDroneData?.battery;
|
||||
const batteryPercent = batteryData?.capacity_percent ?? realtimeData?.battery ?? 0;
|
||||
// 电压可能在 battery.voltage 或 battery.batteries[0].voltage
|
||||
const batteryVoltage = batteryData?.voltage ?? batteryData?.batteries?.[0]?.voltage ?? 0;
|
||||
// 温度可能在 battery.temperature 或 battery.batteries[0].temperature
|
||||
const batteryTemp = batteryData?.temperature ?? batteryData?.batteries?.[0]?.temperature ?? 0;
|
||||
const remainFlightTime = batteryData?.remain_flight_time ?? 0;
|
||||
|
||||
// 信号强度
|
||||
const signal = dockData?.wireless_link?.dongle_number ?? dockData?.sdr?.upward_quality ?? 0;
|
||||
|
||||
// 飞行模式
|
||||
const modeCode = droneData?.mode_code ?? 0;
|
||||
const modeCode = effectiveDroneData?.mode_code ?? 0;
|
||||
const flightMode = FLIGHT_MODE_MAP[modeCode] || `模式${modeCode}`;
|
||||
|
||||
// 云台角度 - 优先从 payload 中获取,否则从根级别获取
|
||||
const gimbalPitch = gimbalPayload?.gimbal_pitch ?? droneData?.gimbal_pitch ?? 0;
|
||||
const gimbalYaw = gimbalPayload?.gimbal_yaw ?? droneData?.gimbal_yaw ?? 0;
|
||||
const windSpeed = droneData?.wind_speed ?? 0;
|
||||
const gimbalPitch = gimbalPayload?.gimbal_pitch ?? effectiveDroneData?.gimbal_pitch ?? 0;
|
||||
const gimbalYaw = gimbalPayload?.gimbal_yaw ?? effectiveDroneData?.gimbal_yaw ?? 0;
|
||||
const windSpeed = effectiveDroneData?.wind_speed ?? 0;
|
||||
|
||||
// 无人机实时经纬度 - 直接从 droneData 根级别获取
|
||||
const droneLat = droneData?.latitude ?? 0;
|
||||
const droneLng = droneData?.longitude ?? 0;
|
||||
// 无人机实时经纬度 - 从 effectiveDroneData 获取
|
||||
const droneLat = effectiveDroneData?.latitude ?? 0;
|
||||
const droneLng = effectiveDroneData?.longitude ?? 0;
|
||||
|
||||
return {
|
||||
pitch: Number(pitch).toFixed(1),
|
||||
@@ -153,7 +163,7 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
latitude: Number(droneLat).toFixed(6),
|
||||
longitude: Number(droneLng).toFixed(6),
|
||||
};
|
||||
}, [droneData, dockData, realtimeData]);
|
||||
}, [droneData, rawDroneData, dockData, realtimeData]);
|
||||
|
||||
// 指令发送状态
|
||||
const [loading, setLoading] = useState<string | null>(null);
|
||||
@@ -163,36 +173,33 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
// WebSocket连接状态
|
||||
const [wsConnected, setWsConnected] = useState(false);
|
||||
|
||||
// 视频流连接状态
|
||||
const [videoConnected, setVideoConnected] = useState(false);
|
||||
|
||||
// 视频全屏状态
|
||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||
const videoContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// 键盘控制状态
|
||||
const [activeKeys, setActiveKeys] = useState<Set<string>>(new Set());
|
||||
const keyIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
// DRC模式状态 - 只需进入一次即可持续控制
|
||||
const [drcMode, setDrcMode] = useState(false);
|
||||
const drcModeRef = useRef(false); // 用于在回调中访问最新状态
|
||||
|
||||
// 获取设备SN
|
||||
const deviceSn = device?.deviceSn;
|
||||
|
||||
// WebSocket连接管理 + 无人机遥测数据订阅
|
||||
// WebSocket连接管理 + 无人机SSE连接管理
|
||||
useEffect(() => {
|
||||
if (visible && deviceSn) {
|
||||
// 1. 连接实时控制WebSocket
|
||||
deviceControlWs.connect(deviceSn);
|
||||
|
||||
// 2. 订阅无人机遥测数据(msg_alarm)
|
||||
// 只有进入操控台时才订阅,因为大部分时间无人机不在线
|
||||
console.log('[LeftControlPanel] 订阅无人机遥测数据:', deviceSn);
|
||||
deviceApi.subscribeDroneTelemetry(deviceSn).then((res) => {
|
||||
if (res.success) {
|
||||
console.log('[LeftControlPanel] 无人机遥测数据订阅成功');
|
||||
} else {
|
||||
console.warn('[LeftControlPanel] 无人机遥测数据订阅失败:', res.message);
|
||||
}
|
||||
});
|
||||
// 2. 建立独立的无人机SSE连接(专门接收无人机遥测数据)
|
||||
connectDroneSSE(deviceSn);
|
||||
|
||||
const unsubscribe = deviceControlWs.onStatusChange((connected) => {
|
||||
setWsConnected(connected);
|
||||
if (connected) {
|
||||
console.log('[LeftControlPanel] 实时控制WebSocket已连接');
|
||||
} else {
|
||||
console.log('[LeftControlPanel] 实时控制WebSocket已断开');
|
||||
if (!connected) {
|
||||
// 断开时重置DRC模式状态
|
||||
setDrcMode(false);
|
||||
drcModeRef.current = false;
|
||||
@@ -202,20 +209,23 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
return () => {
|
||||
unsubscribe();
|
||||
deviceControlWs.disconnect();
|
||||
|
||||
// 清理DRC模式状态
|
||||
setDrcMode(false);
|
||||
drcModeRef.current = false;
|
||||
|
||||
// 3. 取消订阅无人机遥测数据
|
||||
console.log('[LeftControlPanel] 取消订阅无人机遥测数据:', deviceSn);
|
||||
deviceApi.unsubscribeDroneTelemetry(deviceSn).then((res) => {
|
||||
if (res.success) {
|
||||
console.log('[LeftControlPanel] 无人机遥测数据已取消订阅');
|
||||
}
|
||||
});
|
||||
// 断开无人机SSE连接
|
||||
disconnectDroneSSE(deviceSn);
|
||||
resetDroneData();
|
||||
};
|
||||
}
|
||||
}, [visible, deviceSn]);
|
||||
}, [visible, deviceSn, connectDroneSSE, disconnectDroneSSE, resetDroneData]);
|
||||
|
||||
// 监控无人机SSE连接状态(静默)
|
||||
useEffect(() => {
|
||||
// 清理函数
|
||||
return () => {};
|
||||
}, [visible, deviceSn, droneSseConnected, droneSseLoading, droneHasData, droneData]);
|
||||
|
||||
// 进入DRC模式(只需调用一次)
|
||||
const enterDrcMode = useCallback(async () => {
|
||||
@@ -231,17 +241,32 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('drc');
|
||||
try {
|
||||
const res = await deviceApi.enterDrcMode(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
setDrcMode(true);
|
||||
drcModeRef.current = true;
|
||||
message.success('已进入指令飞行模式');
|
||||
return true;
|
||||
} else {
|
||||
message.error(res.msg || '进入指令飞行模式失败');
|
||||
message.error(msg || '进入指令飞行模式失败');
|
||||
return false;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '进入指令飞行模式失败');
|
||||
let errorMsg = '进入指令飞行模式失败';
|
||||
if (error.response) {
|
||||
const data = error.response.data;
|
||||
errorMsg = data?.resp_msg || data?.msg || error.response.statusText || errorMsg;
|
||||
} else if (error.message) {
|
||||
errorMsg = error.message;
|
||||
} else if (error.msg) {
|
||||
errorMsg = error.msg;
|
||||
} else if (error.resp_msg) {
|
||||
errorMsg = error.resp_msg;
|
||||
}
|
||||
message.error(errorMsg);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(null);
|
||||
@@ -262,10 +287,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('return');
|
||||
try {
|
||||
const res = await deviceApi.returnHome(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('返航命令已发送');
|
||||
} else {
|
||||
message.error(res.msg || '返航命令发送失败');
|
||||
message.error(msg || '返航命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '返航命令发送失败');
|
||||
@@ -286,10 +315,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('cancelReturn');
|
||||
try {
|
||||
const res = await deviceApi.cancelReturnHome(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('取消返航命令已发送');
|
||||
} else {
|
||||
message.error(res.msg || '取消返航命令发送失败');
|
||||
message.error(msg || '取消返航命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '取消返航命令发送失败');
|
||||
@@ -308,10 +341,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('pause');
|
||||
try {
|
||||
const res = await deviceApi.pause(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('航线暂停/悬停命令已发送');
|
||||
} else {
|
||||
message.error(res.msg || '暂停命令发送失败');
|
||||
message.error(msg || '暂停命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '暂停命令发送失败');
|
||||
@@ -330,10 +367,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('resume');
|
||||
try {
|
||||
const res = await deviceApi.resume(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('航线恢复命令已发送');
|
||||
} else {
|
||||
message.error(res.msg || '恢复命令发送失败');
|
||||
message.error(msg || '恢复命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '恢复命令发送失败');
|
||||
@@ -354,11 +395,15 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
// camera_mode: 0=拍照模式, 1=录像模式
|
||||
const cameraModeValue = mode === 'photo' ? 0 : 1;
|
||||
const res = await deviceApi.switchCameraMode(deviceSn, cameraModeValue);
|
||||
if (res?.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res?.resp_code !== undefined ? res.resp_code : res?.code;
|
||||
const msg = res?.resp_msg !== undefined ? res.resp_msg : res?.msg;
|
||||
|
||||
if (code === 0) {
|
||||
setCameraMode(mode);
|
||||
message.success(`已切换到${mode === 'photo' ? '拍照' : '录像'}模式`);
|
||||
} else {
|
||||
message.error(res?.msg || '切换相机模式失败');
|
||||
message.error(msg || '切换相机模式失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '切换相机模式失败');
|
||||
@@ -382,10 +427,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('photo');
|
||||
try {
|
||||
const res = await deviceApi.takePhoto(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('拍照命令已发送');
|
||||
} else {
|
||||
message.error(res.msg || '拍照命令发送失败');
|
||||
message.error(msg || '拍照命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '拍照命令发送失败');
|
||||
@@ -409,11 +458,15 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('recording');
|
||||
try {
|
||||
const res = await deviceApi.startRecording(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
setIsRecording(true);
|
||||
message.success('开始录像命令已发送');
|
||||
} else {
|
||||
message.error(res.msg || '开始录像命令发送失败');
|
||||
message.error(msg || '开始录像命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '开始录像命令发送失败');
|
||||
@@ -432,11 +485,15 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
setLoading('recording');
|
||||
try {
|
||||
const res = await deviceApi.stopRecording(deviceSn);
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
setIsRecording(false);
|
||||
message.success('停止录像命令已发送');
|
||||
} else {
|
||||
message.error(res.msg || '停止录像命令发送失败');
|
||||
message.error(msg || '停止录像命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '停止录像命令发送失败');
|
||||
@@ -521,8 +578,123 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
}
|
||||
}, [deviceSn, wsConnected, enterDrcMode]);
|
||||
|
||||
// 键盘按键映射
|
||||
const keyMappings: Record<string, { type: 'stick' | 'gimbal'; direction: string }> = {
|
||||
'w': { type: 'stick', direction: 'forward' }, // 前进
|
||||
's': { type: 'stick', direction: 'backward' }, // 后退
|
||||
'a': { type: 'stick', direction: 'left' }, // 左转
|
||||
'd': { type: 'stick', direction: 'right' }, // 右转
|
||||
'q': { type: 'stick', direction: 'moveLeft' }, // 向左平移
|
||||
'e': { type: 'stick', direction: 'moveRight' }, // 向右平移
|
||||
'r': { type: 'stick', direction: 'up' }, // 上升
|
||||
'f': { type: 'stick', direction: 'down' }, // 下降
|
||||
'arrowup': { type: 'gimbal', direction: 'up' }, // 云台上仰
|
||||
'arrowdown': { type: 'gimbal', direction: 'down' },// 云台下俯
|
||||
'arrowleft': { type: 'gimbal', direction: 'left' },// 云台左转
|
||||
'arrowright': { type: 'gimbal', direction: 'right' },// 云台右转
|
||||
};
|
||||
|
||||
// 处理键盘控制
|
||||
const handleKeyboardControl = useCallback(() => {
|
||||
if (activeKeys.size === 0) return;
|
||||
|
||||
activeKeys.forEach(key => {
|
||||
const mapping = keyMappings[key];
|
||||
if (mapping) {
|
||||
if (mapping.type === 'stick') {
|
||||
handleStickControl(mapping.direction);
|
||||
} else {
|
||||
handleGimbalControl(mapping.direction);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, [activeKeys, handleStickControl, handleGimbalControl]);
|
||||
|
||||
// 键盘事件监听
|
||||
useEffect(() => {
|
||||
if (!visible || !wsConnected) return;
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
const key = e.key.toLowerCase();
|
||||
if (keyMappings[key] && !activeKeys.has(key)) {
|
||||
e.preventDefault();
|
||||
setActiveKeys(prev => new Set(prev).add(key));
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyUp = (e: KeyboardEvent) => {
|
||||
const key = e.key.toLowerCase();
|
||||
if (keyMappings[key]) {
|
||||
e.preventDefault();
|
||||
setActiveKeys(prev => {
|
||||
const newSet = new Set(prev);
|
||||
newSet.delete(key);
|
||||
return newSet;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', handleKeyDown);
|
||||
window.addEventListener('keyup', handleKeyUp);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('keydown', handleKeyDown);
|
||||
window.removeEventListener('keyup', handleKeyUp);
|
||||
setActiveKeys(new Set());
|
||||
};
|
||||
}, [visible, wsConnected]);
|
||||
|
||||
// 持续发送控制指令
|
||||
useEffect(() => {
|
||||
if (activeKeys.size > 0 && wsConnected) {
|
||||
// 立即执行一次
|
||||
handleKeyboardControl();
|
||||
// 然后每100ms执行一次
|
||||
keyIntervalRef.current = setInterval(handleKeyboardControl, 100);
|
||||
} else {
|
||||
if (keyIntervalRef.current) {
|
||||
clearInterval(keyIntervalRef.current);
|
||||
keyIntervalRef.current = null;
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (keyIntervalRef.current) {
|
||||
clearInterval(keyIntervalRef.current);
|
||||
keyIntervalRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [activeKeys, wsConnected, handleKeyboardControl]);
|
||||
|
||||
// 全屏切换
|
||||
const toggleFullscreen = useCallback(() => {
|
||||
if (!videoContainerRef.current) return;
|
||||
|
||||
if (!isFullscreen) {
|
||||
if (videoContainerRef.current.requestFullscreen) {
|
||||
videoContainerRef.current.requestFullscreen();
|
||||
}
|
||||
} else {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
}, [isFullscreen]);
|
||||
|
||||
// 监听全屏变化
|
||||
useEffect(() => {
|
||||
const handleFullscreenChange = () => {
|
||||
setIsFullscreen(!!document.fullscreenElement);
|
||||
};
|
||||
|
||||
document.addEventListener('fullscreenchange', handleFullscreenChange);
|
||||
return () => {
|
||||
document.removeEventListener('fullscreenchange', handleFullscreenChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={`${styles.leftPanel} ${visible ? styles.visible : ''}`}>
|
||||
<div className={`${styles.leftPanel} ${visible ? styles.visible : ''} ${isFullscreen ? styles.fullscreen : ''}`}>
|
||||
<div className={styles.header}>
|
||||
<div className={styles.title}>
|
||||
<VideoCameraOutlined />
|
||||
@@ -534,73 +706,122 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className={styles.videoContainer}>
|
||||
<div className={styles.videoPlaceholder}>
|
||||
<VideoCameraOutlined className={styles.icon} />
|
||||
<span>等待图传信号...</span>
|
||||
<span style={{fontSize: 12, marginTop: 8}}>{device?.deviceSn || '未选择设备'}</span>
|
||||
|
||||
<div className={styles.videoContainer} ref={videoContainerRef}>
|
||||
{/* 使用 WHEP WebRTC 播放器 */}
|
||||
{videoStreamUrl ? (
|
||||
<WhepPlayer
|
||||
url={videoStreamUrl}
|
||||
autoPlay={visible}
|
||||
muted={true}
|
||||
videoOnly={true}
|
||||
onConnectionChange={setVideoConnected}
|
||||
/>
|
||||
) : (
|
||||
<div className={styles.videoPlaceholder}>
|
||||
<VideoCameraOutlined className={styles.icon} />
|
||||
<span>未配置视频流地址</span>
|
||||
<span style={{fontSize: 12, marginTop: 8}}>{device?.deviceSn || '未选择设备'}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 简化的HUD - 左上角状态指示 */}
|
||||
<div className={styles.hudTopLeft}>
|
||||
<div className={styles.statusLine}>
|
||||
<span className={droneData ? styles.statusOk : styles.statusErr}>●</span>
|
||||
{flightData.flightMode}
|
||||
</div>
|
||||
<div className={styles.statusLine}>
|
||||
<span className={videoConnected ? styles.statusOk : styles.statusErr}>●</span>
|
||||
图传
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.hudOverlay}>
|
||||
<div className={styles.crosshair} />
|
||||
{/* HUD左上角 - 飞行模式和状态 */}
|
||||
<div style={{position: 'absolute', top: 10, left: 10, color: '#0f0', fontSize: 12, fontFamily: 'monospace'}}>
|
||||
MODE: {flightData.flightMode}<br/>
|
||||
<span style={{color: droneData ? '#0f0' : '#f00'}}>
|
||||
{droneData ? '● 遥测正常' : '○ 等待遥测'}
|
||||
</span><br/>
|
||||
GIMBAL: P{flightData.gimbalPitch}° Y{flightData.gimbalYaw}°
|
||||
</div>
|
||||
{/* HUD左下角 - 无人机GPS坐标和高度 */}
|
||||
<div style={{position: 'absolute', bottom: 30, left: 10, color: '#0ff', fontSize: 11, fontFamily: 'monospace'}}>
|
||||
<AimOutlined style={{marginRight: 4}} />
|
||||
LAT: {flightData.latitude}°<br/>
|
||||
<span style={{marginLeft: 16}}>LNG: {flightData.longitude}°</span><br/>
|
||||
<span style={{marginLeft: 16}}>ALT: {flightData.altitude}m</span>
|
||||
</div>
|
||||
{/* HUD右上角 - 电池信息 */}
|
||||
<div style={{position: 'absolute', top: 10, right: 10, color: '#fff', fontSize: 12, fontFamily: 'monospace', textAlign: 'right'}}>
|
||||
<span style={{color: Number(flightData.batteryPercent) > 30 ? '#0f0' : '#f00'}}>
|
||||
BAT: {flightData.batteryPercent}%
|
||||
</span><br/>
|
||||
{flightData.batteryVoltage}V / {flightData.batteryTemp}°C<br/>
|
||||
<span style={{color: '#0ff'}}>剩余: {flightData.remainFlightTime}min</span>
|
||||
</div>
|
||||
{/* HUD底部状态条 */}
|
||||
<div style={{
|
||||
position: 'absolute', bottom: 10, left: 10, right: 10,
|
||||
display: 'flex', justifyContent: 'space-between',
|
||||
color: '#fff', fontSize: 12, textShadow: '0 0 2px #000'
|
||||
}}>
|
||||
<span>H: {flightData.altitude}m</span>
|
||||
<span>D: {flightData.distance}m</span>
|
||||
<span>H.S: {flightData.hSpeed}m/s</span>
|
||||
<span>V.S: {flightData.vSpeed}m/s</span>
|
||||
<span>WIND: {flightData.windSpeed}m/s</span>
|
||||
</div>
|
||||
|
||||
{/* 简化的HUD - 右上角电池 */}
|
||||
<div className={styles.hudTopRight}>
|
||||
<span style={{color: Number(flightData.batteryPercent) > 30 ? '#0f0' : '#f00'}}>
|
||||
{flightData.batteryPercent}%
|
||||
</span>
|
||||
<span style={{color: '#888', fontSize: 10}}>{flightData.batteryVoltage}V</span>
|
||||
</div>
|
||||
|
||||
{/* 简化的HUD - 底部数据条 */}
|
||||
<div className={styles.hudBottom}>
|
||||
<span>H:{flightData.altitude}m</span>
|
||||
<span>D:{flightData.distance}m</span>
|
||||
<span>HS:{flightData.hSpeed}</span>
|
||||
<span>VS:{flightData.vSpeed}</span>
|
||||
</div>
|
||||
|
||||
{/* 云台角度指示 - 左下角小字 */}
|
||||
<div className={styles.hudBottomLeft}>
|
||||
<AimOutlined /> P{flightData.gimbalPitch}° Y{flightData.gimbalYaw}°
|
||||
</div>
|
||||
|
||||
{/* 浮动控制按钮组 - 右侧 */}
|
||||
<div className={styles.floatingControls}>
|
||||
{/* 全屏按钮 */}
|
||||
<Tooltip title={isFullscreen ? '退出全屏' : '全屏'} placement="left">
|
||||
<button className={styles.floatBtn} onClick={toggleFullscreen}>
|
||||
{isFullscreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
{/* 拍照按钮 */}
|
||||
<Tooltip title="拍照 (Space)" placement="left">
|
||||
<button
|
||||
className={styles.floatBtn}
|
||||
onClick={handleTakePhoto}
|
||||
disabled={loading === 'photo'}
|
||||
>
|
||||
{loading === 'photo' ? <LoadingOutlined /> : <CameraOutlined />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
{/* 录像按钮 */}
|
||||
<Tooltip title={isRecording ? '停止录像' : '开始录像'} placement="left">
|
||||
<button
|
||||
className={`${styles.floatBtn} ${isRecording ? styles.recording : ''}`}
|
||||
onClick={isRecording ? handleStopRecording : handleStartRecording}
|
||||
disabled={loading === 'recording'}
|
||||
>
|
||||
{loading === 'recording' ? <LoadingOutlined /> : (isRecording ? <StopOutlined /> : <PlayCircleOutlined />)}
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{/* DRC模式和连接状态指示 - 左下 */}
|
||||
<div className={styles.connectionStatus}>
|
||||
{wsConnected ? (
|
||||
<LinkOutlined style={{ color: '#00ff88' }} />
|
||||
) : (
|
||||
<DisconnectOutlined style={{ color: '#ff4444' }} />
|
||||
)}
|
||||
{drcMode && <Tag color="green" style={{ marginLeft: 4, fontSize: 10 }}>DRC</Tag>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 飞行仪表盘区域 */}
|
||||
{/* 飞行仪表盘区域 - 更紧凑 */}
|
||||
<div className={styles.flightDashboard}>
|
||||
<Tooltip title="俯仰角 - 无人机前后倾斜角度">
|
||||
<Tooltip title="俯仰角">
|
||||
<div className={styles.dashItem}>
|
||||
<div className={styles.dashLabel}><CompassOutlined /> PITCH</div>
|
||||
<div className={styles.dashLabel}>PITCH</div>
|
||||
<div className={styles.dashValue}>{flightData.pitch}°</div>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip title="横滚角 - 无人机左右倾斜角度">
|
||||
<Tooltip title="横滚角">
|
||||
<div className={styles.dashItem}>
|
||||
<div className={styles.dashLabel}><CompassOutlined /> ROLL</div>
|
||||
<div className={styles.dashLabel}>ROLL</div>
|
||||
<div className={styles.dashValue}>{flightData.roll}°</div>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip title="偏航角 - 无人机航向角度">
|
||||
<Tooltip title="偏航角">
|
||||
<div className={styles.dashItem}>
|
||||
<div className={styles.dashLabel}><CompassOutlined /> YAW</div>
|
||||
<div className={styles.dashLabel}>YAW</div>
|
||||
<div className={styles.dashValue}>{flightData.yaw}°</div>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip title={`RTK定位状态 (RTK卫星数: ${flightData.rtkSatellites})`}>
|
||||
<Tooltip title={`RTK (${flightData.rtkSatellites}星)`}>
|
||||
<div className={styles.dashItem}>
|
||||
<div className={styles.dashLabel}>RTK</div>
|
||||
<div className={styles.dashValue} style={{
|
||||
@@ -611,7 +832,7 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip title="GPS卫星数量">
|
||||
<Tooltip title="GPS卫星数">
|
||||
<div className={styles.dashItem}>
|
||||
<div className={styles.dashLabel}>SAT</div>
|
||||
<div className={styles.dashValue} style={{
|
||||
@@ -622,9 +843,9 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip title="图传信号质量">
|
||||
<Tooltip title="信号质量">
|
||||
<div className={styles.dashItem}>
|
||||
<div className={styles.dashLabel}><WifiOutlined /> LINK</div>
|
||||
<div className={styles.dashLabel}>LINK</div>
|
||||
<div className={styles.dashValue} style={{
|
||||
color: flightData.signal >= 70 ? '#00ff88' :
|
||||
flightData.signal >= 40 ? '#ffaa00' : '#ff4444'
|
||||
@@ -638,113 +859,54 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
<div className={styles.controlsContent}>
|
||||
{/* 飞行控制指令 */}
|
||||
<div className={styles.controlGroup}>
|
||||
<div className={styles.groupTitle}>飞行控制 / FLIGHT CONTROL</div>
|
||||
<div className={styles.groupTitle}>飞行控制</div>
|
||||
<div className={styles.flightActions}>
|
||||
<button onClick={handleReturnHome} disabled={loading === 'return'}>
|
||||
{loading === 'return' ? <LoadingOutlined /> : <HomeOutlined />} 一键返航
|
||||
{loading === 'return' ? <LoadingOutlined /> : <HomeOutlined />} 返航
|
||||
</button>
|
||||
<button onClick={handleCancelReturn} disabled={loading === 'cancelReturn'}>
|
||||
{loading === 'cancelReturn' ? <LoadingOutlined /> : <StopOutlined />} 取消返航
|
||||
{loading === 'cancelReturn' ? <LoadingOutlined /> : <StopOutlined />} 取消
|
||||
</button>
|
||||
<button className={styles.danger} onClick={handlePause} disabled={loading === 'pause'}>
|
||||
{loading === 'pause' ? <LoadingOutlined /> : <PauseCircleOutlined />} 航线暂停
|
||||
{loading === 'pause' ? <LoadingOutlined /> : <PauseCircleOutlined />} 暂停
|
||||
</button>
|
||||
<button onClick={handleResume} disabled={loading === 'resume'}>
|
||||
{loading === 'resume' ? <LoadingOutlined /> : <CaretRightOutlined />} 航线恢复
|
||||
{loading === 'resume' ? <LoadingOutlined /> : <CaretRightOutlined />} 恢复
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 相机控制 */}
|
||||
{/* 键盘控制说明 */}
|
||||
<div className={styles.controlGroup}>
|
||||
<div className={styles.groupTitle}>
|
||||
相机控制 / CAMERA
|
||||
<Tag color={cameraMode === 'photo' ? 'blue' : 'red'} style={{ marginLeft: 8 }}>
|
||||
{cameraMode === 'photo' ? '拍照模式' : '录像模式'}
|
||||
</Tag>
|
||||
<ThunderboltOutlined /> 键盘控制
|
||||
<span style={{ marginLeft: 8, fontSize: 11, color: wsConnected ? '#00ff88' : '#ff4444' }}>
|
||||
{wsConnected ? '已连接' : '未连接'}
|
||||
</span>
|
||||
</div>
|
||||
<div className={styles.flightActions}>
|
||||
<button onClick={handleTakePhoto} disabled={loading === 'photo'}>
|
||||
{loading === 'photo' ? <LoadingOutlined /> : <CameraOutlined />} 拍照
|
||||
</button>
|
||||
{!isRecording ? (
|
||||
<button onClick={handleStartRecording} disabled={loading === 'recording'}>
|
||||
{loading === 'recording' ? <LoadingOutlined /> : <PlayCircleOutlined />} 开始录像
|
||||
</button>
|
||||
) : (
|
||||
<button className={styles.danger} onClick={handleStopRecording} disabled={loading === 'recording'}>
|
||||
{loading === 'recording' ? <LoadingOutlined /> : <StopOutlined />} 停止录像
|
||||
</button>
|
||||
)}
|
||||
<button onClick={() => handleSwitchCameraMode(cameraMode === 'photo' ? 'video' : 'photo')} disabled={loading === 'switchMode'}>
|
||||
{loading === 'switchMode' ? <LoadingOutlined /> : <SwapOutlined />} 切换模式
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 飞行姿态控制 (模拟双摇杆) */}
|
||||
<div className={styles.controlGroup}>
|
||||
<div className={styles.groupTitle}>
|
||||
姿态控制 / ATTITUDE CONTROL
|
||||
<Tooltip title={wsConnected ? '实时控制通道已连接' : '实时控制通道未连接'}>
|
||||
<span style={{ marginLeft: 8, fontSize: 12 }}>
|
||||
{wsConnected ? (
|
||||
<LinkOutlined style={{ color: '#00ff88' }} />
|
||||
) : (
|
||||
<DisconnectOutlined style={{ color: '#ff4444' }} />
|
||||
)}
|
||||
</span>
|
||||
</Tooltip>
|
||||
{drcMode && (
|
||||
<Tag color="green" style={{ marginLeft: 8 }}>DRC模式</Tag>
|
||||
<div className={styles.keyboardHint}>
|
||||
<div className={styles.keyGroup}>
|
||||
<span className={styles.keyLabel}>飞行:</span>
|
||||
<kbd>W</kbd><kbd>A</kbd><kbd>S</kbd><kbd>D</kbd>
|
||||
<span style={{margin: '0 4px'}}>|</span>
|
||||
<kbd>Q</kbd><kbd>E</kbd> 平移
|
||||
<span style={{margin: '0 4px'}}>|</span>
|
||||
<kbd>R</kbd><kbd>F</kbd> 升降
|
||||
</div>
|
||||
<div className={styles.keyGroup}>
|
||||
<span className={styles.keyLabel}>云台:</span>
|
||||
<kbd>↑</kbd><kbd>↓</kbd><kbd>←</kbd><kbd>→</kbd>
|
||||
</div>
|
||||
{/* 当前按下的键 */}
|
||||
{activeKeys.size > 0 && (
|
||||
<div className={styles.activeKeyDisplay}>
|
||||
{Array.from(activeKeys).map(key => (
|
||||
<kbd key={key} className={styles.activeKey}>{key.toUpperCase()}</kbd>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className={styles.joystickArea}>
|
||||
{/* 左手:升降 + 转向 */}
|
||||
<div className={styles.joystickGroup}>
|
||||
<div className={styles.joystickLabel}>升降 & 偏航 (Left)</div>
|
||||
<div className={styles.dpad}>
|
||||
<button className={styles.up} onClick={() => handleStickControl('up')} title="上升"><VerticalAlignTopOutlined /></button>
|
||||
<button className={styles.left} onClick={() => handleStickControl('left')} title="左转"><RotateLeftOutlined /></button>
|
||||
<button className={styles.right} onClick={() => handleStickControl('right')} title="右转"><RotateRightOutlined /></button>
|
||||
<button className={styles.down} onClick={() => handleStickControl('down')} title="下降"><VerticalAlignBottomOutlined /></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 右手:前后 + 左右 */}
|
||||
<div className={styles.joystickGroup}>
|
||||
<div className={styles.joystickLabel}>水平移动 (Right)</div>
|
||||
<div className={styles.dpad}>
|
||||
<button className={styles.up} onClick={() => handleStickControl('forward')} title="前进"><ArrowUpOutlined /></button>
|
||||
<button className={styles.left} onClick={() => handleStickControl('moveLeft')} title="向左"><ArrowLeftOutlined /></button>
|
||||
<button className={styles.right} onClick={() => handleStickControl('moveRight')} title="向右"><ArrowRightOutlined /></button>
|
||||
<button className={styles.down} onClick={() => handleStickControl('backward')} title="后退"><ArrowDownOutlined /></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 云台控制 */}
|
||||
<div className={styles.controlGroup}>
|
||||
<div className={styles.groupTitle}>
|
||||
云台控制 / GIMBAL
|
||||
{drcMode && (
|
||||
<Tag color="green" style={{ marginLeft: 8 }}>DRC模式</Tag>
|
||||
)}
|
||||
</div>
|
||||
<div className={styles.joystickArea}>
|
||||
<div className={styles.joystickGroup} style={{flex: 1}}>
|
||||
<div className={styles.joystickLabel}>云台方向</div>
|
||||
<div className={styles.dpad}>
|
||||
<button className={styles.up} onClick={() => handleGimbalControl('up')} title="云台上仰"><ArrowUpOutlined /></button>
|
||||
<button className={styles.left} onClick={() => handleGimbalControl('left')} title="云台左转"><ArrowLeftOutlined /></button>
|
||||
<button className={styles.right} onClick={() => handleGimbalControl('right')} title="云台右转"><ArrowRightOutlined /></button>
|
||||
<button className={styles.down} onClick={() => handleGimbalControl('down')} title="云台下俯"><ArrowDownOutlined /></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
+20
-3
@@ -140,13 +140,30 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
maxSpeed: 5,
|
||||
});
|
||||
|
||||
if (res.code === 0) {
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('起飞命令已发送,无人机将自动开机并起飞');
|
||||
} else {
|
||||
message.error(res.msg || '起飞命令发送失败');
|
||||
message.error(msg || '起飞命令发送失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '起飞命令发送失败');
|
||||
console.error('起飞命令发送失败:', error);
|
||||
// 更详细的错误信息
|
||||
let errorMsg = '起飞命令发送失败';
|
||||
if (error.response) {
|
||||
const data = error.response.data;
|
||||
errorMsg = data?.resp_msg || data?.msg || error.response.statusText || errorMsg;
|
||||
} else if (error.message) {
|
||||
errorMsg = error.message;
|
||||
} else if (error.msg) {
|
||||
errorMsg = error.msg;
|
||||
} else if (error.resp_msg) {
|
||||
errorMsg = error.resp_msg;
|
||||
}
|
||||
message.error(errorMsg);
|
||||
} finally {
|
||||
setTakeoffLoading(false);
|
||||
}
|
||||
|
||||
+9
-1
@@ -93,8 +93,16 @@ export const useTilesetLoader = (): UseTilesetLoaderResult => {
|
||||
});
|
||||
|
||||
try {
|
||||
// 处理跨域问题:非 localhost 访问时将 CDN URL 转换为代理路径
|
||||
let tilesetUrl = config.url;
|
||||
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||
if (!isLocalhost && tilesetUrl.includes('minicdn.goflytec.com')) {
|
||||
tilesetUrl = tilesetUrl.replace('https://minicdn.goflytec.com', '');
|
||||
console.log('[Tileset] 使用代理路径:', tilesetUrl);
|
||||
}
|
||||
|
||||
// 创建3DTileset - 高清晰度渲染配置
|
||||
const tileset = await Cesium.Cesium3DTileset.fromUrl(config.url, {
|
||||
const tileset = await Cesium.Cesium3DTileset.fromUrl(tilesetUrl, {
|
||||
// 核心清晰度控制 - 值越小越清晰(大疆司空使用约1-2)
|
||||
maximumScreenSpaceError: config.style?.maximumScreenSpaceError ?? 1,
|
||||
maximumMemoryUsage: config.style?.maximumMemoryUsage ?? 2048, // 增加内存以加载更多高精度瓦片
|
||||
|
||||
+29
-3
@@ -13,10 +13,11 @@ let Cesium: any = null;
|
||||
interface CesiumContainerProps {
|
||||
tourismList: any[];
|
||||
externalSelectedTourism?: any; // 接收外部选择的景区
|
||||
onClearSelection?: () => void; // 清空选择的回调
|
||||
}
|
||||
|
||||
const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const { tourismList, externalSelectedTourism } = props;
|
||||
const { tourismList, externalSelectedTourism, onClearSelection } = props;
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const viewerRef = useRef<any>(null);
|
||||
const entitiesRef = useRef<Map<string, any>>(new Map());
|
||||
@@ -294,20 +295,44 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
}
|
||||
}, [externalSelectedTourism, loading, handleTourismSelect]);
|
||||
|
||||
// 处理从右侧面板点击“操控”
|
||||
// 处理从右侧面板点击"操控"
|
||||
const handleOpenControl = useCallback((device: any, realtimeData: any) => {
|
||||
setControlDevice(device);
|
||||
setControlRealtimeData(realtimeData);
|
||||
setLeftPanelVisible(true);
|
||||
}, []);
|
||||
|
||||
// 获取设备的视频流地址(从设备数据中获取)
|
||||
const getVideoStreamUrl = useCallback((device: any): string | undefined => {
|
||||
// 从设备配置获取视频流地址
|
||||
return device?.videoStreamUrl || undefined;
|
||||
}, []);
|
||||
|
||||
// 关闭右侧面板
|
||||
const handleRightPanelClose = useCallback(() => {
|
||||
setRightPanelVisible(false);
|
||||
setSelectedTourism(null);
|
||||
setLeftPanelVisible(false); // 同时也关闭左侧
|
||||
|
||||
// 【修复】卸载所有3D模型,避免返回地球时出现渲染问题(黑洞)
|
||||
if (viewerRef.current) {
|
||||
unloadAllTilesets(viewerRef.current);
|
||||
}
|
||||
setCurrentTourismModels([]);
|
||||
setTilesetPanelVisible(false);
|
||||
|
||||
// 【修复】重置地形为椭球地形(快速响应,避免地形问题)
|
||||
if (viewerRef.current && Cesium) {
|
||||
viewerRef.current.terrainProvider = new Cesium.EllipsoidTerrainProvider();
|
||||
viewerRef.current.scene.globe.depthTestAgainstTerrain = false;
|
||||
terrainLoadedRef.current = false;
|
||||
}
|
||||
|
||||
// 【修复】通知父组件清空景区选择框
|
||||
onClearSelection?.();
|
||||
|
||||
flyToGlobal();
|
||||
}, [flyToGlobal]);
|
||||
}, [flyToGlobal, unloadAllTilesets, onClearSelection]);
|
||||
|
||||
// ========== 3D Tiles 模型管理方法 ==========
|
||||
|
||||
@@ -638,6 +663,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
onClose={() => setLeftPanelVisible(false)}
|
||||
device={controlDevice}
|
||||
realtimeData={controlRealtimeData}
|
||||
videoStreamUrl={getVideoStreamUrl(controlDevice)}
|
||||
/>
|
||||
|
||||
{/* 右侧数据面板 */}
|
||||
|
||||
+3
-1
@@ -8,10 +8,11 @@ interface MapContainerProps {
|
||||
tourismList: any[];
|
||||
onTourismClick: (tourism: any) => void;
|
||||
selectedTourism?: any;
|
||||
onClearSelection?: () => void; // 清空选择的回调
|
||||
}
|
||||
|
||||
const MapContainer: React.FC<MapContainerProps> = (props) => {
|
||||
const { mode, tourismList, onTourismClick, selectedTourism } = props;
|
||||
const { mode, tourismList, onTourismClick, selectedTourism, onClearSelection } = props;
|
||||
|
||||
return (
|
||||
<div className={styles.mapContainer}>
|
||||
@@ -25,6 +26,7 @@ const MapContainer: React.FC<MapContainerProps> = (props) => {
|
||||
<CesiumContainer
|
||||
tourismList={tourismList}
|
||||
externalSelectedTourism={selectedTourism}
|
||||
onClearSelection={onClearSelection}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -94,6 +94,11 @@ const MapDashboard: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 清空景区选择(关闭设备详情页面时调用)
|
||||
const handleClearSelection = () => {
|
||||
setSelectedTourism(null);
|
||||
};
|
||||
|
||||
// 地图模式切换
|
||||
const handleMapModeChange = (mode: MapMode) => {
|
||||
setMapMode(mode);
|
||||
@@ -143,7 +148,10 @@ const MapDashboard: React.FC = () => {
|
||||
showSearch
|
||||
placeholder="请选择景区进入..."
|
||||
optionFilterProp="children"
|
||||
value={selectedTourism?.id}
|
||||
onChange={handleDropdownSelect}
|
||||
allowClear
|
||||
onClear={handleClearSelection}
|
||||
filterOption={(input, option) =>
|
||||
(option?.children as unknown as string).toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||
}
|
||||
@@ -196,6 +204,7 @@ const MapDashboard: React.FC = () => {
|
||||
tourismList={tourismList}
|
||||
onTourismClick={handleTourismClick}
|
||||
selectedTourism={selectedTourism} // 传递选中的景区
|
||||
onClearSelection={handleClearSelection} // 传递清空选择的回调
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user