Files
UHD_Media_Tool/apps/web/app/components/console/nav.ts
T
rootandClaude Opus 5.5 baf2d6ea04 feat(web): split plan page from tasks (FE-6)
- Nav overview group: 首页 / 任务 / 计划 / Agent 会话; tasks page drops the plan tab
- /console/tasks?tab=plan[&job=] redirects to /console/schedules[?job=]
- Plan page: 自动任务 compact grouped list (switch, interval preset/custom, last result,
  countdown, failure reason, run now/skip/run records) and Agent 巡检 cards (goal,
  allowlist, budget, upstream/model, trigger, cost per run, recent sessions); split stats
- Home plan band: two counts linking to #auto / #checks
- Docs: console-ia §7.4a, glossary, schedules runbook; smoke routes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-29 17:13:54 +08:00

182 lines
5.1 KiB
TypeScript

import {
Bot,
CalendarClock,
CalendarCog,
Download,
FileStack,
FolderTree,
Gauge,
Globe,
House,
Library,
ListChecks,
ListTodo,
type LucideIcon,
Rss,
ScrollText,
Settings,
} from "lucide-react";
export type NavItem = {
to: string;
label: string;
icon: LucideIcon;
description: string;
};
export type NavGroup = { title: string; items: NavItem[] };
/** 控制台路由前缀 */
export const CONSOLE_BASE = "/console";
/** 拼控制台路径:consolePath("library", id) → /console/library/<id> */
export function consolePath(...segments: (string | number)[]): string {
const rest = segments.map((s) => encodeURIComponent(String(s))).join("/");
return rest ? `${CONSOLE_BASE}/${rest}` : CONSOLE_BASE;
}
/**
* 侧栏 5 组 15 项(IA-3 定稿清单 14 项 + FE-6 从任务页拆出的"计划",docs/plan/00-first-version-plan.md §8):概览 → 资源 → 订阅 → 整理 → 系统。
* 待处理不进侧栏,由顶栏收件箱打开;移动端抽屉用同一份表。
*/
export const NAV_GROUPS: NavGroup[] = [
{
title: "概览",
items: [
{
to: "/console",
label: "首页",
icon: House,
description: "正在进行、需要处理、计划、最近结果与运行状态",
},
{
to: "/console/tasks",
label: "任务",
icon: ListTodo,
description: "每次运行都是一条任务:定时、事件、手动、Agent 触发都在这里",
},
{
to: "/console/schedules",
label: "计划",
icon: CalendarCog,
description: "定时任务的开关、间隔和下次运行:自动任务与 Agent 巡检",
},
{
to: "/console/agent",
label: "Agent 会话",
icon: Bot,
description: "交代目标,Agent 在授权内执行并汇报",
},
],
},
{
title: "资源",
items: [
{
to: "/console/sites",
label: "站点",
icon: Globe,
description: "站点、凭证、账号数据与健康;资源、快照与 Feed",
},
{ to: "/console/sources", label: "RSS 订阅", icon: Rss, description: "全部 Feed 与抓取状态" },
],
},
{
title: "订阅",
items: [
{ to: "/console/subscriptions", label: "订阅", icon: CalendarClock, description: "单次收录与持续追踪" },
{ to: "/console/rules", label: "规则", icon: ListChecks, description: "收录策略与偏好标签" },
],
},
{
title: "整理",
items: [
{ to: "/console/downloads", label: "下载面板", icon: Download, description: "下载任务、下载计划与缓存水位" },
{
to: "/console/organize",
label: "整理记录",
icon: FileStack,
description: "每次整理的前后路径与逐文件结果",
},
{
to: "/console/files",
label: "文件管理",
icon: FolderTree,
description: "浏览登记目录,改名、移动、删除与整理",
},
{
to: "/console/library",
label: "媒体概览",
icon: Library,
description: "作品、季 / 集、版本目标、外部身份与待识别资源",
},
],
},
{
title: "系统",
items: [
{
to: "/console/settings",
label: "设置",
icon: Settings,
description: "下载器、媒体服务器、库根、站点账号、Agent 上游与自动化",
},
{
to: "/console/audit",
label: "审计",
icon: ScrollText,
description: "登录、设置、密钥、任务操作的留痕",
},
{
to: "/console/status",
label: "运行状态",
icon: Gauge,
description: "进程心跳、事件循环、数据库、磁盘与挂载根",
},
],
},
];
/** 不在侧栏但有页面的路由:顶栏标题用 */
const EXTRA_TITLES: Record<string, string> = {
"/console/inbox": "待处理",
"/console/preferences": "偏好标签",
"/console/search": "搜索",
};
export const NAV_ITEMS = NAV_GROUPS.flatMap((g) => g.items);
/** 设置页深链(IA-2):`/console/settings#分区[/节]`。调用方只认新分区名 */
export type SettingsSection =
| "automation"
| "sites"
| "downloaders"
| "library"
| "media-servers"
| "metadata"
| "agent"
| "api-keys"
| "account";
export function settingsPath(section: SettingsSection, anchor?: string): string {
return `${CONSOLE_BASE}/settings#${section}${anchor ? `/${anchor}` : ""}`;
}
/** 按路径找当前导航项(最长前缀匹配) */
export function findNavItem(pathname: string): NavItem | undefined {
return (
NAV_ITEMS.find((i) => i.to === pathname.replace(/\/+$/, "")) ??
NAV_ITEMS.filter((i) => i.to !== CONSOLE_BASE && pathname.startsWith(`${i.to}/`)).sort(
(a, b) => b.to.length - a.to.length,
)[0]
);
}
/** 顶栏标题:导航项名,或不在侧栏的页面名 */
export function pageTitle(pathname: string): string | undefined {
const path = pathname.replace(/\/+$/, "");
return (
findNavItem(pathname)?.label ??
EXTRA_TITLES[path] ??
(path.startsWith("/console/media/tmdb/") ? "作品详情" : undefined)
);
}