Merge origin/develop into feature/a-card-operations
This commit is contained in:
@@ -62,6 +62,42 @@ export type NavigationItem = {
|
||||
children?: NavigationItem[];
|
||||
};
|
||||
|
||||
export function pathForPage(page: ActivePage): string {
|
||||
if (page === "home") return "/workbench";
|
||||
return `/${page}`;
|
||||
}
|
||||
|
||||
function normalizePath(pathname: string): string {
|
||||
const trimmed = pathname.replace(/\/+$/, "");
|
||||
return trimmed || "/";
|
||||
}
|
||||
|
||||
/** 根据当前 pathname 解析顶栏标题:二级菜单显示子项名称,一级菜单显示自身名称。 */
|
||||
export function pageTitleFromPath(pathname: string): string {
|
||||
const path = normalizePath(pathname);
|
||||
|
||||
for (const item of navigation) {
|
||||
if (item.children) {
|
||||
for (const child of item.children) {
|
||||
const childPath =
|
||||
child.activePath ?? `${pathForPage(child.page)}/${child.sub}`;
|
||||
if (path === childPath) {
|
||||
return child.label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const item of navigation) {
|
||||
const itemPath = item.activePath ?? pathForPage(item.page);
|
||||
if (path === itemPath) {
|
||||
return item.label;
|
||||
}
|
||||
}
|
||||
|
||||
return "工作台";
|
||||
}
|
||||
|
||||
export const navigation: NavigationItem[] = [
|
||||
{
|
||||
label: "工作台",
|
||||
|
||||
Reference in New Issue
Block a user