mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 02:29:19 +08:00
feat: 菜单侧栏标题与标签标题拆分并支持 tab_title 回退
This commit is contained in:
@@ -13,8 +13,10 @@ export namespace MenuDTO {
|
||||
name: string;
|
||||
/** 路由名称(Vue Router name,建议英文唯一) */
|
||||
routeName?: string;
|
||||
/** 菜单标题 */
|
||||
/** 菜单标题(侧栏) */
|
||||
title?: string;
|
||||
/** 标签页标题(可空;空则回退 title) */
|
||||
tabTitle?: string;
|
||||
/** 路由路径 */
|
||||
path?: string;
|
||||
/** 组件路径 */
|
||||
@@ -47,8 +49,10 @@ export namespace MenuDTO {
|
||||
name: string;
|
||||
/** 路由名称(Vue Router name,建议英文唯一) */
|
||||
routeName?: string;
|
||||
/** 菜单标题 */
|
||||
/** 菜单标题(侧栏) */
|
||||
title?: string;
|
||||
/** 标签页标题(可空;空则回退 title) */
|
||||
tabTitle?: string;
|
||||
/** 路由路径 */
|
||||
path?: string;
|
||||
/** 组件路径 */
|
||||
|
||||
@@ -16,8 +16,10 @@ export namespace MenuVO {
|
||||
name: string;
|
||||
/** 路由名称(Vue Router name) */
|
||||
routeName?: string;
|
||||
/** 菜单标题 */
|
||||
/** 菜单标题(侧栏) */
|
||||
title?: string;
|
||||
/** 标签页标题(可空;空则回退 title) */
|
||||
tabTitle?: string;
|
||||
/** 路由路径 */
|
||||
path?: string;
|
||||
/** 组件路径 */
|
||||
|
||||
@@ -72,8 +72,10 @@ export namespace UserVO {
|
||||
id: number;
|
||||
/** 父路由ID */
|
||||
parentId?: number;
|
||||
/** 路由标题 */
|
||||
/** 路由标题(侧栏) */
|
||||
title: string;
|
||||
/** 标签页标题(可空;空则回退 title) */
|
||||
tabTitle?: string;
|
||||
/** 路由图标 */
|
||||
icon?: string;
|
||||
/** 顺序 */
|
||||
|
||||
@@ -68,6 +68,8 @@ interface FormData {
|
||||
name: string;
|
||||
routeName: string;
|
||||
title: string;
|
||||
/** 标签页标题,空则回退菜单标题 */
|
||||
tabTitle: string;
|
||||
path: string;
|
||||
component: string;
|
||||
redirect: string;
|
||||
@@ -87,6 +89,7 @@ const formData = ref<FormData>({
|
||||
name: '',
|
||||
routeName: '',
|
||||
title: '',
|
||||
tabTitle: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
@@ -350,6 +353,7 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
|
||||
name: record.name,
|
||||
routeName: record.routeName || '',
|
||||
title: record.title || '',
|
||||
tabTitle: record.tabTitle || '',
|
||||
path: record.path || '',
|
||||
component: record.component || '',
|
||||
redirect: record.redirect || '',
|
||||
@@ -380,6 +384,7 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
|
||||
name: '',
|
||||
routeName: '',
|
||||
title: '',
|
||||
tabTitle: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
@@ -399,6 +404,7 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
|
||||
name: '',
|
||||
routeName: '',
|
||||
title: '',
|
||||
tabTitle: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
@@ -490,6 +496,7 @@ async function handleSubmit() {
|
||||
...formData.value,
|
||||
parentId: formData.value.parentId ?? null,
|
||||
routeName: formData.value.routeName?.trim() || null,
|
||||
tabTitle: formData.value.tabTitle?.trim() || null,
|
||||
icon: formData.value.icon?.trim() || null,
|
||||
iconSvg: formData.value.iconSvg?.trim() || null,
|
||||
superMenu: formData.value.superMenu ? 1 : 0,
|
||||
@@ -635,7 +642,17 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="菜单标题" name="title">
|
||||
<Input v-model:value="formData.title" placeholder="请输入菜单标题" />
|
||||
<Input
|
||||
v-model:value="formData.title"
|
||||
placeholder="侧边菜单显示名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="标签标题" name="tabTitle">
|
||||
<Input
|
||||
v-model:value="formData.tabTitle"
|
||||
placeholder="可空;空则标签用菜单标题"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="路由路径" name="path">
|
||||
|
||||
@@ -92,6 +92,12 @@ const menuTableBaseColumns: VxeGridProps<any>['columns'] = [
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'tabTitle',
|
||||
title: '标签标题',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'icon',
|
||||
title: '图标',
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user