/** * Phase 1 Header 重构 * 扁平化导航菜单 + 手机端汉堡菜单 */ import React, { useState } from "react" import { Avatar, Dropdown, Drawer, Space } from "antd" import { LogoutOutlined, SettingOutlined, UserOutlined, MenuOutlined } from "@ant-design/icons" import { useLocation, useNavigate } from "react-router-dom" import { useAuthStore } from "@/store/authStore" import { useLogout } from "@/hooks/useAuth" import type { MenuProps } from "antd" import { NAV_ITEMS } from "@/config/navigation" import "./Header.css" const Header: React.FC = () => { const navigate = useNavigate() const location = useLocation() const user = useAuthStore((state) => state.user) const logoutMutation = useLogout() const [mobileMenuOpen, setMobileMenuOpen] = useState(false) /** 用户下拉菜单 */ const menuItems: MenuProps["items"] = [ { key: "profile", icon: , label: "个人设置", onClick: () => navigate("/app/profile"), }, { key: "subscription", icon: , label: "订阅管理", onClick: () => navigate("/app/subscription"), }, { type: "divider" }, { key: "logout", icon: , label: "退出登录", onClick: () => logoutMutation.mutateAsync(), }, ] /** 判断导航项是否激活 */ const isActive = (path: string) => { // 首页特殊处理:/ 和 /app/dashboard 都算激活 if (path === "/app/dashboard") { return ( location.pathname === "/" || location.pathname === "/app" || location.pathname === "/app/dashboard" ) } return location.pathname.startsWith(path) } return ( navigate("/app/dashboard")}> 🦐 小虾自动剪辑 {/* 桌面端导航 */} {NAV_ITEMS.map((item) => ( navigate(item.path)} > {item.label} ))} {/* 手机端汉堡菜单按钮 */} setMobileMenuOpen(true)}> } /> {user?.display_name || user?.username || "小虾用户"} {/* 手机端侧边抽屉导航 */} setMobileMenuOpen(false)} open={mobileMenuOpen} width={260} className="xx-mobile-drawer" > {NAV_ITEMS.map((item) => ( { navigate(item.path) setMobileMenuOpen(false) }} > {item.icon} {item.label} ))} ) } export default Header