53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
/** 后台单页应用可导航的路由标识,入口公告独立于入口开关维护。 */
|
||
export type AdminRouteId =
|
||
| 'overview'
|
||
| 'tables'
|
||
| 'debug'
|
||
| 'tracking'
|
||
| 'redeem'
|
||
| 'invite'
|
||
| 'tasks'
|
||
| 'recharge-products'
|
||
| 'creation-announcement'
|
||
| 'creation-entry'
|
||
| 'work-visibility';
|
||
|
||
/** 后台导航项定义,hash 是浏览器地址栏和移动底栏共用入口。 */
|
||
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: 'recharge-products', label: '充值商品', hash: '#recharge-products'},
|
||
{id: 'creation-announcement', label: '入口公告', hash: '#creation-announcement'},
|
||
{id: 'creation-entry', label: '入口开关', hash: '#creation-entry'},
|
||
{id: 'work-visibility', label: '作品可见性', hash: '#work-visibility'},
|
||
];
|
||
|
||
/** 根据地址栏 hash 解析后台路由,未知 hash 回落到总览页。 */
|
||
export function resolveAdminRoute(hash: string): AdminRouteId {
|
||
const normalizedHash = hash.trim().toLowerCase().split('?')[0] ?? '';
|
||
return (
|
||
adminRoutes.find((route) => route.hash === normalizedHash)?.id ??
|
||
'overview'
|
||
);
|
||
}
|
||
|
||
/** 根据后台路由标识反查 hash,供导航点击时同步地址栏。 */
|
||
export function routeHash(routeId: AdminRouteId) {
|
||
return (
|
||
adminRoutes.find((route) => route.id === routeId)?.hash ??
|
||
adminRoutes[0]?.hash ??
|
||
'#overview'
|
||
);
|
||
}
|