import { useState } from 'react'; import { cn } from '@/lib/utils'; import { useThemeStore, useTabStore, useNotificationStore, useUserStore } from '@/store'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; 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 { Search, Bell, Menu, X, Settings, User, LogOut, CheckCheck, AlertTriangle, Info, CheckCircle, Palette, Check, } from 'lucide-react'; import { formatDistanceToNow } from '@/lib/utils'; import { useTheme, THEME_OPTIONS } from '@/hooks/useTheme'; export function Header() { const { sidebarCollapsed, toggleSidebar } = useThemeStore(); const { tabs, activeTab, removeTab, setActiveTab } = useTabStore(); const { notifications, unreadCount, markAsRead, markAllAsRead } = useNotificationStore(); const { user, logout } = useUserStore(); const { theme, setTheme } = useTheme(); const [searchValue, setSearchValue] = useState(''); const handleLogout = () => { logout(); window.location.href = '/login'; }; const displayName = user?.real_name || user?.username || '管理员'; const getNotificationIcon = (type: string) => { switch (type) { case 'error': return ; case 'warning': return ; case 'success': return ; default: return ; } }; return (
{/* Left: Toggle & Search */}
{sidebarCollapsed && ( )} {/* Global Search */}
setSearchValue(e.target.value)} className="pl-9 h-9 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500 focus-visible:ring-blue-500/30" /> ⌘K
{/* Right: Actions */}
{/* Theme Switcher */} 主题切换 {THEME_OPTIONS.map((option) => ( setTheme(option.id)} >
{option.name} {option.description}
{theme === option.id && }
))}
{/* Notifications */} 通知 {unreadCount > 0 && ( )}
{notifications.length === 0 ? (

暂无通知

) : ( notifications.slice(0, 10).map((notification) => ( markAsRead(notification.id)} > {getNotificationIcon(notification.type)}

{notification.title}

{notification.message}

{formatDistanceToNow(notification.timestamp)}

{!notification.read && ( )}
)) )}
{/* User Menu */} 我的账号 个人中心 账号设置 退出登录
{/* Tabs */} {tabs.length > 0 && (
{tabs.map((tab) => (
setActiveTab(tab.id)} > {tab.title} {tab.closable && ( )}
))}
)}
); }