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);
// 初始化尺寸、窗口缩放重新计算面板尺寸
useEffect(() => {
const calcSize = () => {
if (!containerRef.current) return;
const rect = containerRef.current.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) return;
const w = rect.width * 0.30;
const h = Math.floor(rect.height * 0.35);
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 }
});
};
calcSize();
const timer = setTimeout(calcSize, 100);
window.addEventListener('resize', calcSize);
return () => {
clearTimeout(timer);
window.removeEventListener('resize', calcSize);
};
}, []);
return (
{/* 前视主画面 - 铺满 */}
{/* 三个可拖拽子面板 */}
{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.headingStatus !== undefined ? `${statusData.headingStatus == 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 ? '远程' : '未知'}
)}
);
}