2025-12-29 14:37:03 +08:00
|
|
|
"use client"
|
2026-01-05 09:14:41 +08:00
|
|
|
import {
|
|
|
|
|
BadgeQuestionMarkIcon,
|
|
|
|
|
BellIcon,
|
|
|
|
|
ChevronDownIcon,
|
|
|
|
|
ChevronRightIcon,
|
|
|
|
|
InboxIcon,
|
|
|
|
|
LogOutIcon,
|
|
|
|
|
SearchIcon,
|
|
|
|
|
SettingsIcon,
|
|
|
|
|
UserIcon,
|
|
|
|
|
} from "lucide-react"
|
2025-12-29 14:37:03 +08:00
|
|
|
import Image from "next/image"
|
|
|
|
|
import Link from "next/link"
|
|
|
|
|
import { usePathname } from "next/navigation"
|
|
|
|
|
import { useEffect, useRef, useState } from "react"
|
2026-01-05 09:14:41 +08:00
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
|
|
import { Input } from "@/components/ui/input"
|
2025-12-29 10:41:23 +08:00
|
|
|
|
2025-12-29 14:37:03 +08:00
|
|
|
export default function Appbar() {
|
2025-12-29 10:41:23 +08:00
|
|
|
const [currentUser] = useState({
|
2025-12-29 14:37:03 +08:00
|
|
|
name: "张三",
|
|
|
|
|
avatar: "/avatar.png",
|
|
|
|
|
role: "管理员",
|
2025-12-29 10:41:23 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const [showDropdown, setShowDropdown] = useState(false)
|
|
|
|
|
const [showNotifications, setShowNotifications] = useState(false)
|
|
|
|
|
const [notifications] = useState([
|
2025-12-29 14:37:03 +08:00
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
title: "系统通知",
|
|
|
|
|
content: "您有新的待审核内容",
|
|
|
|
|
time: "10分钟前",
|
|
|
|
|
read: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
title: "安全提醒",
|
|
|
|
|
content: "您的账号于昨天登录了新设备",
|
|
|
|
|
time: "1小时前",
|
|
|
|
|
read: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
title: "系统更新",
|
|
|
|
|
content: "系统将在今晚进行例行维护",
|
|
|
|
|
time: "2小时前",
|
|
|
|
|
read: true,
|
|
|
|
|
},
|
2025-12-29 10:41:23 +08:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
const pathname = usePathname()
|
|
|
|
|
const dropdownRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
const notificationRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
// 处理点击外部关闭下拉菜单
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
function handleClickOutside(event: MouseEvent) {
|
2025-12-29 14:37:03 +08:00
|
|
|
if (
|
|
|
|
|
dropdownRef.current &&
|
|
|
|
|
!dropdownRef.current.contains(event.target as Node)
|
|
|
|
|
) {
|
2025-12-29 10:41:23 +08:00
|
|
|
setShowDropdown(false)
|
|
|
|
|
}
|
2025-12-29 14:37:03 +08:00
|
|
|
if (
|
|
|
|
|
notificationRef.current &&
|
|
|
|
|
!notificationRef.current.contains(event.target as Node)
|
|
|
|
|
) {
|
2025-12-29 10:41:23 +08:00
|
|
|
setShowNotifications(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-29 14:37:03 +08:00
|
|
|
document.addEventListener("mousedown", handleClickOutside)
|
|
|
|
|
return () => document.removeEventListener("mousedown", handleClickOutside)
|
2025-12-29 10:41:23 +08:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
// 根据路径生成面包屑
|
|
|
|
|
const generateBreadcrumbs = () => {
|
2025-12-29 14:37:03 +08:00
|
|
|
const paths = pathname.split("/").filter(Boolean)
|
2025-12-29 10:41:23 +08:00
|
|
|
|
|
|
|
|
const breadcrumbs = [
|
2025-12-29 14:37:03 +08:00
|
|
|
{ path: "/", label: "首页" },
|
2025-12-29 10:41:23 +08:00
|
|
|
...paths.map((path, index) => {
|
2025-12-29 14:37:03 +08:00
|
|
|
const url = `/${paths.slice(0, index + 1).join("/")}`
|
2025-12-29 10:41:23 +08:00
|
|
|
const label = getBreadcrumbLabel(path)
|
2025-12-29 14:37:03 +08:00
|
|
|
return { path: url, label }
|
2025-12-29 10:41:23 +08:00
|
|
|
}),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return breadcrumbs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getBreadcrumbLabel = (path: string) => {
|
|
|
|
|
const labels: Record<string, string> = {
|
2025-12-29 14:37:03 +08:00
|
|
|
dashboard: "控制台",
|
|
|
|
|
content: "内容管理",
|
|
|
|
|
articles: "文章管理",
|
|
|
|
|
media: "媒体库",
|
2026-01-05 09:14:41 +08:00
|
|
|
user: "用户管理",
|
2025-12-29 14:37:03 +08:00
|
|
|
roles: "角色权限",
|
|
|
|
|
settings: "系统设置",
|
|
|
|
|
logs: "系统日志",
|
2026-01-05 09:14:41 +08:00
|
|
|
proxy: "",
|
|
|
|
|
nodes: "节点列表",
|
|
|
|
|
trade: "交易明细",
|
|
|
|
|
billing: "账单详情",
|
|
|
|
|
resources: "套餐管理",
|
|
|
|
|
batch: "使用记录",
|
|
|
|
|
channel: "IP管理",
|
|
|
|
|
pools: "IP池管理",
|
2025-12-29 10:41:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return labels[path] || path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const breadcrumbs = generateBreadcrumbs()
|
|
|
|
|
const unreadCount = notifications.filter(n => !n.read).length
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<header className="bg-white h-16 border-b border-gray-200 flex items-center justify-between px-6">
|
|
|
|
|
{/* 面包屑导航 */}
|
|
|
|
|
<div className="flex items-center text-sm">
|
|
|
|
|
{breadcrumbs.map((crumb, index) => (
|
|
|
|
|
<div key={crumb.path} className="flex items-center">
|
|
|
|
|
{index > 0 && (
|
2026-01-05 09:14:41 +08:00
|
|
|
<ChevronRightIcon size={18} className="text-gray-400" />
|
2025-12-29 10:41:23 +08:00
|
|
|
)}
|
|
|
|
|
<Link
|
|
|
|
|
href={crumb.path}
|
2025-12-29 14:37:03 +08:00
|
|
|
className={
|
|
|
|
|
index === breadcrumbs.length - 1
|
|
|
|
|
? "text-gray-800 font-medium"
|
|
|
|
|
: "text-gray-500 hover:text-gray-700"
|
2025-12-29 10:41:23 +08:00
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{crumb.label}
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 右侧用户信息和工具栏 */}
|
|
|
|
|
<div className="flex items-center space-x-4">
|
|
|
|
|
{/* 搜索框 */}
|
|
|
|
|
<div className="hidden md:block relative">
|
2026-01-05 09:14:41 +08:00
|
|
|
<div className="relative">
|
|
|
|
|
<SearchIcon className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
|
|
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="搜索..."
|
|
|
|
|
className="pl-10 pr-4 py-2 bg-gray-100 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent w-56"
|
2025-12-29 14:37:03 +08:00
|
|
|
/>
|
2026-01-05 09:14:41 +08:00
|
|
|
</div>
|
2025-12-29 10:41:23 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 通知图标 */}
|
|
|
|
|
<div className="relative" ref={notificationRef}>
|
2026-01-05 09:14:41 +08:00
|
|
|
<Button
|
2025-12-29 10:41:23 +08:00
|
|
|
onClick={() => setShowNotifications(!showNotifications)}
|
2026-01-05 09:14:41 +08:00
|
|
|
className="relative p-2 rounded-full text-gray-600 bg-gray-100 hover:bg-gray-100 hover:text-gray-800 transition-colors"
|
2025-12-29 10:41:23 +08:00
|
|
|
aria-label="通知"
|
|
|
|
|
>
|
2026-01-05 09:14:41 +08:00
|
|
|
<BellIcon />
|
2025-12-29 10:41:23 +08:00
|
|
|
{unreadCount > 0 && (
|
2025-12-29 14:37:03 +08:00
|
|
|
<span className="absolute top-1 right-1 h-4 w-4 text-xs flex items-center justify-center rounded-full bg-red-500 text-white">
|
|
|
|
|
{unreadCount}
|
|
|
|
|
</span>
|
2025-12-29 10:41:23 +08:00
|
|
|
)}
|
2026-01-05 09:14:41 +08:00
|
|
|
</Button>
|
2025-12-29 10:41:23 +08:00
|
|
|
|
|
|
|
|
{/* 通知下拉面板 */}
|
|
|
|
|
{showNotifications && (
|
|
|
|
|
<div className="absolute right-0 mt-2 w-80 bg-white rounded-md shadow-lg py-1 z-20 border border-gray-200">
|
|
|
|
|
<div className="px-4 py-2 border-b border-gray-100 flex justify-between items-center">
|
|
|
|
|
<h3 className="font-medium text-gray-800">通知</h3>
|
2026-01-05 09:14:41 +08:00
|
|
|
<Button className="text-xs text-blue-600 hover:text-blue-800">
|
2025-12-29 10:41:23 +08:00
|
|
|
全部标为已读
|
2026-01-05 09:14:41 +08:00
|
|
|
</Button>
|
2025-12-29 10:41:23 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="max-h-72 overflow-y-auto">
|
|
|
|
|
{notifications.length > 0 ? (
|
2025-12-29 14:37:03 +08:00
|
|
|
notifications.map(notification => (
|
2025-12-29 10:41:23 +08:00
|
|
|
<div
|
|
|
|
|
key={notification.id}
|
|
|
|
|
className={`px-4 py-3 border-b border-gray-100 hover:bg-gray-50 ${
|
2025-12-29 14:37:03 +08:00
|
|
|
notification.read ? "bg-white" : "bg-blue-50"
|
2025-12-29 10:41:23 +08:00
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex justify-between items-start">
|
2025-12-29 14:37:03 +08:00
|
|
|
<h4 className="text-sm font-medium text-gray-800">
|
|
|
|
|
{notification.title}
|
|
|
|
|
</h4>
|
|
|
|
|
<span className="text-xs text-gray-500">
|
|
|
|
|
{notification.time}
|
|
|
|
|
</span>
|
2025-12-29 10:41:23 +08:00
|
|
|
</div>
|
2025-12-29 14:37:03 +08:00
|
|
|
<p className="text-xs text-gray-600 mt-1">
|
|
|
|
|
{notification.content}
|
|
|
|
|
</p>
|
2025-12-29 10:41:23 +08:00
|
|
|
</div>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
|
|
|
|
<div className="py-8 px-4 text-center">
|
2026-01-05 09:14:41 +08:00
|
|
|
<InboxIcon size={18} />
|
2025-12-29 10:41:23 +08:00
|
|
|
<p className="mt-2 text-sm text-gray-500">暂无通知</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="border-t border-gray-100 p-2 text-center">
|
2025-12-29 14:37:03 +08:00
|
|
|
<Link
|
|
|
|
|
href="/notifications"
|
|
|
|
|
className="text-xs text-blue-600 hover:text-blue-800"
|
|
|
|
|
>
|
2025-12-29 10:41:23 +08:00
|
|
|
查看全部通知
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 分隔线 */}
|
|
|
|
|
<div className="hidden md:block h-8 w-px bg-gray-200"></div>
|
|
|
|
|
|
|
|
|
|
{/* 用户下拉菜单 */}
|
|
|
|
|
<div className="relative" ref={dropdownRef}>
|
2026-01-05 09:14:41 +08:00
|
|
|
<Button
|
2025-12-29 10:41:23 +08:00
|
|
|
onClick={() => setShowDropdown(!showDropdown)}
|
2026-01-05 09:14:41 +08:00
|
|
|
className="flex items-center space-x-2 rounded-lg text-gray-800 bg-gray-100 hover:bg-gray-100 p-2 transition-colors"
|
2025-12-29 10:41:23 +08:00
|
|
|
aria-label="用户菜单"
|
|
|
|
|
>
|
2025-12-29 14:37:03 +08:00
|
|
|
<div className="h-8 w-8 rounded-full bg-blue-100 text-blue-800 flex items-center justify-center overflow-hidden border-2 border-white shadow-sm">
|
2025-12-29 10:41:23 +08:00
|
|
|
<Image
|
|
|
|
|
src={currentUser.avatar}
|
|
|
|
|
alt="用户头像"
|
|
|
|
|
width={32}
|
|
|
|
|
height={32}
|
2025-12-29 14:37:03 +08:00
|
|
|
onError={e => {
|
2025-12-29 10:41:23 +08:00
|
|
|
const target = e.target as HTMLImageElement
|
2025-12-29 14:37:03 +08:00
|
|
|
target.style.display = "none"
|
2025-12-29 10:41:23 +08:00
|
|
|
target.parentElement!.innerHTML = currentUser.name.charAt(0)
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="hidden md:block text-left">
|
2025-12-29 14:37:03 +08:00
|
|
|
<p className="text-sm font-medium text-gray-800">
|
|
|
|
|
{currentUser.name}
|
|
|
|
|
</p>
|
2025-12-29 10:41:23 +08:00
|
|
|
<p className="text-xs text-gray-500">{currentUser.role}</p>
|
|
|
|
|
</div>
|
2026-01-05 09:14:41 +08:00
|
|
|
<ChevronDownIcon />
|
|
|
|
|
</Button>
|
2025-12-29 10:41:23 +08:00
|
|
|
|
|
|
|
|
{/* 用户下拉内容 */}
|
|
|
|
|
{showDropdown && (
|
|
|
|
|
<div className="absolute right-0 mt-2 w-56 bg-white rounded-lg shadow-lg py-2 z-20 border border-gray-200">
|
|
|
|
|
<div className="px-4 py-2 border-b border-gray-100 md:hidden">
|
|
|
|
|
<p className="font-medium text-gray-800">{currentUser.name}</p>
|
|
|
|
|
<p className="text-xs text-gray-500">{currentUser.role}</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="py-1">
|
2025-12-29 14:37:03 +08:00
|
|
|
<Link
|
|
|
|
|
href="/profile"
|
|
|
|
|
className="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
|
|
|
|
|
>
|
2026-01-05 09:14:41 +08:00
|
|
|
<UserIcon size={18} />
|
|
|
|
|
<span className="pl-3">个人资料</span>
|
2025-12-29 10:41:23 +08:00
|
|
|
</Link>
|
|
|
|
|
<Link
|
|
|
|
|
href="/settings/account"
|
2025-12-29 14:37:03 +08:00
|
|
|
className="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
|
|
|
|
|
>
|
2026-01-05 09:14:41 +08:00
|
|
|
<SettingsIcon size={18} />
|
|
|
|
|
<span className="pl-3">账号设置</span>
|
2025-12-29 10:41:23 +08:00
|
|
|
</Link>
|
|
|
|
|
<Link
|
2025-12-29 14:37:03 +08:00
|
|
|
href="/system/help"
|
|
|
|
|
className="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
|
|
|
|
|
>
|
2026-01-05 09:14:41 +08:00
|
|
|
<BadgeQuestionMarkIcon size={18} />
|
|
|
|
|
<span className="pl-3">帮助中心</span>
|
2025-12-29 10:41:23 +08:00
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="border-t border-gray-100 mt-1">
|
2025-12-29 14:37:03 +08:00
|
|
|
<Link
|
|
|
|
|
href="/login"
|
|
|
|
|
className="flex items-center px-4 py-2 text-sm text-red-600 hover:bg-gray-100"
|
|
|
|
|
>
|
2026-01-05 09:14:41 +08:00
|
|
|
<LogOutIcon size={18} />
|
|
|
|
|
<span className="pl-3">退出登录</span>
|
2025-12-29 10:41:23 +08:00
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
)
|
|
|
|
|
}
|