import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import Link from 'next/link'; import useClientMount from '../utils/useClientMount'; import { HomeIcon, UsersIcon, PhoneIcon, CalendarIcon, DocumentTextIcon, CurrencyDollarIcon, ChartBarIcon, CogIcon, BellIcon, UserGroupIcon, ClipboardDocumentListIcon, Bars3Icon, XMarkIcon, BuildingOfficeIcon, FolderIcon, DocumentIcon, ReceiptPercentIcon, ChevronDownIcon, ChevronRightIcon } from '@heroicons/react/24/outline'; interface LayoutProps { children: React.ReactNode; user?: any; } const navigation = [ { name: '仪表盘', href: '/dashboard', icon: HomeIcon }, { name: '用户管理', href: '/dashboard/users', icon: UsersIcon }, { name: '翻译员管理', href: '/dashboard/interpreters', icon: UserGroupIcon }, { name: '订单管理', icon: DocumentTextIcon, children: [ { name: '订单列表', href: '/dashboard/orders' }, { name: '发票管理', href: '/dashboard/invoices' } ] }, { name: '通话记录', href: '/dashboard/calls', icon: PhoneIcon }, { name: '企业服务', href: '/dashboard/enterprise', icon: BuildingOfficeIcon }, { name: '文档管理', href: '/dashboard/documents', icon: FolderIcon }, { name: '系统设置', href: '/dashboard/settings', icon: CogIcon }, ]; export default function Layout({ children, user }: LayoutProps) { const [sidebarOpen, setSidebarOpen] = useState(false); const [isDemoMode, setIsDemoMode] = useState(false); const [expandedItems, setExpandedItems] = useState([]); const isClient = useClientMount(); const router = useRouter(); useEffect(() => { // 只在客户端执行 if (!isClient) return; const checkDemoMode = () => { const isDemo = !process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL === 'https://demo.supabase.co' || process.env.NEXT_PUBLIC_SUPABASE_URL === ''; setIsDemoMode(isDemo); }; checkDemoMode(); }, [isClient]); const handleLogout = () => { if (isDemoMode) { router.push('/auth/login'); } else { // 实际的登出逻辑 router.push('/auth/login'); } }; const toggleExpanded = (itemName: string) => { setExpandedItems(prev => prev.includes(itemName) ? prev.filter(name => name !== itemName) : [...prev, itemName] ); }; const isItemActive = (item: any) => { if (item.href) { return router.pathname === item.href; } if (item.children) { return item.children.some((child: any) => router.pathname === child.href); } return false; }; const renderNavItem = (item: any) => { const hasChildren = item.children && item.children.length > 0; const isActive = isItemActive(item); const isExpanded = expandedItems.includes(item.name); if (hasChildren) { return (
{isExpanded && (
{item.children.map((child: any) => ( {child.name} ))}
)}
); } return ( {item.name} ); }; // 在客户端挂载之前,返回一个简单的布局以避免水合错误 if (!isClient) { return (
{children}
); } return (
{/* 移动端侧边栏 */}
setSidebarOpen(false)} />

口译管理系统

{/* 桌面端侧边栏 */}

口译管理系统

{isDemoMode && ( 演示模式 )}

管理员

admin@demo.com

{/* 主内容区域 */}

口译管理系统

{isDemoMode && ( 演示模式 )}
{children}
); }