diff --git a/components/header.tsx b/components/header.tsx index 93fbd9e..cbec558 100644 --- a/components/header.tsx +++ b/components/header.tsx @@ -40,18 +40,37 @@ const roleLabels: Record = { owner: "店主", } -const navLinks = [ - { href: "/", label: "首页" }, - { href: "/community", label: "社区" }, - { href: "/orders", label: "订单" }, - { href: "/chat", label: "消息" }, -] - export function Header() { const [mobileOpen, setMobileOpen] = useState(false) const pathname = usePathname() const router = useRouter() - const { isAuthenticated, currentRole, switchRole, logout } = useAuthStore() + const { isAuthenticated, currentRole, verifiedRoles, switchRole, logout } = useAuthStore() + + const navLinks = + currentRole === "consumer" + ? [ + { href: "/", label: "首页" }, + { href: "/search", label: "找陪玩" }, + { href: "/community", label: "社区" }, + { href: "/chat", label: "消息" }, + ] + : [ + { href: "/", label: "首页" }, + { href: "/community", label: "社区" }, + { href: "/orders", label: "订单" }, + { href: "/chat", label: "消息" }, + { href: "/dashboard", label: "管理后台" }, + ] + + const availableRoles = (Object.entries(roleLabels) as [UserRole, string][]).filter(([role]) => + verifiedRoles.includes(role), + ) + + const handleRoleSwitch = (role: UserRole) => { + switchRole(role) + router.push(role === "consumer" ? "/" : "/dashboard") + setMobileOpen(false) + } const unreadCount = mockNotifications.filter((n) => !n.read).length @@ -106,10 +125,10 @@ export function Header() { 切换身份 - {(Object.entries(roleLabels) as [UserRole, string][]).map(([role, label]) => ( + {availableRoles.map(([role, label]) => ( switchRole(role)} + onClick={() => handleRoleSwitch(role)} className={cn(currentRole === role && "bg-accent")} > {label} @@ -275,15 +294,6 @@ export function Header() { > 设置 - {(currentRole === "player" || currentRole === "owner") && ( - setMobileOpen(false)} - className="px-3 py-2 rounded-md text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-accent/50" - > - 管理后台 - - )} )} @@ -292,13 +302,13 @@ export function Header() {

切换身份

- {(Object.entries(roleLabels) as [UserRole, string][]).map(([role, label]) => ( + {availableRoles.map(([role, label]) => (