From 75ed862801e37b68e65f0d9e0c0d13a035dfdac2 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Tue, 17 Nov 2026 16:54:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A3=B0=E7=BD=91=E8=A7=86=E9=A2=91=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=AE=8C=E6=88=90=20=20=20=E6=80=BB=E8=A7=88=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=92=8C=20=20=E4=BB=BB=E5=8A=A1=E8=A7=84=E5=88=92?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=20=E9=83=BD=E6=98=BE=E7=A4=BA=20=E4=BA=86=20?= =?UTF-8?q?=20=20=E6=A0=B9=E6=8D=AE=E6=9C=BA=E5=99=A8=E9=85=8D=E5=A4=87?= =?UTF-8?q?=E7=9A=84=E5=87=A0=E8=B7=AF=E8=A7=86=E9=A2=91=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AgrtcRoomRobot.tsx | 543 +++++++++++--------- src/components/devices/DeviceStatusPage.tsx | 201 ++++---- src/components/devices/TaskPlanningView.tsx | 37 +- src/index.css | 4 + src/locales/en/index.ts | 1 + src/locales/zh/index.ts | 1 + 6 files changed, 436 insertions(+), 351 deletions(-) diff --git a/src/components/AgrtcRoomRobot.tsx b/src/components/AgrtcRoomRobot.tsx index ca7cfd3..c2bd4fc 100644 --- a/src/components/AgrtcRoomRobot.tsx +++ b/src/components/AgrtcRoomRobot.tsx @@ -1,281 +1,346 @@ -import React, { useEffect, useRef, useState } from "react"; -import AgoraRTC, { IAgoraRTCClient, IRemoteVideoTrack } from "agora-rtc-sdk-ng"; -import { Badge, message } from "antd"; +import React, { useEffect, useMemo, useRef, useState } from 'react'; +import AgoraRTC, { IAgoraRTCClient, IRemoteVideoTrack } from 'agora-rtc-sdk-ng'; +import { Badge, message } from 'antd'; -AgoraRTC.setLogLevel(2); // 2=只输出warning/error,屏蔽debug日志 +// 日志等级:2=仅 warning/error,屏蔽 debug 噪点 +AgoraRTC.setLogLevel(2); -const APP_ID = "5afc6f096ddf433aa690df6f251274a4"; -const TOKEN = "007eJxTYHj/XqzNYP1utbUqvUkLly0/ypRz8liNgdKBqBeqqzX3+WgqMJgmpiWbpRlYmqWkpJkYGycmmlkapKSZpRmZGhqZmySaRH37ndUQyMjgu3k5KyMDBIL47AzJiblGuobmDAwA6vwg4g=="; +const APP_ID = '5afc6f096ddf433aa690df6f251274a4'; +const TOKEN = + '007eJxTYHj/XqzNYP1utbUqvUkLly0/ypRz8liNgdKBqBeqqzX3+WgqMJgmpiWbpRlYmqWkpJkYGycmmlkapKSZpRmZGhqZmySaRH37ndUQyMjgu3k5KyMDBIL47AzJiblGuobmDAwA6vwg4g=='; -export default function AgrtcRoomRobot({ CHANNEL }: { CHANNEL: string }) { - const [uid] = useState(() => Number(Math.floor(Math.random() * 100000))); +/** + * 每路摄像头在 Agora 频道内用固定 UID 区分: + * 101 = cam0 (GMSL A) = 前视 + * 102 = cam1 (GMSL B) = 左视 + * 103 = cam2 (GMSL C) = 后视 + * 104 = cam3 (GMSL D) = 右视 + */ +/** 按摄像头路数选默认 UID:2 路时优先前+后 */ +export const DEFAULT_UIDS_BY_COUNT: Record = { + 1: [101], + 2: [101, 103], + 3: [101, 102, 103], + 4: [101, 102, 103, 104], +}; +export const DEFAULT_CAMERA_UIDS = [101, 102, 103, 104]; +export const CAMERA_UID_LABEL: Record = { + 101: '前视', + 102: '左视', + + 103: '后视', + 104: '右视', +}; + +interface AgrtcRoomRobotProps { + /** 机器人 SN → 一个 Agora 频道 */ + channel?: string; + /** 向后兼容:channel 的别名 */ + CHANNEL?: string; + /** 当前机器人有几路摄像头(从 deviceRunParamSelectByDeviceId 的 cameraNum 字段取),1-4 */ + cameraCount?: number; + /** + * 显式指定本次只订阅哪些 UID(单路视图模式:front/back/left/right 各传一个 UID;all/grid 不传则按 cameraCount 取前 N 个默认 UID) + * 留空时取 DEFAULT_CAMERA_UIDS.slice(0, cameraCount) + */ + slotUids?: number[]; +} + +interface SlotRuntime { + uid: number; + containerRef: React.RefObject; + track: IRemoteVideoTrack | null; + subscribedUid: number | null; + hasVideo: boolean; + unpublishTimer: NodeJS.Timeout | null; +} + +export default function AgrtcRoomRobot(props: AgrtcRoomRobotProps) { + const channel = "cam2-17" || props.channel || props.CHANNEL || ''; + const cameraCount = Math.max(1, Math.min(4, Number(props.cameraCount) || 1)); + + // 订阅 UID 列表:外部显式 slotUids > 默认按 cameraCount 截断 + const slotUids = useMemo(() => { + if (Array.isArray(props.slotUids) && props.slotUids.length > 0) { + return props.slotUids.filter((n) => Number.isFinite(n) && n >= 1); + } + return DEFAULT_UIDS_BY_COUNT[cameraCount] || [101]; + }, [props.slotUids, cameraCount]); + + const [mountKey, setMountKey] = useState(0); const [connected, setConnected] = useState(false); const [joined, setJoined] = useState(false); - const [hasRemoteVideo, setHasRemoteVideo] = useState(false); - - const remoteVideoRef = useRef(null); - const clientRef = useRef(null); - const remoteVideoTrackRef = useRef(null); - const joiningRef = useRef(false); - const reconnectTimerRef = useRef(null); - const subscribedUidRef = useRef(null); useEffect(() => { - const client = AgoraRTC.createClient({ - mode: "live", - codec: "h264", - }); - clientRef.current = client; - client.setClientRole("audience"); - // ========= 删掉了 setParameters,Web NG不支持!======== + setMountKey((k) => k + 1); + }, [channel, slotUids.join(',')]); - let isUnmounted = false; - let videoWatchDogTimer: NodeJS.Timeout | null = null; - let unpublishTimer: NodeJS.Timeout | null = null; + if (!channel) { + return ( +
+ 无可订阅频道 +
+ ); + } - const clearRemoteVideo = () => { - if (remoteVideoTrackRef.current) { + return ( + + {(renderProps) => { + const gridStyle = pickGridStyle(slotUids.length); + return ( +
+
+ + + + 共 {slotUids.length} 路 +
+
+
+ {slotUids.map((uid) => { + const slot = renderProps.slotsByUid.get(uid); + const hasVideo = slot?.hasVideo || false; + const label = CAMERA_UID_LABEL[uid] || `UID ${uid}`; + return ( +
+
+ {label} +
+
+ {!hasVideo && ( +
+ 等待推流 (UID {uid})… +
+ )} +
+ ); + })} +
+
+
+ ); + }} + + ); +} + +function pickGridStyle(count: number): React.CSSProperties { + if (count <= 1) return { display: 'grid', gridTemplateColumns: '1fr', gridTemplateRows: '1fr', gap: 4 }; + if (count === 2) return { display: 'grid', gridTemplateColumns: '1fr', gridTemplateRows: '1fr 1fr', gap: 4 }; + return { display: 'grid', gridTemplateColumns: '1fr 1fr', gridTemplateRows: '1fr 1fr', gap: 4 }; +} + +interface AgrtcSingleChannelProps { + channel: string; + slotUids: number[]; + onConnect: (c: boolean) => void; + onJoin: (j: boolean) => void; + children: (renderProps: { slotsByUid: Map }) => React.ReactNode; +} + +function AgrtcSingleChannel({ channel, slotUids, onConnect, onJoin, children }: AgrtcSingleChannelProps) { + // 用 Map 做按 UID 索引的 slot,避免 React 重建循环引用 + const slotsRef = useRef>(new Map()); + const [, forceTick] = useState(0); + + useEffect(() => { + const slotsByUid = new Map(); + const containerKeyByUid = new Map>(); + for (const uid of slotUids) { + containerKeyByUid.set(uid, React.createRef()); + slotsByUid.set(uid, { + uid, + containerRef: containerKeyByUid.get(uid)!, + track: null, + subscribedUid: null, + hasVideo: false, + unpublishTimer: null, + }); + } + slotsRef.current = slotsByUid; + forceTick((v) => v + 1); + + const client: IAgoraRTCClient = AgoraRTC.createClient({ mode: 'live', codec: 'h264' }); + console.log('[AGRTC] init channel=' + channel + ', slotUids=' + JSON.stringify(slotUids)); + client.setClientRole('audience'); + + const localUid = Number(Math.floor(Math.random() * 100000) + 1); + let unmounted = false; + + const clearSlotTrack = (uid: number) => { + const slot = slotsRef.current.get(uid); + if (!slot) return; + if (slot.track) { try { - remoteVideoTrackRef.current.stop(); - } catch (e) { - console.warn("stop track error", e); - } - remoteVideoTrackRef.current = null; + slot.track.stop(); + } catch { } + slot.track = null; } - subscribedUidRef.current = null; - setHasRemoteVideo(false); - if (videoWatchDogTimer) clearInterval(videoWatchDogTimer); + slot.subscribedUid = null; + slot.hasVideo = false; + if (slot.unpublishTimer) { + clearTimeout(slot.unpublishTimer); + slot.unpublishTimer = null; + } + forceTick((v) => v + 1); }; - const startVideoWatchDog = () => { - if (videoWatchDogTimer) clearInterval(videoWatchDogTimer); - videoWatchDogTimer = setInterval(async () => { - const track = remoteVideoTrackRef.current; - const dom = remoteVideoRef.current; - if (!track || !dom) return; - const videoEl = dom.querySelector("video") as HTMLVideoElement; - if (!videoEl) return; - if (videoEl.readyState < 2) { - console.warn("看门狗检测视频无画面,尝试重新play"); - try { - await track.play(dom); - } catch (e) { - console.warn("看门狗play异常", e); - } - } - }, 3000); - }; - - const playRemoteTrack = async (track: IRemoteVideoTrack) => { - const dom = remoteVideoRef.current; - if (!dom || !track) return; + const playIntoSlot = async (uid: number, track: IRemoteVideoTrack) => { + const slot = slotsRef.current.get(uid); + if (!slot || !slot.containerRef.current) return; try { - await track.play(dom); - console.log("远端视频播放成功"); - setHasRemoteVideo(true); - startVideoWatchDog(); + await track.play(slot.containerRef.current); + slot.track = track; + slot.hasVideo = true; + forceTick((v) => v + 1); } catch (err: any) { - if (err.name === "AbortError") { - console.warn("播放请求被中断 AbortError,忽略", err); - return; - } - console.error("视频播放失败", err); - message.error("视频播放失败"); + if (err?.name === 'AbortError') return; + console.error('[AGRTC] play failed', channel, uid, err); } }; - const doReconnect = async () => { - if (isUnmounted || joiningRef.current) return; - console.log("执行RTC重连(信令断开)"); - clearRemoteVideo(); - setJoined(false); + const onUserPublished = async (user: any, mediaType: 'video' | 'audio') => { + if (unmounted || mediaType !== 'video') return; + const uid = Number(user.uid); + if (!slotUids.includes(uid)) return; // 只关心我们订阅的摄像头 UID + const slot = slotsRef.current.get(uid); + if (!slot || slot.subscribedUid === user.uid) return; + if (slot.unpublishTimer) { + clearTimeout(slot.unpublishTimer); + slot.unpublishTimer = null; + } try { - joiningRef.current = true; - await client.join(APP_ID, CHANNEL, TOKEN, uid); - if (isUnmounted) return; - setJoined(true); - message.info("RTC重连成功"); - for (const remoteUser of client.remoteUsers) { - if (isUnmounted) break; - if (remoteUser.hasVideo && subscribedUidRef.current !== remoteUser.uid) { - await client.subscribe(remoteUser, "video"); - remoteVideoTrackRef.current = remoteUser.videoTrack; - subscribedUidRef.current = remoteUser.uid; - await playRemoteTrack(remoteUser.videoTrack!); - } + await client.subscribe(user, 'video'); + slot.subscribedUid = user.uid; + if (user.videoTrack) { + await playIntoSlot(uid, user.videoTrack); } - } catch (err: any) { - if (err?.code !== "OPERATION_ABORTED") { - console.error("重连失败", err); - } - } finally { - joiningRef.current = false; + } catch (e) { + console.error('[AGRTC] subscribe failed', channel, uid, e); } }; - const onConnStateChange = (curState: string, prevState: string) => { - if (isUnmounted) return; - console.log("连接状态变更", prevState, "→", curState); - setConnected(curState === "CONNECTED"); - if (curState === "DISCONNECTED") { - clearRemoteVideo(); - if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current); - reconnectTimerRef.current = setTimeout(() => { - doReconnect(); - }, 2000); - } - }; - - const onUserPublished = async (user: any, mediaType: "video" | "audio") => { - if (isUnmounted) return; - console.log("user-published", user.uid, mediaType); - if (mediaType !== "video") return; - if (subscribedUidRef.current === user.uid) { - console.log("该用户已订阅,跳过"); - return; - } - // 取消待执行的清空定时器 - if (unpublishTimer) clearTimeout(unpublishTimer); - - await client.subscribe(user, mediaType); - remoteVideoTrackRef.current = user.videoTrack; - subscribedUidRef.current = user.uid; - await playRemoteTrack(user.videoTrack); - }; - - const onUserUnpublished = (user: any, mediaType: "video" | "audio") => { - if (isUnmounted) return; - console.log("user-unpublished", user.uid, mediaType, subscribedUidRef.current); - if (mediaType === "video" && subscribedUidRef.current === user.uid) { - if (unpublishTimer) clearTimeout(unpublishTimer); - // 延迟2s清空,短闪断自动恢复不黑屏 - unpublishTimer = setTimeout(() => { - clearRemoteVideo(); - }, 2000); - } + const onUserUnpublished = (user: any, mediaType: 'video' | 'audio') => { + if (unmounted || mediaType !== 'video') return; + const uid = Number(user.uid); + if (!slotUids.includes(uid)) return; + const slot = slotsRef.current.get(uid); + if (!slot || slot.subscribedUid !== user.uid) return; + if (slot.unpublishTimer) clearTimeout(slot.unpublishTimer); + slot.unpublishTimer = setTimeout(() => clearSlotTrack(uid), 2000); }; const onUserLeft = (user: any) => { - if (isUnmounted) return; - console.log("user-left", user.uid); - if (subscribedUidRef.current === user.uid) { - if (unpublishTimer) clearTimeout(unpublishTimer); - clearRemoteVideo(); + if (unmounted) return; + const uid = Number(user.uid); + if (!slotUids.includes(uid)) return; + const slot = slotsRef.current.get(uid); + if (!slot || slot.subscribedUid !== user.uid) return; + clearSlotTrack(uid); + }; + + const onConnStateChange = (cur: string, prev: string) => { + if (unmounted) return; + onConnect(cur === 'CONNECTED'); + if (cur === 'CONNECTED') onJoin(true); + else if (cur === 'DISCONNECTED') { + onJoin(false); + // 断线时清空所有槽位,重连成功后 onUserPublished 会重新走一遍 + for (const uid of slotUids) clearSlotTrack(uid); } }; - const onUserJoined = (user: any) => { - if (!isUnmounted) console.log("远端用户进入频道:", user.uid); - }; + client.on('connection-state-change', onConnStateChange); + client.on('user-published', onUserPublished); + client.on('user-unpublished', onUserUnpublished); + client.on('user-left', onUserLeft); - const onTokenWillExpire = () => { - console.warn("token即将过期,请更新token"); - message.warning("Token即将过期,视频可能很快断开"); - }; - - client.on("connection-state-change", onConnStateChange); - client.on("user-published", onUserPublished); - client.on("user-unpublished", onUserUnpublished); - client.on("user-left", onUserLeft); - client.on("user-joined", onUserJoined); - client.on("token-privilege-will-expire", onTokenWillExpire); - - const init = async () => { - if (joiningRef.current) return; - joiningRef.current = true; + const doJoin = async () => { try { - await client.join(APP_ID, CHANNEL, TOKEN, uid); - if (isUnmounted) { - console.log("组件已卸载,丢弃join结果"); - return; - } - console.log("加入频道成功"); - setJoined(true); - message.success("RTC已加入频道"); - for (const remoteUser of client.remoteUsers) { - if (isUnmounted) break; - console.log("发现已有远端用户:", remoteUser.uid); - if (remoteUser.hasVideo && subscribedUidRef.current !== remoteUser.uid) { - await client.subscribe(remoteUser, "video"); - remoteVideoTrackRef.current = remoteUser.videoTrack; - subscribedUidRef.current = remoteUser.uid; - await playRemoteTrack(remoteUser.videoTrack!); - } + console.log('[AGRTC] joining channel=' + channel + ', localUid=' + localUid + ', appId=' + APP_ID); + console.log('[AGRTC] joined ' + channel + ', remoteUsers=', (client.remoteUsers || []).map(u => u.uid)); + await client.join(APP_ID, channel, TOKEN, localUid); + if (unmounted) return; + onJoin(true); + // 加入后立刻把已在频道内的远端摄像头扫一遍,避免错过 onUserPublished + for (const remote of client.remoteUsers) { + if (unmounted) break; + if (!remote.hasVideo) continue; + const uid = Number(remote.uid); + if (!slotUids.includes(uid)) continue; + const slot = slotsRef.current.get(uid); + if (!slot || slot.subscribedUid === remote.uid) continue; + try { + await client.subscribe(remote, 'video'); + slot.subscribedUid = remote.uid; + if (remote.videoTrack) await playIntoSlot(uid, remote.videoTrack); + } catch { /* ignore */ } } } catch (err: any) { - if (err?.code === "OPERATION_ABORTED") { - console.log("join操作被取消,忽略"); - return; + if (err?.code !== 'OPERATION_ABORTED') { + console.error('[AGRTC] join failed', channel, err); + message.error(`加入 ${channel} 失败`); } - console.error("加入频道失败:", err); - if (!isUnmounted) { - message.error("加入频道失败,请检查appid/token/channel"); - } - } finally { - joiningRef.current = false; } }; + doJoin(); - init(); + // Watchdog:每 3s 检查每个 video 元素,readyState 未到 HAVE_CURRENT_DATA 时重新 .play() + const watchdog = setInterval(() => { + if (unmounted) return; + for (const [uid, slot] of slotsRef.current.entries()) { + if (!slot.track || !slot.containerRef.current) continue; + const videoEl = slot.containerRef.current.querySelector('video') as HTMLVideoElement | null; + if (!videoEl) continue; + if (videoEl.readyState < 2) { + try { + slot.track.play(slot.containerRef.current); + } catch (e) { + console.warn('[AGRTC] watchdog replay error', channel, uid, e); + } + } + } + }, 3000); return () => { - isUnmounted = true; - if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current); - if (unpublishTimer) clearTimeout(unpublishTimer); - if (videoWatchDogTimer) clearInterval(videoWatchDogTimer); - clearRemoteVideo(); - const c = clientRef.current; - if (!c) return; - c.off("connection-state-change", onConnStateChange); - c.off("user-published", onUserPublished); - c.off("user-unpublished", onUserUnpublished); - c.off("user-left", onUserLeft); - c.off("user-joined", onUserJoined); - c.off("token-privilege-will-expire", onTokenWillExpire); - c.leave(); - clientRef.current = null; + unmounted = true; + clearInterval(watchdog); + for (const slot of slotsRef.current.values()) { + if (slot.unpublishTimer) clearTimeout(slot.unpublishTimer); + if (slot.track) { + try { slot.track.stop(); } catch { } + } + } + try { + client.off('connection-state-change'); + client.off('user-published'); + client.off('user-unpublished'); + client.off('user-left'); + client.leave(); + } catch { } + slotsRef.current.clear(); + onConnect(false); + onJoin(false); }; - }, [CHANNEL]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [channel, slotUids.join(',')]); - return ( -
-
- - - 频道:{CHANNEL} -
-
- {!hasRemoteVideo && ( -
- 视频加载中,等待远端推流... -
- )} -
-
-
- ); + return <>{children({ slotsByUid: slotsRef.current })}; } diff --git a/src/components/devices/DeviceStatusPage.tsx b/src/components/devices/DeviceStatusPage.tsx index 775a945..6417134 100644 --- a/src/components/devices/DeviceStatusPage.tsx +++ b/src/components/devices/DeviceStatusPage.tsx @@ -21,6 +21,7 @@ import { message, Modal, Switch, + DatePicker } from 'antd'; import { DashboardOutlined, @@ -65,7 +66,8 @@ import VideoPlayer from '../VideoPlayer.tsx'; import SteerButton from './SteerButton'; import AgrtcRoomRobot from '../AgrtcRoomRobot'; import DeviceController from './DeviceController'; -import { DatePicker } from 'antd'; + +import { deviceRunParamSelectByDeviceId } from '@/api/stationManage/index'; import dayjs from 'dayjs'; import { MowerAllView } from './MowerAllView'; import { useMqtt } from '@/hooks/useMqtt'; @@ -87,15 +89,7 @@ const ConsoleBadge = ({ online, text, color }: any) => ( {text} ); -const ConsoleRow = ({ icon, label, value }: any) => ( -
- - {icon} - {label} - - {value} -
-); + // 暗色控制台面板(参考图样式:细边框、小圆角、蓝色竖条标题、右侧状态 badge) const ConsolePanel = ({ title, extra, badge, children, style, bodyStyle }: any) => (
@@ -109,76 +103,7 @@ const ConsolePanel = ({ title, extra, badge, children, style, bodyStyle }: any)
{children}
); -// 方向盘功能按钮(暗色小方块,样式参考参考图) -// SteerButton:支持长按持续发送(与 DPadControl 方向键行为一致) -//const SteerButton = ({ icon, label, color, onPressStart, onPressEnd }: any) => { -// const [pressed, setPressed] = useState(false); -// const holdingRef = useRef(false); -// const intervalRef = useRef(null); -// const emitEndedRef = useRef(false); -// const stopHold = useCallback(() => { -// if (intervalRef.current !== null) { window.clearInterval(intervalRef.current); intervalRef.current = null; } -// if (!holdingRef.current) return; -// holdingRef.current = false; -// emitEndedRef.current = false; -// setPressed(false); -// onPressEnd?.(); -// }, [onPressEnd]); -// const startHold = useCallback(() => { -// if (holdingRef.current) return; -// holdingRef.current = true; -// emitEndedRef.current = false; -// setPressed(true); -// if (intervalRef.current !== null) window.clearInterval(intervalRef.current); -// // 立即首帧 + 每 100ms 持续(DPadControl 也是 100ms) -// onPressStart?.(); -// intervalRef.current = window.setInterval(() => { -// if (!holdingRef.current) return; -// onPressStart?.(); -// }, 100); -// }, [onPressStart]); -// useEffect(() => () => { -// if (intervalRef.current !== null) window.clearInterval(intervalRef.current); -// if (holdingRef.current) stopHold(); -// }, [stopHold]); -// return ( -// -// ); -//}; + export default function DeviceStatusPage() { const { t } = useTranslation(); const { userInfo } = useSelector((state: RootState) => state.user); @@ -199,9 +124,20 @@ export default function DeviceStatusPage() { const [messageApi, contextHolder] = message.useMessage(); // 视频播放开关 const [isVideoPlaying, setIsVideoPlaying] = useState(false); + + // 当前机器人摄像头路数(接口返回 cameraNum,1-4) + const [cameraNum, setCameraNum] = useState(1); + // 行车辅助线开关(仅前视/后视单路叠加) + const [showGuideLine, setShowGuideLine] = useState(true); + // 设备 Agora 视频频道号(后端 paramData 或 device 字段;最终兜底 SN) const toggleVideoPlay = useCallback(() => { setIsVideoPlaying(prev => !prev); }, []); + + // 选中机器人变化 → 拉设备参数,取 cameraNum 决定视频网格布局(1/2/4 路) + + + const [isControlled, setIsControlled] = useState(false); const [hasControlRight, setHasControlRight] = useState(false); const [connecting, setConnecting] = useState(false); @@ -272,6 +208,15 @@ export default function DeviceStatusPage() { const handleFinishEdPoint = (point) => { setArrivedPoint(point); } + const ConsoleRow = ({ icon, label, value }: any) => ( +
+ + {icon} + {label} + + {value} +
+ ); useEffect(() => { fetchAllData(); }, [userInfo, stationId]); @@ -437,6 +382,50 @@ export default function DeviceStatusPage() { onMessage: handleMqttMessage, enabled: mqttTopics.length > 0, }); + + useEffect(() => { + const id = device?.device_sn || device?.serialNumber || selectedSn; + if (!id || !stationId) { + setCameraNum(1); + return; + } + let cancelled = false; + deviceRunParamSelectByDeviceId({ deviceId: id }).then((res) => { + if (cancelled) return; + if (res?.code === 200) { + const n = Number(res.data?.cameraNum); + // channel 字段:videoChannel / cameraChannel / agoraChannel / rtcChannel / channel + + setCameraNum(Number.isFinite(n) && n >= 1 && n <= 4 ? n : 1); + console.log('[DSP] deviceRunParam res.data=', res.data); + } else { + setCameraNum(1); + } + }).catch(() => { + if (!cancelled) setCameraNum(1); + }); + return () => { cancelled = true; }; + }, [device?.device_sn, device?.serialNumber, selectedSn, stationId]); + + // 视角按钮:按摄像头路数动态裁剪 + const viewButtons = useMemo(() => { + const all = [ + { key: 'all', label: t('devices.panorama') }, + { key: 'front', label: t('devices.frontView'), minCams: 1 }, + { key: 'back', label: t('devices.backView'), minCams: 1 }, + { key: 'left', label: t('devices.leftView'), minCams: 3 }, + { key: 'right', label: t('devices.rightView'), minCams: 3 }, + ]; + const n = Number(cameraNum) || 1; + return all.filter((b) => !b.minCams || n >= b.minCams); + }, [cameraNum, t]); + + // cameraNum 变化时自动把非法视角回退到 front + useEffect(() => { + const n = Number(cameraNum) || 1; + if (n <= 2 && (mowerView === 'left' || mowerView === 'right')) setMowerView('front'); + }, [cameraNum, mowerView]); + // 合并无人机和机场数据 const currentDroneData = React.useMemo(() => { return { ...persistentHostData, ...persistentDroneData }; @@ -1406,51 +1395,57 @@ export default function DeviceStatusPage() { bodyStyle={{ padding: 8, display: 'flex', flexDirection: 'column', gap: 8 }} >
- {[{ key: 'front', label: t('devices.frontView') }, { key: 'left', label: t('devices.leftView') }, { key: 'right', label: t('devices.rightView') }, { key: 'back', label: t('devices.backView') }, { key: 'all', label: t('devices.panorama') }].map((v) => ( + {viewButtons.map((v) => ( ))} + + {t('devices.showGuideLine')} + +
{isVideoPlaying && ( mowerView === 'all' ? ( + // 全景/网格视图:单频道多 UID,按 cameraNum 决定 1/2/4 路布局
- +
) : mowerView === 'front' ? ( + // 前视:单路 UID 101
- +
+ ) : mowerView === 'back' ? ( + // 后视:单路 UID 103 + 倒车辅助线 +
+ + +
+ ) : mowerView === 'left' ? ( +
+ +
) : ( + // 右视:单路 UID 104
- - {mowerView === 'back' && ( - - )} +
- ) - )} + ))} {!isVideoPlaying && (
diff --git a/src/components/devices/TaskPlanningView.tsx b/src/components/devices/TaskPlanningView.tsx index db131c4..87c39bd 100644 --- a/src/components/devices/TaskPlanningView.tsx +++ b/src/components/devices/TaskPlanningView.tsx @@ -19,6 +19,8 @@ import { MapEditorView } from './MapEditorView'; import type { ViewStats } from './WayLineView'; import { backToRestPointCommand } from '@/api/mapEdit'; import { sendEmergencyStop, subscribeEmergencyStop, syncEmergencyStop } from './emergencyStopControl'; +import AgrtcRoomRobot from '../AgrtcRoomRobot.js'; +import { deviceRunParamSelectByDeviceId } from '@/api/stationManage/index.js'; const { Text, Title } = Typography; @@ -109,6 +111,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC // 当前激活的Tab const [activeTab, setActiveTab] = useState('pool'); // 'task' for 任务列表, 'pool' for 任务池, 'history' for 历史任务 + const [cameraNum, setCameraNum] = useState(0); // 任务池和历史任务筛选表单 const [poolFilterForm, setPoolFilterForm] = useState({ @@ -1384,6 +1387,26 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC setDeviceStatistics(res.data || {}); } }); + + const id = selectedMachineSn; + if (!id || !stationId) { + setCameraNum(1); + return; + } + let cancelled = false; + deviceRunParamSelectByDeviceId({ deviceId: id }).then((res) => { + if (cancelled) return; + if (res?.code === 200) { + const n = Number(res.data?.cameraNum); + setCameraNum(Number.isFinite(n) && n >= 1 && n <= 4 ? n : 1); + console.log('[DSP] deviceRunParam res.data=', res.data); + } else { + setCameraNum(1); + } + }).catch(() => { + if (!cancelled) setCameraNum(1); + }); + return () => { cancelled = true; }; }, [selectedMachineSn]); useEffect(() => { @@ -3105,22 +3128,18 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC */} - {/*{showVideo && executingRobot && execute && taskPoolList.length > 0 && ( + {showVideo && ( setShowVideo(false)} >
- + +
- )}*/} + )}
); } diff --git a/src/index.css b/src/index.css index b8f2051..7399cb7 100644 --- a/src/index.css +++ b/src/index.css @@ -198,4 +198,8 @@ h4, .ant-typography h4 { font-size: clamp(1rem, 1.5vw, 1.25rem) !important; } } } +.badge-rtc-connected .ant-badge-status-text{ + color:#fff !important +} + diff --git a/src/locales/en/index.ts b/src/locales/en/index.ts index edf8717..8500e59 100644 --- a/src/locales/en/index.ts +++ b/src/locales/en/index.ts @@ -492,6 +492,7 @@ autoFetch: 'Auto Fetch', autoResumeFromBreakpoint: 'Auto Resume From Breakpoint', backView: 'Back View', + showGuideLine: "Show Guide Line", batteryCapacity: 'Battery Capacity', batteryWithPercent: 'Battery with Percent', batteryWithValue: 'Battery with Value', diff --git a/src/locales/zh/index.ts b/src/locales/zh/index.ts index ee996ee..37e7328 100644 --- a/src/locales/zh/index.ts +++ b/src/locales/zh/index.ts @@ -513,6 +513,7 @@ const zh = { autoFetch: '自动获取', autoResumeFromBreakpoint: '自动恢复从断点', backView: '后视角', + showGuideLine: "显示辅助线", batteryCapacity: '电量容量', batteryWithPercent: '电量带百分比', batteryWithValue: '电量带值',