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: () =>