43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
export type AdminRouteId =
|
|
| 'overview'
|
|
| 'tables'
|
|
| 'debug'
|
|
| 'tracking'
|
|
| 'redeem'
|
|
| 'invite'
|
|
| 'tasks'
|
|
| 'creation-entry';
|
|
|
|
export interface AdminRouteDefinition {
|
|
id: AdminRouteId;
|
|
label: string;
|
|
hash: string;
|
|
}
|
|
|
|
export const adminRoutes: AdminRouteDefinition[] = [
|
|
{id: 'overview', label: '总览', hash: '#overview'},
|
|
{id: 'tables', label: '表查询', hash: '#tables'},
|
|
{id: 'debug', label: 'API 调试', hash: '#debug'},
|
|
{id: 'tracking', label: '埋点数据', hash: '#tracking'},
|
|
{id: 'redeem', label: '兑换码', hash: '#redeem'},
|
|
{id: 'invite', label: '邀请码', hash: '#invite'},
|
|
{id: 'tasks', label: '任务配置', hash: '#tasks'},
|
|
{id: 'creation-entry', label: '入口开关', hash: '#creation-entry'},
|
|
];
|
|
|
|
export function resolveAdminRoute(hash: string): AdminRouteId {
|
|
const normalizedHash = hash.trim().toLowerCase().split('?')[0] ?? '';
|
|
return (
|
|
adminRoutes.find((route) => route.hash === normalizedHash)?.id ??
|
|
'overview'
|
|
);
|
|
}
|
|
|
|
export function routeHash(routeId: AdminRouteId) {
|
|
return (
|
|
adminRoutes.find((route) => route.id === routeId)?.hash ??
|
|
adminRoutes[0]?.hash ??
|
|
'#overview'
|
|
);
|
|
}
|