声网视频组件完成 总览界面和 任务规划界面 都显示 了 根据机器配备的几路视频 显示
This commit is contained in:
@@ -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}
|
||||
</span>
|
||||
);
|
||||
const ConsoleRow = ({ icon, label, value }: any) => (
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, color: '#8c8c8c', whiteSpace: 'nowrap' }}>
|
||||
{icon}
|
||||
{label}
|
||||
</span>
|
||||
<span style={{ fontSize: 12, color: '#262626', textAlign: 'right', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{value}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
// 暗色控制台面板(参考图样式:细边框、小圆角、蓝色竖条标题、右侧状态 badge)
|
||||
const ConsolePanel = ({ title, extra, badge, children, style, bodyStyle }: any) => (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', background: '#fff', borderRadius: 10, overflow: 'hidden', ...style }}>
|
||||
@@ -109,76 +103,7 @@ const ConsolePanel = ({ title, extra, badge, children, style, bodyStyle }: any)
|
||||
<div style={{ flex: 1, minHeight: 0, padding: 10, ...bodyStyle }}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
// 方向盘功能按钮(暗色小方块,样式参考参考图)
|
||||
// SteerButton:支持长按持续发送(与 DPadControl 方向键行为一致)
|
||||
//const SteerButton = ({ icon, label, color, onPressStart, onPressEnd }: any) => {
|
||||
// const [pressed, setPressed] = useState(false);
|
||||
// const holdingRef = useRef(false);
|
||||
// const intervalRef = useRef<number | null>(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 (
|
||||
// <button
|
||||
// type="button"
|
||||
// aria-label={label}
|
||||
// onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); startHold(); }}
|
||||
// onMouseUp={(e) => { e.preventDefault(); e.stopPropagation(); stopHold(); }}
|
||||
// onMouseLeave={() => { if (holdingRef.current) stopHold(); }}
|
||||
// onTouchStart={(e) => { e.preventDefault(); startHold(); }}
|
||||
// onTouchEnd={(e) => { e.preventDefault(); stopHold(); }}
|
||||
// onTouchCancel={() => { if (holdingRef.current) stopHold(); }}
|
||||
// onContextMenu={(e) => e.preventDefault()}
|
||||
// onClick={(e) => e.preventDefault()}
|
||||
// style={{
|
||||
// flex: '1 1 0',
|
||||
// display: 'flex',
|
||||
// flexDirection: 'column',
|
||||
// alignItems: 'center',
|
||||
// justifyContent: 'center',
|
||||
// gap: 4,
|
||||
// minHeight: 46,
|
||||
// padding: '6px 4px',
|
||||
// borderRadius: 8,
|
||||
// background: pressed ? color + '30' : '#1e293b',
|
||||
// border: '1px solid ' + (pressed ? color : color + '55'),
|
||||
// color: color,
|
||||
// cursor: 'pointer',
|
||||
// userSelect: 'none',
|
||||
// touchAction: 'none',
|
||||
// transform: pressed ? 'scale(0.94)' : 'scale(1)',
|
||||
// boxShadow: pressed ? '0 0 14px ' + color + '66' : 'none',
|
||||
// transition: 'transform .08s, background .12s, border-color .12s, box-shadow .12s',
|
||||
// }}
|
||||
// >
|
||||
// <span style={{ display: 'inline-flex', fontSize: 16, lineHeight: 1 }}>{icon}</span>
|
||||
// <span style={{ fontSize: 11, fontWeight: 600, whiteSpace: 'nowrap' }}>{label}</span>
|
||||
// </button>
|
||||
// );
|
||||
//};
|
||||
|
||||
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<number>(1);
|
||||
// 行车辅助线开关(仅前视/后视单路叠加)
|
||||
const [showGuideLine, setShowGuideLine] = useState<boolean>(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) => (
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, color: '#8c8c8c', whiteSpace: 'nowrap' }}>
|
||||
{icon}
|
||||
{label}
|
||||
</span>
|
||||
<span style={{ fontSize: 12, color: '#262626', textAlign: 'right', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{value}</span>
|
||||
</div>
|
||||
);
|
||||
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 }}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0, overflowX: 'auto' }}>
|
||||
{[{ 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) => (
|
||||
<Button key={v.key} type={mowerView === v.key ? 'primary' : 'default'} size="small" onClick={() => setMowerView(v.key)}>
|
||||
{v.label}
|
||||
</Button>
|
||||
))}
|
||||
<span style={{ marginLeft: 'auto', display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, color: '#555' }}>
|
||||
{t('devices.showGuideLine')}
|
||||
<Switch size="small" checked={showGuideLine} onChange={setShowGuideLine} />
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ position: 'relative', flex: 1, minHeight: 0, borderRadius: 8, overflow: 'hidden', }}>
|
||||
{isVideoPlaying && (
|
||||
mowerView === 'all' ? (
|
||||
// 全景/网格视图:单频道多 UID,按 cameraNum 决定 1/2/4 路布局
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||
<MowerAllView serialNumber={device?.serialNumber} robotVideo={robotVideo} error={error} ready={ready} />
|
||||
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} cameraCount={cameraNum} />
|
||||
</div>
|
||||
) : mowerView === 'front' ? (
|
||||
// 前视:单路 UID 101
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||
<AgrtcRoomRobot CHANNEL={"cam2-17"} />
|
||||
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[101]} />
|
||||
<CarReverseGuideLine
|
||||
direction="forward"
|
||||
steer={steerXY.x * 45}
|
||||
linearSpeed={Number(runningStatus?.linear_speed ?? runningStatus?.linearSpeed)}
|
||||
angularSpeed={Number(runningStatus?.angular_speed ?? runningStatus?.angularSpeed)}
|
||||
visible={isVideoPlaying}
|
||||
visible={isVideoPlaying && showGuideLine}
|
||||
/>
|
||||
</div>
|
||||
) : mowerView === 'back' ? (
|
||||
// 后视:单路 UID 103 + 倒车辅助线
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[103]} />
|
||||
<CarReverseGuideLine
|
||||
direction="reverse"
|
||||
steer={steerXY.x * 45}
|
||||
linearSpeed={Number(runningStatus?.linear_speed ?? runningStatus?.linearSpeed)}
|
||||
angularSpeed={Number(runningStatus?.angular_speed ?? runningStatus?.angularSpeed)}
|
||||
visible={isVideoPlaying && showGuideLine}
|
||||
/>
|
||||
</div>
|
||||
) : mowerView === 'left' ? (
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[102]} />
|
||||
</div>
|
||||
) : (
|
||||
// 右视:单路 UID 104
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||
<VideoPlayer
|
||||
deviceId={device?.serialNumber}
|
||||
idx={mowerView === 'back' ? 2 : mowerView === 'left' ? 3 : 4}
|
||||
className="w-full h-full object-contain"
|
||||
video={robotVideo}
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
{mowerView === 'back' && (
|
||||
<CarReverseGuideLine
|
||||
direction="reverse"
|
||||
steer={steerXY.x * 45}
|
||||
linearSpeed={Number(runningStatus?.linear_speed ?? runningStatus?.linearSpeed)}
|
||||
angularSpeed={Number(runningStatus?.angular_speed ?? runningStatus?.angularSpeed)}
|
||||
visible={isVideoPlaying}
|
||||
/>
|
||||
)}
|
||||
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[104]} />
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
))}
|
||||
{!isVideoPlaying && (
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column', gap: 12, color: 'rgba(14, 78, 198, 0.55)' }}>
|
||||
<VideoCameraOutlined style={{ fontSize: 56, opacity: 0.6 }} />
|
||||
|
||||
Reference in New Issue
Block a user