无人机摄像头封装成功
This commit is contained in:
@@ -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,
|
||||
|
||||
{/* 视频容器 */}
|
||||
<div style={{ width: '100%', height: 160, borderRadius: 8, position: 'relative', overflow: 'hidden', background: '#000' }}>
|
||||
|
||||
{/* 右上角摄像头切换按钮 */}
|
||||
{isUAV && (
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
top: '6px',
|
||||
right: '6px',
|
||||
display: 'flex',
|
||||
gap: '4px',
|
||||
zIndex: 10,
|
||||
}}>
|
||||
{videoSource === 'station' ? (
|
||||
<>
|
||||
<Button size="small" type="text" style={{
|
||||
background: 'rgba(0,0,0,0.4)', color: '#fff', fontSize: '12px', padding: '0 2px', height: '22px',
|
||||
borderRadius: '4px',
|
||||
...(selectedCamera === 'indoor' && { background: '#1890ff', color: '#fff' })
|
||||
}} onClick={() => { setSelectedCamera('indoor'); loadStationCamera('indoor'); }}>室内</Button>
|
||||
|
||||
<Button size="small" type="text" style={{
|
||||
background: 'rgba(0,0,0,0.4)', color: '#fff', fontSize: '12px', padding: '0 6px', height: '22px',
|
||||
borderRadius: '4px',
|
||||
...(selectedCamera === 'outdoor' && { background: '#1890ff', color: '#fff' })
|
||||
}} onClick={() => { setSelectedCamera('outdoor'); loadStationCamera('outdoor'); }}>室外</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Button size="small" type="text" style={{
|
||||
background: 'rgba(0,0,0,0.4)', color: '#fff', fontSize: '12px', padding: '0 6px', height: '22px',
|
||||
borderRadius: '4px',
|
||||
...(selectedLens === 'wide' && { background: '#1890ff', color: '#fff' })
|
||||
}} onClick={() => { setSelectedLens('wide'); loadDroneLens('wide'); }}>广角</Button>
|
||||
|
||||
<Button size="small" type="text" style={{
|
||||
background: 'rgba(0,0,0,0.4)', color: '#fff', fontSize: '12px', padding: '0 6px', height: '22px',
|
||||
borderRadius: '4px',
|
||||
...(selectedLens === 'zoom' && { background: '#1890ff', color: '#fff' })
|
||||
}} onClick={() => { setSelectedLens('zoom'); loadDroneLens('zoom'); }}>变焦</Button>
|
||||
|
||||
<Button size="small" type="text" style={{
|
||||
background: 'rgba(0,0,0,0.4)', color: '#fff', fontSize: '12px', padding: '0 6px', height: '22px',
|
||||
borderRadius: '4px',
|
||||
...(selectedLens === 'ir' && { background: '#1890ff', color: '#fff' })
|
||||
}} onClick={() => { setSelectedLens('ir'); loadDroneLens('ir'); }}>红外</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 视频内容 */}
|
||||
{isUAV ? (
|
||||
planeVideo ? (
|
||||
<DroneLivePlayer streamData={planeVideo} />
|
||||
) : (
|
||||
<div style={{ color: '#ccc', display: 'flex', height: '100%', alignItems: 'center', justifyContent: 'center' }}>
|
||||
<ReloadOutlined spin style={{ marginRight: 6 }} /> 视频加载中...
|
||||
</div>
|
||||
)
|
||||
<DroneVideoPlayer
|
||||
device={selectedDevice}
|
||||
height={160}
|
||||
showSourceSelect={false}
|
||||
videoSource={videoSource}
|
||||
onSourceChange={setVideoSource}
|
||||
/>
|
||||
) : (
|
||||
robotVideo ? (
|
||||
<VideoPlayer
|
||||
@@ -447,13 +328,6 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll,
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
|
||||
{selectedDevice?.device_sn && (
|
||||
<div style={{ position: 'absolute', bottom: 0, left: 0, right: 0, background: 'rgba(0,0,0,0.6)', color: '#fff', display: 'flex', justifyContent: 'space-between', padding: '8px 12px', fontSize: 12 }}>
|
||||
<span>高度 {fix2(selectedDevice.height)}m</span>
|
||||
<span>风速 {fix2(selectedDevice.wind_speed)}m/s</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user