From 9dbfe7d7c4778c5c5be5a18b0c11608cdd5a91d3 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 22 May 2026 15:53:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=A7=86=E9=A2=91=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/VolcRtcPlayer.jsx | 6 +- src/components/devices/DeviceOverviewPage.tsx | 376 +++++------------- 2 files changed, 96 insertions(+), 286 deletions(-) diff --git a/src/components/VolcRtcPlayer.jsx b/src/components/VolcRtcPlayer.jsx index 235cd85..c135307 100644 --- a/src/components/VolcRtcPlayer.jsx +++ b/src/components/VolcRtcPlayer.jsx @@ -35,7 +35,7 @@ export default function DroneLivePlayer({ // ---------------- 解析 RTC 参数 ---------------- - const params = new URLSearchParams(streamData.url); + const params = new URLSearchParams(streamData?.url); const appId = ( params.get("app_id") || @@ -69,8 +69,8 @@ export default function DroneLivePlayer({ const liveheartbeat = async () => { try { await postLiveHeartbeat({ - sn: streamData.sn, - cameraIndex: streamData.camera_index, + sn: streamData?.sn, + cameraIndex: streamData?.camera_index, }); } catch (err) { console.error("心跳失败", err); diff --git a/src/components/devices/DeviceOverviewPage.tsx b/src/components/devices/DeviceOverviewPage.tsx index 407b25f..923b0f4 100644 --- a/src/components/devices/DeviceOverviewPage.tsx +++ b/src/components/devices/DeviceOverviewPage.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { Layout, Card, Row, Col, Statistic, Tag, Button, Table, Typography, Space, Progress, Badge, Timeline, message, @@ -16,7 +16,7 @@ import { } from '@ant-design/icons'; import { useSelector } from 'react-redux'; -import { getDeviceListApi, getLiveStream, getPlaneDeviceList } from '../../api/device.ts'; +import { changeCameragateway, getDeviceListApi, getLiveStream, getPlaneDeviceList } from '../../api/device.ts'; import { RootState } from '@/src/store'; import DroneLivePlayer from '../VolcRtcPlayer.jsx'; import AgoraTextTest from '../AgoraRtc.tsx'; @@ -27,9 +27,6 @@ import CesiumMap from '../Map.jsx'; const { Content } = Layout; const { Text, Title } = Typography; - - - const taskTimeline = [ { time: '10:24:18', color: 'blue', text: 'UAV-C01 开始执行清洗航线 C-05', status: '任务开始' }, { time: '10:21:35', color: 'orange', text: 'RBT-01 开始执行巡检航线 P-02', status: '任务开始' }, @@ -48,70 +45,41 @@ const logs = [ { time: '10:05:22', device: 'RBT-01', type: '事件', desc: '电量较低,建议回充', level: '低电量' }, ]; -// 设备总览组件 export default function DeviceOverviewPage({ devices, planedevices, devicesAll, onViewStatus, selectedSn, onDeviceSelect }) { - const [planeVideo, setPlaneVideo] = useState([]); // 初始为空数组 - const [zoomedVideo, setZoomedVideo] = useState(null); // 放大查看的视频数据 + const [planeVideo, setPlaneVideo] = useState([]); + const [zoomedVideo, setZoomedVideo] = useState(null); + const [mowerView, setMowerView] = useState('front'); + const videoTypeRef = useRef('drone'); // drone → 无人机镜头 station → 机场镜头 - // 衍生状态:从 SN 获取设备对象 const selectedDevice = React.useMemo(() => { const sn = selectedSn || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber); return devicesAll?.find(item => (item.device_sn || item.serialNumber) === sn) || null; }, [devicesAll, selectedSn]); - // 动态计算顶部卡片数据 + const isUAV = !!selectedDevice?.gateway_sn; + + const { video: robotVideo, error, ready } = useWebRTCPlayer( + selectedDevice?.serialNumber || '', + `webrtc://1.95.137.212/live/livestream/${selectedDevice?.serialNumber}`, + ); + const dynamicTopCards = React.useMemo(() => { const totalDrones = planedevices?.length || 0; const onlineDrones = planedevices?.filter(d => d.onlineStatus === 1).length || 0; - const totalRobots = devicesAll?.filter(d => d.productName?.includes('巡检')).length || 0; const activeRobots = devicesAll?.filter(d => d.productName?.includes('巡检') && d.onlineStatus === 1).length || 0; - const totalMowers = devicesAll?.filter(d => d.productName?.includes('割草机')).length || 0; const activeMowers = devicesAll?.filter(d => d.productName?.includes('割草机') && d.onlineStatus === 1).length || 0; - const washDroneStandby = planedevices?.filter(d => d.productName?.includes('清洗') && d.onlineStatus === 1).length || 0; - return [ - { - title: '无人机机场状态', - icon: , - value: `${onlineDrones} / ${totalDrones}`, - sub: `可调度 ${onlineDrones} 架`, - color: '#1890ff' - }, - { - title: '机器人', - icon: , - value: `${totalMowers} 台`, - sub: `作业中 ${activeMowers}`, - color: '#13c2c2' - }, - { - title: '无人机', - icon: , - value: `${totalDrones} 架`, - sub: `待命 ${washDroneStandby}`, - color: '#eb2f96' - }, - { - title: '设备平均电量', - icon: , - value: '86%', - sub: '', - color: '#52c41a' - }, - { - title: '今日任务执行', - icon: , - value: '12 / 15', - sub: '完成率 80%', - color: '#2f54eb' - }, + { title: '无人机机场状态', icon: , value: `${onlineDrones} / ${totalDrones}`, sub: `可调度 ${onlineDrones} 架`, color: '#1890ff' }, + { title: '机器人', icon: , value: `${totalMowers} 台`, sub: `作业中 ${activeMowers}`, color: '#13c2c2' }, + { title: '无人机', icon: , value: `${totalDrones} 架`, sub: `待命 ${washDroneStandby}`, color: '#eb2f96' }, + { title: '设备平均电量', icon: , value: '86%', sub: '', color: '#52c41a' }, + { title: '今日任务执行', icon: , value: '12 / 15', sub: '完成率 80%', color: '#2f54eb' }, ]; }, [devicesAll, planedevices]); - // 动态生成调度列表 const dynamicScheduleList = React.useMemo(() => { return devicesAll.map((d, index) => ({ id: d.deviceId || index, @@ -126,105 +94,73 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, })); }, [devicesAll]); - const [mowerView, setMowerView] = useState('front'); - const isUAV = !!selectedDevice?.device_sn; - - // 机器人 WebRTC 视频(和你第二个页面逻辑一致) - const { video: robotVideo, error, ready } = useWebRTCPlayer( - selectedDevice?.serialNumber || '', - `webrtc://1.95.137.212/live/livestream/${selectedDevice?.serialNumber}`, - ); - - const handleStart = () => message.success('任务已启动'); const handlePause = () => message.info('任务已暂停'); const handleReturn = () => message.info('返航指令已下发'); const handleRecharge = () => message.info('回充指令已下发'); const handleEmergencyStop = () => message.error('已触发急停!'); - const getLiveDefault = () => { + + // ====================== ✅ 核心:无人机视频获取逻辑(优先无人机 → 无则机场) ====================== + const getDroneLiveStream = async () => { if (!selectedDevice?.gateway_sn) return; - const data = { - getway_sn: selectedDevice?.gateway_sn, - drone_sn: selectedDevice?.device_sn, - getway_camera_list: selectedDevice?.gateway_camera_list ?? [], - drone_camera_list: selectedDevice?.drone_camera_list ?? [], - video_expire: 7200, - quality_type: "adaptive", - } - getLiveStream(data).then(res => { - if (res.code == 200) { - setPlaneVideo(res.data); + console.log(selectedDevice, "selectedDevice") + try { + if (selectedDevice.gateway_camera_list && selectedDevice.gateway_camera_list.length > 0) { + const droneData = { + sn: selectedDevice.gateway_sn, + cameraIndex: selectedDevice.gateway_camera_list.filter(item => item.camera_position + == "indoor")[0]?.camera_index || "", + + cameraPosition: "indoor", + qualityType: "adaptive", + videoExpire: 7200, + }; + changeCameragateway(droneData).then(res => { + if (res.code == 200) { + setPlaneVideo(res.data) + } + }) } - }) - } + + setPlaneVideo({}); + } catch (err) { + console.error('视频拉流失败', err); + setPlaneVideo({}); + } + }; - - // 数字保留两位小数 const fix2 = (val) => { if (val === null || val === undefined || isNaN(val)) return '-'; return Number(val).toFixed(2); }; - // 安全取值 const getVal = (val) => val == "no_rain" ? "无" : (val || '-'); - // 默认选中第一个 useEffect(() => { - getLiveDefault(); - }, [selectedDevice]) - - // 切换设备 - const handleDeviceChange = (id) => { - if (onDeviceSelect) { - onDeviceSelect(id); + if (isUAV) { + setPlaneVideo({}); + getDroneLiveStream(); } + }, [selectedDevice]); + + const handleDeviceChange = (id) => { + if (onDeviceSelect) onDeviceSelect(id); }; return ( - {/**/} {dynamicTopCards.map((card, idx) => ( - + - {/* 左侧图标 */} - + {card.icon} - - {/* 右侧文字 */} {card.title} - - {card.value} - - {card.sub && ( - - {card.sub} - - )} + {card.value} + {card.sub && {card.sub}} @@ -244,7 +180,6 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, ——— 清洗路径 🚗 机器位置 ✈️ 无人机位置 - ● 补给/充电点 ■ 障碍/禁入区 @@ -264,7 +199,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, { title: '位置', dataIndex: 'position', width: 90 }, { title: '当前任务', dataIndex: 'task', width: 100 }, { title: '通讯状态', dataIndex: 'comm', width: 70, render: v => }, - { title: '操作', key: 'action', width: 80, render: () => } />} /> } + { title: '操作', key: 'action', width: 80, render: () => } />} /> }, ]} dataSource={dynamicScheduleList} scroll={{ x: 'max-content', y: 280 }} @@ -286,46 +221,21 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, - 设备控制面板>} - bordered={false} - style={{ borderRadius: 8, marginBottom: 8 }} - bodyStyle={{ padding: 12, paddingBottom: 0 }} - > + 设备控制面板>} bordered={false} style={{ borderRadius: 8, marginBottom: 8 }} bodyStyle={{ padding: 12, paddingBottom: 0 }}> - option.label.toLowerCase().includes(input.toLowerCase()) - } + showSearch + allowClear + optionFilterProp="label" + filterOption={(input, option) => option.label.toLowerCase().includes(input.toLowerCase())} options={[ - { - label: 机器人, - title: 'manager', - options: devices.map(item => ({ - value: item.device_sn || item.serialNumber, - label: item.deviceAlias || item.deviceName || '未知设备' - })), - }, - { - label: 无人机, - title: 'engineer', - options: planedevices.map(item => ({ - value: item.device_sn, - label: item.drone_callsign || item.callsign || '未知设备' - })), - }, + { label: 机器人, options: devices.map(item => ({ value: item.device_sn || item.serialNumber, label: item.deviceAlias || item.deviceName || '未知设备' })) }, + { label: 无人机, options: planedevices.map(item => ({ value: item.device_sn, label: item.drone_callsign || item.callsign || '未知设备' })) }, ]} - //options={devicesAll.map(item => ({ - // value: item.device_sn || item.serialNumber, - // label: item.deviceAlias || item.drone_callsign || item.callsign || item.deviceName || '未知设备' - //}))} /> {selectedDevice && ( @@ -333,29 +243,20 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, - {selectedDevice.deviceType === 'drone' || - selectedDevice.deviceName?.includes('无人机') || - selectedDevice.drone_callsign ? ( + {selectedDevice.deviceType === 'drone' || selectedDevice.deviceName?.includes('无人机') || selectedDevice.drone_callsign ? ( ) : ( )} - {selectedDevice.deviceAlias || selectedDevice.drone_callsign || selectedDevice.callsign || selectedDevice.deviceName} {selectedDevice.onlineStatus == 1 ? "在线" : "离线"} } + type="primary" size="small" ghost icon={} style={{ borderRadius: 4, fontSize: 11, marginLeft: 'auto' }} onClick={() => onViewStatus && onViewStatus(selectedDevice.device_sn || selectedDevice.serialNumber)} - > - 详情 - + >详情 @@ -369,30 +270,18 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, {fix2(selectedDevice.environment_temperature || 25)}℃ )} - {selectedDevice.productName && ( - <> - - 产品类型 - {getVal(selectedDevice.productName)} - - > + + 产品类型 + {getVal(selectedDevice.productName)} + )} - 设备SN - + {getVal(selectedDevice.device_sn || selectedDevice.serialNumber)} @@ -408,7 +297,6 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, v{selectedDevice.firmwareVersion} )} - {/* 无人机特定信息 */} {(selectedDevice.productName?.includes('无人机') || selectedDevice.device_sn) && ( <> @@ -421,7 +309,6 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, > )} - @@ -434,48 +321,36 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, - {/* 实时画面 */} 实时画面 - {/* 角度选择下拉框 */} {!isUAV && ( - )} + {/* 显示当前镜头类型 */} + {isUAV && ( + + {videoTypeRef.current === 'drone' ? '无人机镜头' : '机场镜头'} + + )} - {/* 无人机视频 */} {isUAV ? ( - planeVideo?.length > 0 ? ( - + planeVideo ? ( + ) : ( - 暂无视频流 + 视频加载中... ) ) : ( - // 机器人单画面 + 角度切换 robotVideo ? ( 高度 {fix2(selectedDevice.height)}m @@ -507,6 +381,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, )} + {/* 下面的卡片逻辑保持不变 */} AI分析与操作建议>} bordered={false} style={{ borderRadius: 12, marginBottom: 16 }}> 🔥热斑疑似2 处 @@ -537,7 +412,6 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, - {/* 条件渲染:只有无人机显示环境与飞行条件 */} {(selectedDevice?.productName?.includes('无人机') || selectedDevice?.device_sn) && ( @@ -551,84 +425,29 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, 适宜执行 - - - - 可正常作业 )} - {/* 条件渲染:机器人显示其余信息(此处以任务详情为例) */} {(!selectedDevice?.productName?.includes('无人机') && !selectedDevice?.device_sn) && ( - - - 机器人作业状态 - - } - bordered={false} - style={{ - borderRadius: 12, - marginBottom: 16, - boxShadow: '0 2px 8px rgba(0,0,0,0.06)', - border: '1px solid #f0f0f0', - }} - > + 机器人作业状态} bordered={false} style={{ borderRadius: 12, marginBottom: 16, boxShadow: '0 2px 8px rgba(0,0,0,0.06)', border: '1px solid #f0f0f0' }}> - - 累计里程} - value={128.5} - suffix="km" - valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} - /> + + 累计里程} value={128.5} suffix="km" valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} /> - - 本次作业耗时} - value={45} - suffix="min" - valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} - /> + + 本次作业耗时} value={45} suffix="min" valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} /> - - 预计剩余时间} - value={12} - suffix="min" - valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} - /> + + 预计剩余时间} value={12} suffix="min" valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} /> @@ -649,16 +468,7 @@ export default function DeviceOverviewPage({ devices, planedevices, devicesAll, - setZoomedVideo(null)} - footer={null} - width={1000} - centered - bodyStyle={{ padding: 0, height: 600, background: '#000' }} - destroyOnClose - > + setZoomedVideo(null)} footer={null} width={1000} centered bodyStyle={{ padding: 0, height: 600, background: '#000' }} destroyOnClose> {zoomedVideo && }