Sidebar.tsx
2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use client";
import { useEffect, useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { BookOpen, Database, FileText, NotebookPen, Settings, UserRound } from "lucide-react";
import { cn } from "@/lib/utils";
import { fetchMe } from "@/lib/auth";
interface NavItem {
href: string;
label: string;
icon: typeof BookOpen;
/** 仅管理员可见 */
adminOnly?: boolean;
}
const NAV_ITEMS: NavItem[] = [
{ href: "/notes", label: "知识录入", icon: NotebookPen },
{ href: "/", label: "Wiki 原始文件", icon: FileText },
{ href: "/wiki-repo", label: "Wiki 知识库", icon: BookOpen },
{ href: "/rag", label: "RAG 工作台", icon: Database },
{ href: "/profile", label: "我的画像", icon: UserRound },
{ href: "/system/user", label: "系统管理", icon: Settings, adminOnly: true },
];
export default function Sidebar() {
const pathname = usePathname();
const [isAdmin, setIsAdmin] = useState(false);
useEffect(() => {
fetchMe()
.then((user) => setIsAdmin(Boolean(user?.isSuperadmin)))
.catch(() => setIsAdmin(false));
}, []);
const visible = NAV_ITEMS.filter((item) => !item.adminOnly || isAdmin);
return (
<aside className="w-16 flex flex-col items-center py-6 bg-slate-900 text-slate-400 shrink-0">
<div className="w-10 h-10 bg-blue-600 rounded-xl flex items-center justify-center text-white mb-8 shadow-lg shadow-blue-500/20">
<BookOpen className="w-6 h-6 fill-current" />
</div>
<nav className="flex-1 flex flex-col gap-6">
{visible.map(({ href, label, icon: Icon }) => {
const active = pathname === href || (href !== "/" && pathname.startsWith(href));
return (
<Link
key={href}
href={href}
className={cn(
"p-2 rounded-lg transition relative group",
active ? "bg-slate-800 text-white" : "hover:bg-slate-800 hover:text-slate-200"
)}
title={label}
>
<Icon className="w-5 h-5" />
<span className="absolute left-full ml-2 px-2 py-1 bg-slate-800 text-white text-xs rounded opacity-0 group-hover:opacity-100 pointer-events-none whitespace-nowrap z-50">
{label}
</span>
</Link>
);
})}
</nav>
</aside>
);
}