diff --git a/src/components/devices/DeviceOverviewPage.tsx b/src/components/devices/DeviceOverviewPage.tsx
index 08bf59d..b55fee0 100644
--- a/src/components/devices/DeviceOverviewPage.tsx
+++ b/src/components/devices/DeviceOverviewPage.tsx
@@ -16,9 +16,10 @@ import {
} from '@ant-design/icons';
import { useSelector } from 'react-redux';
-import { changeCameragateway, changeCameraPlane, getDeviceListApi, getLiveStream, getPlaneDeviceList } from '../../api/device.ts';
+import { getDeviceListApi, getPlaneDeviceList } from '../../api/device.ts';
import { RootState } from '@/src/store';
import DroneLivePlayer from '../VolcRtcPlayer.jsx';
+import DroneVideoPlayer from './DroneVideoPlayer';
import AgoraTextTest from '../AgoraRtc.tsx';
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
import VideoPlayer from '../VideoPlayer.tsx.tsx';
@@ -46,13 +47,9 @@ const logs = [
];
export default function DeviceOverviewPage({ devices, planedevices, devicesAll, onViewStatus, selectedSn, onDeviceSelect }) {
- const [planeVideo, setPlaneVideo] = useState(null);
const [zoomedVideo, setZoomedVideo] = useState(null);
const [mowerView, setMowerView] = useState('front');
- const [videoSource, setVideoSource] = useState('drone'); // station / drone
- const videoTypeRef = useRef('station');
- const [selectedCamera, setSelectedCamera] = useState('outdoor'); // 机场默认室外
- const [selectedLens, setSelectedLens] = useState('wide'); // 飞机默认广角
+ const [videoSource, setVideoSource] = useState('drone'); // 恢复 videoSource 状态管理
const selectedDevice = React.useMemo(() => {
const sn = selectedSn || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
@@ -103,72 +100,6 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
const handleRecharge = () => message.info('回充指令已下发');
const handleEmergencyStop = () => message.error('已触发急停!');
- // 加载机场摄像头
- const loadStationCamera = async (cameraPosition) => {
- console.log(cameraPosition, "cameraPosition")
- if (!selectedDevice?.gateway_sn) return;
- console.log(selectedDevice, "selectedDevice", cameraPosition)
- try {
- const cameraIndex = selectedDevice.gateway_camera_list?.find(
- item => item.camera_position == cameraPosition
- )?.camera_index || "";
- console.log(cameraIndex, "cameraIndex")
- if (!cameraIndex) {
- setPlaneVideo({});
- return
- }
- const res = await changeCameragateway({
- sn: selectedDevice.gateway_sn,
- cameraIndex,
- cameraPosition,
- qualityType: "adaptive",
- videoExpire: 7200,
- });
- if (res.code == 200) {
- setPlaneVideo(res.data);
- videoTypeRef.current = 'station';
- }
- } catch (err) {
- console.error('切换机场摄像头失败', err);
- }
- };
-
- // 加载无人机镜头
- const loadDroneLens = async (lensType) => {
- console.log(lensType, "lensType")
- if (!selectedDevice?.gateway_sn || !selectedDevice?.device_sn) return;
- const cameraIndex = selectedDevice.drone_camera_list[1].camera_index || "";
- console.log(cameraIndex, "cameraIndex")
- if (!cameraIndex) return;
- try {
- const res = await changeCameraPlane({
- sn: selectedDevice.device_sn,
- lensType,
- cameraIndex,
- qualityType: "adaptive",
- videoExpire: 7200,
- });
- if (res.code === 200) {
- setPlaneVideo(res.data);
- videoTypeRef.current = 'drone';
- }
- } catch (err) {
- console.error('切换无人机镜头失败', err);
- }
- };
-
- // 自动加载默认画面
- useEffect(() => {
- if (isUAV) {
- setPlaneVideo(null);
- if (videoSource === 'station') {
- loadStationCamera('outdoor');
- } else {
- loadDroneLens('wide');
- }
- }
- }, [selectedDevice, videoSource]);
-
const fix2 = (val) => {
if (val === null || val === undefined || isNaN(val)) return '-';
return Number(val).toFixed(2);
@@ -373,64 +304,14 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
{/* 视频容器 */}
-
- {/* 右上角摄像头切换按钮 */}
- {isUAV && (
-
- {videoSource === 'station' ? (
- <>
-
-
-
- >
- ) : (
- <>
-
-
-
-
-
- >
- )}
-
- )}
-
- {/* 视频内容 */}
{isUAV ? (
- planeVideo ? (
-
- ) : (
-
- 视频加载中...
-
- )
+
) : (
robotVideo ? (
)
)}
-
- {selectedDevice?.device_sn && (
-
- 高度 {fix2(selectedDevice.height)}m
- 风速 {fix2(selectedDevice.wind_speed)}m/s
-
- )}
diff --git a/src/components/devices/DeviceStatusPage.tsx b/src/components/devices/DeviceStatusPage.tsx
index 8213a67..7b8c56c 100644
--- a/src/components/devices/DeviceStatusPage.tsx
+++ b/src/components/devices/DeviceStatusPage.tsx
@@ -34,8 +34,7 @@ import {
} from '@ant-design/icons';
import XboxController from './XboxController';
-import DroneLivePlayer from '../VolcRtcPlayer.jsx';
-import { getLiveStream } from '../../api/device.ts';
+import DroneVideoPlayer from './DroneVideoPlayer';
import CesiumMap from '../Map.jsx';
import { useSelector } from 'react-redux';
import { RootState } from '@/src/store/index.ts';
@@ -59,7 +58,6 @@ export default function DeviceStatusPage({
const controllerRef = useRef(null);
- const [planeVideo, setPlaneVideo] = useState([]);
const [isControlled, setIsControlled] = useState(false);
const [hasControlRight, setHasControlRight] = useState(false);
const [connecting, setConnecting] = useState(false);
@@ -146,36 +144,6 @@ export default function DeviceStatusPage({
controllerRef.current.connectDevice(device);
}, [device]);
- useEffect(() => {
- if (!device?.gateway_sn) {
- setPlaneVideo([]);
- return;
- }
-
- const loadVideo = async () => {
- try {
- const data = {
- getway_sn: device.gateway_sn,
- drone_sn: device.device_sn,
- getway_camera_list: device.gateway_camera_list ?? [],
- drone_camera_list: device.drone_camera_list ?? [],
- video_expire: 7200,
- quality_type: 'adaptive',
- };
-
- const res = await getLiveStream(data);
-
- if (res.code === 200) {
- setPlaneVideo(res.data || []);
- }
- } catch (err) {
- console.error(err);
- }
- };
-
- loadVideo();
- }, [device]);
-
const mapDevices = useMemo(() => {
if (!device) return [];
@@ -328,24 +296,12 @@ export default function DeviceStatusPage({
}}
>
{isUAV ? (
- planeVideo.length > 0 ? (
- planeVideo.map((s, i) => (
-
-
-
- ))
- ) : (
-
- 暂无视频
-
- )
+
) : robotVideo ? (
// 全景模式 = 4 分屏
mowerView === 'all' ? (
diff --git a/src/components/devices/DroneVideoPlayer.tsx b/src/components/devices/DroneVideoPlayer.tsx
new file mode 100644
index 0000000..e37b559
--- /dev/null
+++ b/src/components/devices/DroneVideoPlayer.tsx
@@ -0,0 +1,305 @@
+import React, { useState, useEffect, useRef } from 'react';
+import { Button, Select, Space, Typography } from 'antd';
+import { ReloadOutlined } from '@ant-design/icons';
+import DroneLivePlayer from '../VolcRtcPlayer.jsx';
+import { changeCameragateway, changeCameraPlane } from '../../api/device.ts';
+import utils from '../../lib/utils';
+
+const { Text } = Typography;
+
+interface DroneVideoPlayerProps {
+ device: any;
+ height?: number | string;
+ showSourceSelect?: boolean;
+ defaultSource?: 'station' | 'drone';
+ videoSource?: 'station' | 'drone'; // 新增:支持受控模式
+ onSourceChange?: (source: 'station' | 'drone') => void; // 新增:支持受控模式
+}
+
+const DroneVideoPlayer: React.FC = ({
+ device,
+ height = 160,
+ showSourceSelect = true,
+ defaultSource = 'drone',
+ videoSource: propsVideoSource,
+ onSourceChange
+}) => {
+ const [internalVideoSource, setInternalVideoSource] = useState<'station' | 'drone'>(defaultSource);
+
+ // 如果提供了 propsVideoSource,则使用受控值,否则使用内部状态
+ const videoSource = propsVideoSource !== undefined ? propsVideoSource : internalVideoSource;
+ const setVideoSource = (source: 'station' | 'drone') => {
+ if (onSourceChange) {
+ onSourceChange(source);
+ } else {
+ setInternalVideoSource(source);
+ }
+ };
+ const [selectedCamera, setSelectedCamera] = useState<'indoor' | 'outdoor'>('outdoor');
+ const [selectedLens, setSelectedLens] = useState<'wide' | 'zoom' | 'ir'>('wide');
+ const [streamData, setStreamData] = useState(null);
+ const [loading, setLoading] = useState(false);
+
+ // 防抖锁:防止重复点击(核心优化)
+ const switchingLock = useRef(false);
+
+ // 加载机场摄像头
+ const loadStationCamera = async (cameraPosition: 'indoor' | 'outdoor') => {
+ setSelectedCamera(cameraPosition);
+
+ if (!device?.gateway_sn || switchingLock.current) return;
+ switchingLock.current = true;
+ setLoading(true);
+ try {
+ const cameraIndex = device.gateway_camera_list?.find(
+ (item: any) => item.camera_position === cameraPosition
+ )?.camera_index || "";
+
+ if (!cameraIndex) {
+ setStreamData(null);
+ utils.message.warning(`未找到${cameraPosition === 'indoor' ? '室内' : '室外'}摄像头配置`);
+ return;
+ }
+
+ const res = await changeCameragateway({
+ sn: device.gateway_sn,
+ cameraIndex,
+ cameraPosition,
+ qualityType: "adaptive",
+ videoExpire: 7200,
+ });
+
+ if (res.code === 200) {
+ setStreamData(res.data);
+ } else {
+ utils.message.error(res.msg || '切换机场摄像头失败');
+ }
+ } catch (err) {
+ console.error('切换机场摄像头失败', err);
+ } finally {
+ setLoading(false);
+ switchingLock.current = false;
+ }
+ };
+
+ // 加载无人机镜头(优化版)
+ const loadDroneLens = async (lensType: 'wide' | 'zoom' | 'ir') => {
+ setSelectedLens(lensType);
+
+ if (!device?.device_sn || switchingLock.current) return;
+
+ // 如果已经是当前镜头,不重复请求(超级重要!)
+ if (selectedLens === lensType && streamData) {
+ return;
+ }
+
+ switchingLock.current = true;
+ setLoading(true);
+
+ try {
+ const cameraIndex = device.drone_camera_list?.[1]?.camera_index ||
+ device.drone_camera_list?.[0]?.camera_index || "";
+
+ if (!cameraIndex) {
+ utils.message.warning('未找到无人机相机配置');
+ return;
+ }
+
+ const res = await changeCameraPlane({
+ sn: device.device_sn,
+ lensType,
+ cameraIndex,
+ qualityType: "adaptive",
+ videoExpire: 7200,
+ });
+
+ if (res.code === 200) {
+ setStreamData(res.data);
+ } else {
+ utils.message.error(res.msg || '切换无人机镜头失败');
+ }
+ } catch (err) {
+ console.error('切换无人机镜头失败', err);
+ } finally {
+ setLoading(false);
+ switchingLock.current = false;
+ }
+ };
+
+ // 自动加载默认画面
+ useEffect(() => {
+ if (device) {
+ setStreamData(null);
+ if (videoSource === 'station') {
+ loadStationCamera(selectedCamera);
+ } else {
+ loadDroneLens(selectedLens);
+ }
+ }
+ }, [device, videoSource]);
+
+ return (
+
+ {showSourceSelect && (
+
+
+ )}
+
+
+ {/* 切换按钮覆盖层 */}
+
+ {videoSource === 'station' ? (
+ <>
+
+
+ >
+ ) : (
+ <>
+
+
+
+ >
+ )}
+
+
+ {/* 视频内容 */}
+ {streamData ? (
+
+ ) : (
+
+ {loading ? : null}
+ {loading ? '视频加载中...' : '暂无视频信号'}
+
+ )}
+
+ {/* 底部信息叠加 */}
+ {videoSource === 'drone' && device && (
+
+ 高度 {device.height?.toFixed(2) || '-'}m
+ 风速 {device.wind_speed?.toFixed(2) || '-'}m/s
+
+ )}
+
+
+ );
+};
+
+export default DroneVideoPlayer;