| 1 | /* 账户层壳:Profile / Administration 的宿主。 |
| 2 | 与 KB 无关,所以没有 KB 切换器、没有 tab 导航——只有字标、返回、用户菜单。 */ |
| 3 | import { useQuery } from "@tanstack/react-query"; |
| 4 | import { Link, Outlet, useNavigate } from "@tanstack/react-router"; |
| 5 | import { usePageTitle } from "../useTitle"; |
| 6 | import { BookMarked, KeyRound, ShieldCheck, UserRound } from "lucide-react"; |
| 7 | import { api, ApiError } from "../api"; |
| 8 | import { S } from "../i18n"; |
| 9 | import { GithubMark, RAIL_CLS, SectionMark } from "../ui"; |
| 10 | import { ServerDown } from "./ServerDown"; |
| 11 | import { UserMenu } from "./UserMenu"; |
| 12 | |
| 13 | export function AccountShell() { |
| 14 | const navigate = useNavigate(); |
| 15 | const me = useQuery({ queryKey: ["me"], queryFn: api.me }); |
| 16 | const health = useQuery({ queryKey: ["health"], queryFn: api.health, staleTime: Infinity }); |
| 17 | // 标题:`Utopia | Persona`——账户区整体一个名字,不逐页细分 |
| 18 | usePageTitle(S.app.name, S.account.titleTag); |
| 19 | |
| 20 | if (me.isPending) { |
| 21 | return ( |
| 22 | <div className="min-h-screen flex items-center justify-center text-neutral-500 text-sm"> |
| 23 | {S.nav.loading} |
| 24 | </div> |
| 25 | ); |
| 26 | } |
| 27 | if (me.isError) { |
| 28 | if (me.error instanceof ApiError && me.error.status === 401) { |
| 29 | navigate({ to: "/login" }); |
| 30 | return null; |
| 31 | } |
| 32 | return <ServerDown />; |
| 33 | } |
| 34 | |
| 35 | const rail = |
| 36 | "flex items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] text-neutral-400 hover:bg-white/[0.05] hover:text-neutral-200"; |
| 37 | const railActive = "flex items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] u-nav-active"; |
| 38 | |
| 39 | return ( |
| 40 | <div className="h-screen flex flex-col overflow-hidden u-arrive"> |
| 41 | {/* 顶栏与 Docs 页同构:分区字标(点击回城)+ 返回 + GitHub·版本 + 用户 */} |
| 42 | <header className="glass-strong relative z-40 border-x-0 border-t-0 h-14 shrink-0 flex items-center px-5"> |
| 43 | <SectionMark text={S.account.brand} title={S.docs.backTitle} /> |
| 44 | <div className="ml-auto flex items-center gap-1.5"> |
| 45 | <Link |
| 46 | to="/" |
| 47 | className="px-2 py-1 rounded-lg text-[12.5px] text-neutral-500 hover:text-neutral-200 hover:bg-white/[0.05] transition-colors" |
| 48 | > |
| 49 | {S.account.backToApp} |
| 50 | </Link> |
| 51 | <a |
| 52 | href={S.login.githubUrl} |
| 53 | target="_blank" |
| 54 | rel="noreferrer" |
| 55 | title="GitHub" |
| 56 | className="flex items-center gap-1.5 rounded-full border border-white/10 px-2.5 py-1 text-neutral-500 hover:text-neutral-200 hover:border-white/25 transition-colors" |
| 57 | > |
| 58 | <GithubMark size={13} /> |
| 59 | {health.data && <span className="u-num text-[11px]">v{health.data.version}</span>} |
| 60 | </a> |
| 61 | <div className="ml-1.5"> |
| 62 | <UserMenu user={me.data} /> |
| 63 | </div> |
| 64 | </div> |
| 65 | </header> |
| 66 | |
| 67 | <div className="flex-1 min-h-0 flex"> |
| 68 | {/* 账户导航栏(仅两项,管理员多一项) */} |
| 69 | <aside className={`${RAIL_CLS} p-3 space-y-0.5`}> |
| 70 | {/* exact:/account 是 /account/kbs 的前缀,默认前缀匹配会双亮 */} |
| 71 | <Link |
| 72 | to="/account" |
| 73 | activeOptions={{ exact: true }} |
| 74 | className={rail} |
| 75 | activeProps={{ className: railActive }} |
| 76 | > |
| 77 | <UserRound size={14} /> |
| 78 | {S.account.profile} |
| 79 | </Link> |
| 80 | <Link to="/account/kbs" className={rail} activeProps={{ className: railActive }}> |
| 81 | <BookMarked size={14} /> |
| 82 | {S.account.kbsNav} |
| 83 | </Link> |
| 84 | <Link to="/account/tokens" className={rail} activeProps={{ className: railActive }}> |
| 85 | <KeyRound size={14} /> |
| 86 | {S.account.tokensNav} |
| 87 | </Link> |
| 88 | {me.data.is_admin && ( |
| 89 | <Link to="/admin" className={rail} activeProps={{ className: railActive }}> |
| 90 | <ShieldCheck size={14} /> |
| 91 | {S.account.administration} |
| 92 | </Link> |
| 93 | )} |
| 94 | </aside> |
| 95 | <main className="flex-1 min-w-0 overflow-y-auto u-scroll"> |
| 96 | <Outlet /> |
| 97 | </main> |
| 98 | </div> |
| 99 | </div> |
| 100 | ); |
| 101 | } |