'use client' import { useState, useEffect } from 'react' import { Menu, X } from 'lucide-react' import { Sidebar } from '../navigation/Sidebar' import { cn } from '@/lib/utils' interface ResponsiveLayoutProps { children: React.ReactNode role?: 'creator' | 'agency' | 'brand' className?: string } export function ResponsiveLayout({ children, role = 'creator', className = '', }: ResponsiveLayoutProps) { const [isMobile, setIsMobile] = useState(false) const [sidebarOpen, setSidebarOpen] = useState(false) useEffect(() => { const checkMobile = () => { const mobile = window.innerWidth < 1024 setIsMobile(mobile) // 大屏幕自动关闭抽屉 if (!mobile) { setSidebarOpen(false) } } checkMobile() window.addEventListener('resize', checkMobile) return () => window.removeEventListener('resize', checkMobile) }, []) // 点击遮罩关闭侧边栏 const closeSidebar = () => setSidebarOpen(false) return (
{/* 移动端:汉堡菜单按钮 */} {isMobile && !sidebarOpen && ( )} {/* 移动端:遮罩层 */} {isMobile && sidebarOpen && (
)} {/* 侧边栏 */}
{/* 移动端:关闭按钮 */} {isMobile && sidebarOpen && ( )}
{/* 主内容区 */}
{children}
) } export default ResponsiveLayout