"use client" import { BadgeQuestionMarkIcon, ChevronDownIcon, ChevronRightIcon, LogOutIcon, SettingsIcon, UserIcon, } from "lucide-react" import Image from "next/image" import Link from "next/link" import { usePathname, useRouter } from "next/navigation" import { useEffect, useRef, useState } from "react" import { logout } from "@/actions/auth" import { Button } from "@/components/ui/button" import type { Admin } from "@/models/admin" export default function Appbar(props: { admin: Admin }) { const router = useRouter() const [showDropdown, setShowDropdown] = useState(false) const [showNotifications, setShowNotifications] = useState(false) const pathname = usePathname() const dropdownRef = useRef(null) const notificationRef = useRef(null) // 处理点击外部关闭下拉菜单 useEffect(() => { function handleClickOutside(event: MouseEvent) { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setShowDropdown(false) } if ( notificationRef.current && !notificationRef.current.contains(event.target as Node) ) { setShowNotifications(false) } } document.addEventListener("mousedown", handleClickOutside) return () => document.removeEventListener("mousedown", handleClickOutside) }, []) const generateBreadcrumbs = () => { const paths = pathname.split("/").filter(Boolean) const hiddenSegments = ["client"] const filteredPaths = paths.filter(path => !hiddenSegments.includes(path)) const breadcrumbs = [ { path: "/", label: "首页" }, ...filteredPaths.map((path, index) => { const originalIndex = paths.findIndex(p => p === path) const url = `/${paths.slice(0, originalIndex + 1).join("/")}` const label = getBreadcrumbLabel(path) return { path: url, label } }), ] return breadcrumbs } const getBreadcrumbLabel = (path: string) => { const labels: Record = { dashboard: "控制台", content: "内容管理", articles: "文章管理", media: "媒体库", user: "客户认领", roles: "角色权限", settings: "系统设置", logs: "系统日志", proxy: "", nodes: "节点列表", trade: "交易明细", billing: "账单详情", cust: "客户管理", product: "产品管理", resources: "套餐管理", batch: "提取记录", channel: "IP管理", pools: "IP池管理", coupon: "优惠券", admin: "管理员", permissions: "权限列表", discount: "折扣管理", statistics: "数据统计", balance: "余额明细", } return labels[path] || path } const breadcrumbs = generateBreadcrumbs() const doLogout = async () => { const resp = await logout() if (resp.success) { router.replace("/") router.refresh() } } return (
{/* 面包屑导航 */}
{breadcrumbs.map((crumb, index) => (
{index > 0 && ( )} {crumb.label}
))}
{/* 右侧用户信息和工具栏 */}
{/* 用户下拉菜单 */}
{/* 用户下拉内容 */} {showDropdown && (
{props.admin && (

{props.admin.name}

{props.admin.name}

)}
个人资料 账号设置 帮助中心
)}
) }