- pnpm workspace: apps/{web,server}, packages/{contracts,db,domain,adapters,tasks,agent,testkit}
- server: Hono + zod-openapi, API Key auth with scopes, redacting pino logger, SSE event bus with replay, worker heartbeat
- db: Kysely + pg, file migrator, 0001_init (settings/api_key/audit_event/outbox_event)
- web: React Router 7 SPA console shell with 12 workspace placeholders, uhd_web tokens/ui/guard scripts
- docs: ADR-001 (Node over Deno), dev runbook, design system rules
Co-Authored-By: Claude Fable 5.1 <[email protected]>
209 lines
8.0 KiB
TypeScript
209 lines
8.0 KiB
TypeScript
import { ChevronLeft, ChevronRight, Clapperboard, Menu } from "lucide-react";
|
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
import { Link, NavLink, Outlet, useLocation } from "react-router";
|
|
import { ApiKeyDialog } from "~/components/console/api-key-dialog";
|
|
import { findNavItem, NAV_GROUPS, NAV_ITEMS, type NavGroup } from "~/components/console/nav";
|
|
import PrismLeak from "~/components/prism-leak";
|
|
import { ThemeToggle } from "~/components/theme-toggle";
|
|
import { Button } from "~/components/ui/button";
|
|
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "~/components/ui/sheet";
|
|
import { cn } from "~/lib/utils";
|
|
|
|
const PORTAL_NAME = "媒体自动化";
|
|
|
|
// ─── 展开态导航:选中项由一枚玻璃滑块(seg-thumb)滑到激活链接背后 ───
|
|
function ExpandedNav({ groups, onNavigate }: { groups: NavGroup[]; onNavigate?: () => void }) {
|
|
const location = useLocation();
|
|
const navRef = useRef<HTMLElement>(null);
|
|
const [pill, setPill] = useState<{ x: number; y: number; w: number; h: number } | null>(null);
|
|
|
|
const measure = useCallback(() => {
|
|
const nav = navRef.current;
|
|
if (!nav) return;
|
|
const active = nav.querySelector<HTMLElement>('[aria-current="page"]');
|
|
if (!active) {
|
|
setPill(null);
|
|
return;
|
|
}
|
|
const navRect = nav.getBoundingClientRect();
|
|
const rect = active.getBoundingClientRect();
|
|
setPill({ x: rect.left - navRect.left, y: rect.top - navRect.top + nav.scrollTop, w: rect.width, h: rect.height });
|
|
}, []);
|
|
|
|
// biome-ignore lint/correctness/useExhaustiveDependencies: 路由变化时重新量测
|
|
useLayoutEffect(() => {
|
|
measure();
|
|
}, [measure, location.pathname]);
|
|
|
|
useEffect(() => {
|
|
window.addEventListener("resize", measure);
|
|
return () => window.removeEventListener("resize", measure);
|
|
}, [measure]);
|
|
|
|
return (
|
|
<nav ref={navRef} className="relative flex-1 space-y-4 overflow-y-auto px-2.5 py-4">
|
|
{pill ? (
|
|
<span
|
|
aria-hidden
|
|
className="tab-slider seg-thumb pointer-events-none absolute top-0 left-0 -z-[1] rounded-lg"
|
|
style={{ transform: `translate(${pill.x}px, ${pill.y}px)`, width: pill.w, height: pill.h }}
|
|
/>
|
|
) : null}
|
|
{groups.map((group) => (
|
|
<div key={group.title}>
|
|
<p className="mb-1 px-2 text-micro font-semibold tracking-[0.15em] text-muted-foreground/75 uppercase">
|
|
{group.title}
|
|
</p>
|
|
<div className="space-y-0.5">
|
|
{group.items.map((item) => (
|
|
<NavLink
|
|
key={item.to}
|
|
to={item.to}
|
|
end={item.to === "/"}
|
|
onClick={onNavigate}
|
|
className={({ isActive }) =>
|
|
cn(
|
|
"flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors duration-base",
|
|
isActive
|
|
? "text-foreground"
|
|
: "text-muted-foreground hover:bg-foreground/[0.04] hover:text-foreground",
|
|
)
|
|
}
|
|
>
|
|
{({ isActive }) => (
|
|
<>
|
|
<item.icon className={cn("h-4 w-4 shrink-0", isActive && "text-primary")} />
|
|
<span className="flex-1 truncate">{item.label}</span>
|
|
</>
|
|
)}
|
|
</NavLink>
|
|
))}
|
|
</div>
|
|
</div>
|
|
))}
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
// ─── 折叠态:只显示图标 ───
|
|
function CollapsedNav() {
|
|
return (
|
|
<nav className="flex flex-1 flex-col items-center gap-1 overflow-y-auto py-4">
|
|
{NAV_ITEMS.map((item) => (
|
|
<NavLink
|
|
key={item.to}
|
|
to={item.to}
|
|
end={item.to === "/"}
|
|
title={item.label}
|
|
className={({ isActive }) =>
|
|
cn(
|
|
"flex h-10 w-10 items-center justify-center rounded-xl transition-colors duration-micro",
|
|
isActive
|
|
? "seg-thumb text-primary"
|
|
: "text-muted-foreground hover:bg-foreground/[0.04] hover:text-foreground",
|
|
)
|
|
}
|
|
>
|
|
<item.icon className="h-[18px] w-[18px]" />
|
|
</NavLink>
|
|
))}
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
function Brand({ collapsed = false }: { collapsed?: boolean }) {
|
|
return (
|
|
<Link
|
|
to="/"
|
|
className={cn(
|
|
"flex items-center transition-opacity hover:opacity-80",
|
|
collapsed ? "w-full justify-center" : "gap-2",
|
|
)}
|
|
>
|
|
<span className="grid h-7 w-7 place-items-center rounded-lg pill-selected">
|
|
<Clapperboard className="h-4 w-4" />
|
|
</span>
|
|
{!collapsed && <p className="text-xs font-bold tracking-wide text-foreground">UHD Media Tool</p>}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
export default function ConsoleLayout() {
|
|
const location = useLocation();
|
|
const [collapsed, setCollapsed] = useState(false);
|
|
const [sheetOpen, setSheetOpen] = useState(false);
|
|
const activeLabel = findNavItem(location.pathname)?.label ?? PORTAL_NAME;
|
|
|
|
return (
|
|
<div className="app-scrollbars relative isolate flex min-h-screen overflow-x-hidden bg-background">
|
|
<div className="pointer-events-none fixed inset-0 -z-10 bg-page-glow" />
|
|
<PrismLeak className="-z-10" />
|
|
|
|
{/* 桌面端侧栏 */}
|
|
<aside
|
|
className={cn(
|
|
"pg-chrome pg-chrome-side fixed inset-y-0 left-0 z-30 hidden flex-col border-r transition-all duration-layout select-none xl:flex",
|
|
collapsed ? "w-[60px]" : "w-60",
|
|
)}
|
|
>
|
|
<button
|
|
type="button"
|
|
onClick={() => setCollapsed((v) => !v)}
|
|
className="absolute top-3 -right-4 z-40 flex h-8 w-8 cursor-pointer items-center justify-center rounded-full border border-[var(--shell-border)] bg-background text-muted-foreground shadow-md transition-all duration-base hover:scale-110 hover:bg-foreground/[0.04] hover:text-foreground"
|
|
title={collapsed ? "展开侧边栏" : "收起侧边栏"}
|
|
>
|
|
{collapsed ? <ChevronRight className="h-4 w-4" /> : <ChevronLeft className="h-4 w-4" />}
|
|
</button>
|
|
<div
|
|
className={cn(
|
|
"flex h-14 shrink-0 items-center border-b border-[var(--shell-border)]",
|
|
collapsed ? "justify-center px-0" : "px-4",
|
|
)}
|
|
>
|
|
<Brand collapsed={collapsed} />
|
|
</div>
|
|
{collapsed ? <CollapsedNav /> : <ExpandedNav groups={NAV_GROUPS} />}
|
|
</aside>
|
|
|
|
{/* 主内容区 */}
|
|
<div
|
|
className={cn(
|
|
"relative flex min-h-screen min-w-0 flex-1 flex-col transition-all duration-layout",
|
|
collapsed ? "xl:ml-[60px]" : "xl:ml-60",
|
|
)}
|
|
>
|
|
<header className="pg-chrome sticky top-0 z-20 flex h-14 items-center border-b px-4 md:px-6">
|
|
<div className="flex min-w-0 items-center gap-3">
|
|
<Sheet open={sheetOpen} onOpenChange={setSheetOpen}>
|
|
<SheetTrigger asChild>
|
|
<Button variant="ghost" size="icon" className="h-8 w-8 xl:hidden" aria-label="打开导航">
|
|
<Menu className="h-4 w-4" />
|
|
</Button>
|
|
</SheetTrigger>
|
|
<SheetContent side="left" className="w-64 p-0 select-none">
|
|
<SheetHeader className="border-b border-[var(--shell-border)] px-5 py-4">
|
|
<SheetTitle className="text-sm">
|
|
<Brand />
|
|
</SheetTitle>
|
|
</SheetHeader>
|
|
<ExpandedNav groups={NAV_GROUPS} onNavigate={() => setSheetOpen(false)} />
|
|
</SheetContent>
|
|
</Sheet>
|
|
<span className="truncate text-sm font-semibold text-foreground">{activeLabel}</span>
|
|
</div>
|
|
<div className="ml-auto flex items-center gap-2">
|
|
<ApiKeyDialog />
|
|
<ThemeToggle />
|
|
</div>
|
|
</header>
|
|
|
|
<main className="relative flex-1 overflow-x-hidden px-4 py-6 md:px-6 md:py-8">
|
|
<div key={location.pathname} className="mx-auto max-w-6xl motion-safe:animate-blur-in">
|
|
<Outlet />
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|