import React, { useState } from 'react' import { Link, useLocation, useNavigate } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' import { Button } from '@/components/ui/button' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Badge } from '@/components/ui/badge' import { Separator } from '@/components/ui/separator' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu' import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet' import { LayoutDashboard, Camera, FolderOpen, Tags, Users, Settings, LogOut, Menu, User, Bell, Search } from 'lucide-react' import { cn } from '@/lib/utils' import { useAuthStore } from '@/stores/authStore' import { authService } from '@/services/authService' import { toast } from 'sonner' interface DashboardLayoutProps { children: React.ReactNode } const navigation = [ { name: '仪表板', href: '/dashboard', icon: LayoutDashboard }, { name: '照片管理', href: '/photos', icon: Camera }, { name: '分类管理', href: '/categories', icon: FolderOpen }, { name: '标签管理', href: '/tags', icon: Tags }, { name: '用户管理', href: '/users', icon: Users }, { name: '系统设置', href: '/settings', icon: Settings }, ] export default function DashboardLayout({ children }: DashboardLayoutProps) { const location = useLocation() const navigate = useNavigate() const { user, logout } = useAuthStore() const [sidebarOpen, setSidebarOpen] = useState(false) // 获取当前用户信息 const { data: currentUser } = useQuery({ queryKey: ['current-user'], queryFn: authService.getCurrentUser, initialData: user, staleTime: 5 * 60 * 1000, // 5分钟 }) const handleLogout = async () => { try { await authService.logout() logout() toast.success('退出登录成功') navigate('/login') } catch (error) { toast.error('退出登录失败') } } const isCurrentPath = (path: string) => { return location.pathname === path || location.pathname.startsWith(path + '/') } const SidebarContent = () => (
{/* Logo */}
摄影管理
{/* Navigation */} {/* User info */}
{currentUser?.username?.charAt(0).toUpperCase()}

{currentUser?.username}

{currentUser?.role === 'admin' ? '管理员' : currentUser?.role === 'editor' ? '编辑者' : '用户'}
) return (
{/* Desktop sidebar */}
{/* Mobile sidebar */} {/* Main content */}
{/* Top bar */}
我的账户 navigate('/profile')}> 个人资料 navigate('/settings')}> 设置 退出登录
{/* Page content */}
{children}
) }