机器航向角和 机器人设备状态视频 完善拖动
This commit is contained in:
@@ -67,30 +67,35 @@ export function MowerAllView({ serialNumber, robotVideo, error, ready, statusDat
|
||||
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 calcSize = () => {
|
||||
if (!containerRef.current) return;
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
if (rect.width === 0 || rect.height === 0) return;
|
||||
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
const w = rect.width * 0.30;
|
||||
const h = Math.floor(rect.height * 0.35);
|
||||
|
||||
// 统一三个面板的尺寸
|
||||
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 }
|
||||
});
|
||||
};
|
||||
|
||||
setPanelSize({ width: w, height: h });
|
||||
setContainerBounds({ width: rect.width, height: rect.height });
|
||||
calcSize();
|
||||
const timer = setTimeout(calcSize, 100);
|
||||
window.addEventListener('resize', calcSize);
|
||||
|
||||
// 设置初始位置
|
||||
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 () => {
|
||||
clearTimeout(timer);
|
||||
window.removeEventListener('resize', calcSize);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -112,13 +117,11 @@ export function MowerAllView({ serialNumber, robotVideo, error, ready, statusDat
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
{/* 三个可拖拽子面板 */}
|
||||
{initialized && panelSize && initialPositions && containerBounds && (
|
||||
{panelSize && initialPositions && containerBounds && (
|
||||
<>
|
||||
{/* 左视 */}
|
||||
<VideoSubPanel
|
||||
idx={3}
|
||||
label="左视"
|
||||
@@ -132,8 +135,6 @@ export function MowerAllView({ serialNumber, robotVideo, error, ready, statusDat
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
|
||||
{/* 右视 */}
|
||||
<VideoSubPanel
|
||||
idx={4}
|
||||
label="右视"
|
||||
@@ -147,8 +148,6 @@ export function MowerAllView({ serialNumber, robotVideo, error, ready, statusDat
|
||||
error={error}
|
||||
ready={ready}
|
||||
/>
|
||||
|
||||
{/* 后视 */}
|
||||
<VideoSubPanel
|
||||
idx={2}
|
||||
label="后视"
|
||||
|
||||
Reference in New Issue
Block a user