feat: 菜单侧栏标题与标签标题拆分并支持 tab_title 回退

This commit is contained in:
2026-09-05 18:27:53 +08:00
parent d99d8352b6
commit ebca4d093a
19 changed files with 119 additions and 21 deletions
@@ -118,9 +118,17 @@ interface RouteMeta {
*/
query?: Recordable;
/**
* 标题名称
* 标题名称(侧栏菜单)
*/
title: string;
/**
* 标签页标题(可空;空则回退 title;运行时 setTabTitle 写入 newTabTitle 优先生效)
*/
tabTitle?: string;
/**
* 运行时覆盖的标签标题(如概览页动态名)
*/
newTabTitle?: string;
}
// 定义递归类型以将 RouteRecordRaw 的 component 属性更改为 string
@@ -41,7 +41,8 @@ const style = computed(() => {
const tabsView = computed(() => {
return props.tabs.map((tab) => {
const { fullPath, meta, name, path, key } = tab || {};
const { affixTab, icon, newTabTitle, tabClosable, title } = meta || {};
const { affixTab, icon, newTabTitle, tabClosable, tabTitle, title } =
meta || {};
return {
affixTab: !!affixTab,
closable: Reflect.has(meta, 'tabClosable') ? !!tabClosable : true,
@@ -51,7 +52,8 @@ const tabsView = computed(() => {
meta,
name,
path,
title: (newTabTitle || title || name) as string,
// 运行时覆盖 > 配置 tabTitle > 侧栏 title
title: (newTabTitle || tabTitle || title || name) as string,
} as TabConfig;
});
});
@@ -48,7 +48,8 @@ const typeWithClass = computed(() => {
const tabsView = computed(() => {
return props.tabs.map((tab) => {
const { fullPath, meta, name, path, key } = tab || {};
const { affixTab, icon, newTabTitle, tabClosable, title } = meta || {};
const { affixTab, icon, newTabTitle, tabClosable, tabTitle, title } =
meta || {};
return {
affixTab: !!affixTab,
closable: Reflect.has(meta, 'tabClosable') ? !!tabClosable : true,
@@ -58,7 +59,8 @@ const tabsView = computed(() => {
meta,
name,
path,
title: (newTabTitle || title || name) as string,
// 运行时覆盖 > 配置 tabTitle > 侧栏 title
title: (newTabTitle || tabTitle || title || name) as string,
} as TabConfig;
});
});
@@ -87,27 +87,35 @@ export function useTabbar() {
function wrapperTabLocale(tab: RouteLocationNormalizedGeneric) {
const title = tab?.meta?.title;
const tabTitle = tab?.meta?.tabTitle;
let processedTitle = 'Unknown';
let processedTabTitle: string | undefined;
try {
if (title && typeof title === 'string' && title.trim()) {
// 尝试国际化处理
processedTitle = $t(title);
} else if (tab?.name) {
// 如果没有 title,使用路由名称
processedTitle = tab.name as string;
}
if (tabTitle && typeof tabTitle === 'string' && tabTitle.trim()) {
processedTabTitle = $t(tabTitle);
}
} catch (error) {
console.warn('国际化处理失败,使用原始标题:', title, error);
// 如果国际化失败,直接使用原始标题
processedTitle = title || (tab?.name as string) || 'Unknown';
processedTabTitle =
tabTitle && typeof tabTitle === 'string' && tabTitle.trim()
? tabTitle
: undefined;
}
return {
...tab,
meta: {
...tab?.meta,
title: processedTitle,
// 空则不写入,展示层回退 title
...(processedTabTitle ? { tabTitle: processedTabTitle } : { tabTitle: undefined }),
},
};
}
@@ -579,6 +579,7 @@ function cloneTab(route: TabDefinition): TabDefinition {
meta: {
...meta,
newTabTitle: meta.newTabTitle,
tabTitle: meta.tabTitle,
},
};
}