无人机组件 终于可以显示两个视频了!!!!

This commit is contained in:
mmc
2026-05-28 15:17:00 +08:00
parent 834f93b947
commit 1ca393472d
9 changed files with 317 additions and 353 deletions

View File

@@ -19,8 +19,7 @@ interface DroneVideoPlayerProps {
const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
device,
wind_speed,
h,
height = 160,
showSourceSelect = true,
dualVideo = false,
@@ -118,26 +117,57 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
const switchDroneCamera = (idx: number) => {
setSelectedDroneCameraIdx(idx);
};
// 用来记住上一次的值,判断哪一路发生了变化
const prevRef = useRef({
selectedCamera: '',
selectedLens: '',
});
// 自动加载
useEffect(() => {
if (device) {
if (dualVideo) {
setDroneStreamData(null);
if (!device?.device_sn && !device?.gateway_sn) return;
const prev = prevRef.current;
const currentCamera = selectedCamera;
const currentLens = selectedLens;
// 双画面:只刷新【真正变化】的那一路,另一路不动
if (dualVideo) {
// 只有【机场摄像头】变化了,才刷新机场
if (currentCamera !== prev.selectedCamera) {
setStationStreamData(null);
loadStationCamera(selectedCamera);
loadDroneLens(selectedLens);
} else {
if (videoSource === 'station') {
setStationStreamData(null);
loadStationCamera(selectedCamera);
} else {
setDroneStreamData(null);
loadDroneLens(selectedLens);
}
loadStationCamera(currentCamera);
}
// 只有【无人机镜头】变化了,才刷新无人机
if (currentLens !== prev.selectedLens) {
setDroneStreamData(null);
loadDroneLens(currentLens);
}
// 保存最新值,供下一次对比
prevRef.current = {
selectedCamera: currentCamera,
selectedLens: currentLens,
};
return;
}
}, [device, videoSource, selectedDroneCameraIdx, dualVideo]);
// 单画面:保持原有逻辑
if (videoSource === 'station') {
setStationStreamData(null);
loadStationCamera(currentCamera);
} else {
setDroneStreamData(null);
loadDroneLens(currentLens);
}
}, [
device,
videoSource,
selectedDroneCameraIdx,
dualVideo,
selectedCamera,
selectedLens,
]);
// 生成摄像头下拉选项
const droneCameraOptions = device?.drone_camera_list?.map((item: any, idx: number) => ({
@@ -157,7 +187,7 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
background: '#000',
border: dualVideo ? '1px solid #243157' : 'none',
minWidth: dualVideo ? '300px' : 'auto' // 确保在双视频模式下有最小宽度
}}>
}} key={type}>
{/* 视频控制按钮 */}
<div style={{
position: 'absolute',
@@ -214,7 +244,8 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
{/* 视频内容 */}
{streamData ? (
<DroneLivePlayer streamData={streamData} />
<DroneLivePlayer streamData={streamData}
/>
) : (
<div style={{
color: '#ccc',
@@ -263,8 +294,8 @@ const DroneVideoPlayer: React.FC<DroneVideoPlayerProps> = ({
padding: '4px 8px',
fontSize: 10
}}>
<span>高度 {h?.toFixed(2) || device?.height?.toFixed(2) || '-'}m</span>
<span>风速 {wind_speed?.toFixed(2) || device?.wind_speed?.toFixed(2) || '0'}m/s</span>
<span>高度 {Number(device?.height)?.toFixed(2) || '-'}m</span>
<span>风速 {Number(device?.wind_speed?.toFixed(2) || '0')}m/s</span>
</div>
)}
</div>