diff --git a/frontend/src/frameworks/components/layout/CenterCanvas.tsx b/frontend/src/frameworks/components/layout/CenterCanvas.tsx index f4b5846..2229ad4 100644 --- a/frontend/src/frameworks/components/layout/CenterCanvas.tsx +++ b/frontend/src/frameworks/components/layout/CenterCanvas.tsx @@ -1,6 +1,7 @@ 'use client'; -import React, { useMemo, useState, useEffect } from 'react'; +import React, { useMemo, useRef, useState, useEffect } from 'react'; +import { Responsive } from 'react-grid-layout'; import { useAppSelector } from '@/adapters/state/redux/store'; import { useLayout } from '@/frameworks/hooks/useLayout'; import { ChartWrapper } from '@/frameworks/components/charts/ChartWrapper'; @@ -41,16 +42,19 @@ function DropZonePlaceholder() { export function CenterCanvas() { const charts = useAppSelector((s) => s.chart.charts); const { layouts, onLayoutChange } = useLayout(); - const [GridLayout, setGridLayout] = useState(null); + const containerRef = useRef(null); + const [width, setWidth] = useState(1200); useEffect(() => { - import('react-grid-layout').then((mod: any) => { - const WP = mod.WidthProvider || mod.default?.WidthProvider; - const Resp = mod.Responsive || mod.default?.Responsive; - if (WP && Resp) { - setGridLayout(() => WP(Resp)); + if (!containerRef.current) return; + const observer = new ResizeObserver((entries) => { + for (const entry of entries) { + setWidth(entry.contentRect.width); } }); + observer.observe(containerRef.current); + setWidth(containerRef.current.clientWidth); + return () => observer.disconnect(); }, []); const gridLayouts = useMemo(() => { @@ -79,29 +83,23 @@ export function CenterCanvas() { ); } - if (!GridLayout) { - return
加载中...
; - } - return ( -
- + onLayoutChange(layout)} - isDraggable - isResizable - compactType="vertical" + onLayoutChange={(layout: any) => onLayoutChange([...layout])} > {charts.map((chart) => (
))} -
+
); }