diff --git a/app/canvas/[id]/page.tsx b/app/canvas/[id]/page.tsx index 0b3baff21..a32366961 100644 --- a/app/canvas/[id]/page.tsx +++ b/app/canvas/[id]/page.tsx @@ -79,6 +79,10 @@ const SIZE_PRESETS = [ { label: "9:16", value: "9:16", width: 1024, height: 1820 }, ]; +const FLOATING_PANEL_WIDTH = 460; +const FLOATING_PANEL_INSET = 16; +const FLOATING_UI_GAP = 16; + export default function CanvasEditorPage({ params }: PageProps) { // 使用 useParams 确保客户端导航时能正确获取更新的 id const routeParams = useParams(); @@ -124,6 +128,7 @@ export default function CanvasEditorPage({ params }: PageProps) { const [isPanelOpen, setIsPanelOpen] = useState(true); // 面板模式: 'chat' 聊天面板, 'fileList' 文件列表 const [panelMode, setPanelMode] = useState<'chat' | 'fileList'>('chat'); + const [viewportWidth, setViewportWidth] = useState(0); const { data: siteSettingsData } = useSWR<{ siteName?: string; @@ -145,6 +150,13 @@ export default function CanvasEditorPage({ params }: PageProps) { ? nodes.find(n => n.id === selectedNodeIds[0] && n.type === 'image') : null; + const resolvedPanelWidth = viewportWidth > 0 + ? Math.min(FLOATING_PANEL_WIDTH, Math.max(viewportWidth - FLOATING_PANEL_INSET, 0)) + : FLOATING_PANEL_WIDTH; + const panelOcclusionRight = isPanelOpen ? resolvedPanelWidth + FLOATING_PANEL_INSET : 0; + const floatingToolbarOffset = isPanelOpen ? -(panelOcclusionRight / 2) : 0; + const compactControlsRight = isPanelOpen ? panelOcclusionRight + FLOATING_UI_GAP : FLOATING_UI_GAP; + // 加载画布数据 useEffect(() => { console.log('[Canvas] Loading project:', id); @@ -179,6 +191,13 @@ export default function CanvasEditorPage({ params }: PageProps) { loadProject(); }, [id]); // 只依赖 id,使用 getState() 直接调用 store actions + useEffect(() => { + const updateViewportWidth = () => setViewportWidth(window.innerWidth); + updateViewportWidth(); + window.addEventListener("resize", updateViewportWidth); + return () => window.removeEventListener("resize", updateViewportWidth); + }, []); + const persistCanvasState = useCallback( async (reason: "autosave" | "delete" | "beforeunload") => { const canvasData = getCanvasState(); @@ -561,7 +580,7 @@ export default function CanvasEditorPage({ params }: PageProps) { {/* 1. Canvas Layer (Full Screen) - 使用 key 强制在 id 变化时重新挂载 */}
- +
{/* Brand Entry (Top Left) */} @@ -641,7 +660,7 @@ export default function CanvasEditorPage({ params }: PageProps) { {/* 3. Floating Actions (Top Right) */} {!isPanelOpen && ( -
+