import React, { useState, useRef, useEffect, memo } from 'react'; import VideoPlayer from '../VideoPlayer.tsx'; import DraggablePanel from './DraggablePanel.jsx'; // 视频子面板,使用 memo 避免不必要的重渲染 const VideoSubPanel = memo(({ idx, label, x, y, width, height, bounds, serialNumber, robotVideo, error, ready }) => { const hasVideo = ready && !error; if (!hasVideo) return null; return ( ⋮⋮ {label} } >
); }); export function MowerAllView({ serialNumber, robotVideo, error, ready, statusData }) { const containerRef = useRef(null); const [panelSize, setPanelSize] = useState(null); const [initialPositions, setInitialPositions] = useState(null); const [containerBounds, setContainerBounds] = useState(null); const [initialized, setInitialized] = useState(false); // 初始化尺寸和位置 useEffect(() => { if (!containerRef.current || initialized) return; const rect = containerRef.current.getBoundingClientRect(); // 统一三个面板的尺寸 const w = Math.max(200, Math.floor(rect.width * 0.25)); const h = Math.max(150, Math.floor(rect.height * 0.3)); setPanelSize({ width: w, height: h }); setContainerBounds({ width: rect.width, height: rect.height }); // 设置初始位置 setInitialPositions({ left: { x: 8, y: 8 }, right: { x: rect.width - w - 8, y: 8 }, back: { x: (rect.width - w) / 2, y: rect.height - h - 8 } }); setInitialized(true); }, [initialized]); return (
{/* 前视主画面 - 铺满 */}
{/* 三个可拖拽子面板 */} {initialized && panelSize && initialPositions && containerBounds && ( <> {/* 左视 */} {/* 右视 */} {/* 后视 */} )} {/* 状态详情面板 */} {statusData && (
机器人状态
电量: {statusData.battery !== undefined ? `${statusData.battery}%` : '-'} 电压: {statusData.voltage !== undefined ? `${Number(statusData.voltage).toFixed(2)}V` : '-'} 左电机: {statusData.leftCurrent !== undefined ? `${Number(statusData.leftCurrent).toFixed(2)}A` : '-'} 右电机: {statusData.rightCurrent !== undefined ? `${Number(statusData.rightCurrent).toFixed(2)}A` : '-'} 左速度: {statusData.leftMeasureSpeed !== undefined ? `${Number(statusData.leftMeasureSpeed).toFixed(1)}rpm` : '-'} 右速度: {statusData.rightMeasureSpeed !== undefined ? `${Number(statusData.rightMeasureSpeed).toFixed(1)}rpm` : '-'} 左温度: {statusData.leftMotorTemp !== undefined ? `${Number(statusData.leftMotorTemp).toFixed(1)}℃` : '-'} 右温度: {statusData.rightMotorTemp !== undefined ? `${Number(statusData.rightMotorTemp).toFixed(1)}℃` : '-'} 主控温度: {statusData.chipTemp !== undefined ? `${Number(statusData.chipTemp).toFixed(1)}℃` : '-'} 航向角: {statusData.yaw !== undefined ? `${Number(statusData.yaw).toFixed(1)}°` : '-'} 俯仰角: {statusData.pitch !== undefined ? `${Number(statusData.pitch).toFixed(1)}°` : '-'} 定位: {statusData.qual == 0 ? '无效' : statusData.qual == 1 ? 'GPS单点' : statusData.qual == 2 ? 'DGPS差分' : statusData.qual == 4 ? 'RTK固定' : statusData.qual == 5 ? 'RTK浮点' : '未知'} 卫星: {statusData.satelliteCnt || 0}颗 模式: {statusData.controlMode == 1 ? '本地' : statusData.controlMode == 3 ? '远程' : '未知'}
)}
); }