This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
import { Archive, ClipboardList, LayoutDashboard, RefreshCw, Trash2, Users } from "lucide-react";
|
||||
|
||||
export type RouteId = "dashboard" | "expenses" | "trash" | "admins" | "audit" | "update";
|
||||
|
||||
export interface AppRoute {
|
||||
id: RouteId;
|
||||
title: string;
|
||||
eyebrow: string;
|
||||
icon: LucideIcon;
|
||||
}
|
||||
|
||||
export const APP_ROUTES: readonly AppRoute[] = [
|
||||
{ id: "dashboard", title: "仪表盘", eyebrow: "概览", icon: LayoutDashboard },
|
||||
{ id: "expenses", title: "账目", eyebrow: "工作台", icon: ClipboardList },
|
||||
{ id: "trash", title: "回收站", eyebrow: "系统", icon: Trash2 },
|
||||
{ id: "admins", title: "管理员", eyebrow: "系统", icon: Users },
|
||||
{ id: "audit", title: "审计日志", eyebrow: "系统", icon: Archive },
|
||||
{ id: "update", title: "系统更新", eyebrow: "系统", icon: RefreshCw },
|
||||
];
|
||||
|
||||
export const DEFAULT_ROUTE_ID: RouteId = "dashboard";
|
||||
|
||||
export const ROUTE_PATHS: Readonly<Record<RouteId, string>> = {
|
||||
dashboard: "/",
|
||||
expenses: "/expenses",
|
||||
trash: "/trash",
|
||||
admins: "/admins",
|
||||
audit: "/audit",
|
||||
update: "/update",
|
||||
};
|
||||
|
||||
export function isRouteId(value: string): value is RouteId {
|
||||
return APP_ROUTES.some((route) => route.id === value);
|
||||
}
|
||||
|
||||
export function routePath(id: RouteId): string {
|
||||
return ROUTE_PATHS[id];
|
||||
}
|
||||
|
||||
export function routeIdFromPath(pathname: string): RouteId | undefined {
|
||||
const normalized = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
|
||||
if (normalized === "/dashboard") return DEFAULT_ROUTE_ID;
|
||||
return APP_ROUTES.find((route) => ROUTE_PATHS[route.id] === normalized)?.id;
|
||||
}
|
||||
|
||||
export function routeTitle(id: string): string {
|
||||
return APP_ROUTES.find((route) => route.id === id)?.title ?? "账目";
|
||||
}
|
||||
Reference in New Issue
Block a user