导航栏优化

This commit is contained in:
biss committed 2026-10-24 21:27:19 +08:00
1 parent eb7c20d0c4
commit c1599b38a0
3 files changed
+140 -37

No files matched your search

+1
View File
@@ -39,6 +39,7 @@ declare module 'vue' {
ElLink: typeof import('element-plus/es')['ElLink']
ElMenu: typeof import('element-plus/es')['ElMenu']
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
ElMenuItemGroup: typeof import('element-plus/es')['ElMenuItemGroup']
ElOption: typeof import('element-plus/es')['ElOption']
ElPagination: typeof import('element-plus/es')['ElPagination']
ElPopover: typeof import('element-plus/es')['ElPopover']
+114 -37
View File
@@ -30,6 +30,12 @@ interface NavigationGroup {
items: NavigationItem[]
}
interface NavigationCategory {
key: string
label: string
groups: NavigationGroup[]
}
const stableNavigationIds: Record<string, string> = {
'/dashboard': 'dashboard',
'/academic-calendar': 'academic-calendar',
@@ -457,16 +463,63 @@ const favoriteItems = computed(() => {
.filter((item): item is NavigationItem => Boolean(item))
})
const navigationGroups = computed<NavigationGroup[]>(() => [
const navigationCategoryBlueprints = [
{ key: 'workspace', label: '工作台', groupKeys: ['overview', 'statistics'] },
{
key: 'teaching',
label: '教学管理',
groupKeys: ['teaching-construction', 'teaching-operation', 'experiments'],
},
{
key: 'assessment',
label: '考试与成绩',
groupKeys: ['teaching-assessment', 'examinations'],
},
{
key: 'students',
label: '学生事务',
groupKeys: [
'student-status',
'student-development',
'physical-health',
'dormitory-management',
'graduation',
],
},
{ key: 'system', label: '系统管理', groupKeys: ['organization'] },
] as const
const systemNavigationCategories = computed<NavigationCategory[]>(() => {
const groupsByKey = new Map(
availableNavigationGroups.value.map((group) => [group.key, group]),
)
return navigationCategoryBlueprints
.map((category) => ({
key: category.key,
label: category.label,
groups: category.groupKeys
.map((key) => groupsByKey.get(key))
.filter((group): group is NavigationGroup => Boolean(group)),
}))
.filter((category) => category.groups.length > 0)
})
const navigationCategories = computed<NavigationCategory[]>(() => [
...(favoriteItems.value.length
? [{ key: 'favorites', label: '常用', items: favoriteItems.value }]
? [{
key: 'favorites',
label: '常用',
groups: [{ key: 'favorites', label: '常用功能', items: favoriteItems.value }],
}]
: []),
...availableNavigationGroups.value,
...systemNavigationCategories.value,
])
const activeGroupKey = computed(
() => availableNavigationGroups.value.find((group) =>
group.items.some((item) => item.path === route.path),
const activeCategoryKey = computed(
() => systemNavigationCategories.value.find((category) =>
category.groups.some((group) =>
group.items.some((item) => item.path === route.path),
),
)?.key ?? '',
)
@@ -493,9 +546,7 @@ const workspaceLabel = computed(() => {
const pageTitle = computed(() => {
if (route.path === '/account') return '个人账户'
const matchedItem = navigationGroups.value
.flatMap((group) => group.items)
.find((item) => item.path === route.path)
const matchedItem = allNavigationItems.value.find((item) => item.path === route.path)
return matchedItem?.label ?? '教务管理'
})
@@ -671,24 +722,37 @@ onMounted(() => {
class="horizontal-menu"
@select="handleNavigationSelect"
>
<template v-for="group in navigationGroups" :key="group.key">
<el-menu-item v-if="group.direct" :index="group.items[0].path">
{{ group.label }}
</el-menu-item>
<template v-for="category in navigationCategories" :key="category.key">
<el-sub-menu
v-else
:index="group.key"
:index="category.key"
:show-timeout="80"
:hide-timeout="180"
:popper-class="`navigation-category-popper navigation-category-popper--${category.key}`"
>
<template #title>{{ group.label }}</template>
<el-menu-item
v-for="item in group.items"
:key="item.path"
:index="group.key === 'favorites' ? `favorite:${item.path}` : item.path"
>
{{ item.label }}
</el-menu-item>
<template #title>{{ category.label }}</template>
<template v-for="group in category.groups" :key="group.key">
<el-menu-item-group
v-if="!['favorites', 'system'].includes(category.key)"
:title="group.label"
>
<el-menu-item
v-for="item in group.items"
:key="item.path"
:index="category.key === 'favorites' ? `favorite:${item.path}` : item.path"
>
{{ item.label }}
</el-menu-item>
</el-menu-item-group>
<template v-else>
<el-menu-item
v-for="item in group.items"
:key="item.path"
:index="category.key === 'favorites' ? `favorite:${item.path}` : item.path"
>
{{ item.label }}
</el-menu-item>
</template>
</template>
</el-sub-menu>
</template>
</el-menu>
@@ -716,24 +780,37 @@ onMounted(() => {
<el-menu
:default-active="route.path"
:default-openeds="activeGroupKey ? [activeGroupKey] : []"
:default-openeds="activeCategoryKey ? [activeCategoryKey] : []"
unique-opened
class="mobile-nav-menu"
@select="handleNavigationSelect"
>
<template v-for="group in navigationGroups" :key="group.key">
<el-menu-item v-if="group.direct" :index="group.items[0].path">
{{ group.label }}
</el-menu-item>
<el-sub-menu v-else :index="group.key">
<template #title>{{ group.label }}</template>
<el-menu-item
v-for="item in group.items"
:key="item.path"
:index="group.key === 'favorites' ? `favorite:${item.path}` : item.path"
>
{{ item.label }}
</el-menu-item>
<template v-for="category in navigationCategories" :key="category.key">
<el-sub-menu :index="category.key">
<template #title>{{ category.label }}</template>
<template v-for="group in category.groups" :key="group.key">
<el-menu-item-group
v-if="!['favorites', 'system'].includes(category.key)"
:title="group.label"
>
<el-menu-item
v-for="item in group.items"
:key="item.path"
:index="category.key === 'favorites' ? `favorite:${item.path}` : item.path"
>
{{ item.label }}
</el-menu-item>
</el-menu-item-group>
<template v-else>
<el-menu-item
v-for="item in group.items"
:key="item.path"
:index="category.key === 'favorites' ? `favorite:${item.path}` : item.path"
>
{{ item.label }}
</el-menu-item>
</template>
</template>
</el-sub-menu>
</template>
</el-menu>
+25
View File
@@ -88,6 +88,27 @@ button { cursor: pointer; }
font-weight: 650;
}
.horizontal-menu .el-sub-menu__icon-arrow { display: none; }
.navigation-category-popper .el-menu--popup { min-width: 220px; padding: 8px; }
.navigation-category-popper .el-menu-item-group__title {
padding: 10px 12px 5px; color: #7a8799; font-size: 11px; font-weight: 700;
letter-spacing: .08em;
}
.navigation-category-popper .el-menu-item {
min-width: 204px; height: 38px; margin: 2px 0; border-radius: 6px;
color: #344054; font-size: 13px;
}
.navigation-category-popper .el-menu-item:hover { color: var(--indigo); background: #f3f6fb; }
.navigation-category-popper .el-menu-item.is-active {
color: var(--indigo); background: #edf4f3; font-weight: 650;
}
.navigation-category-popper--workspace .el-menu--popup,
.navigation-category-popper--assessment .el-menu--popup {
display: grid; grid-template-columns: repeat(2, minmax(204px, 1fr)); gap: 0 8px;
}
.navigation-category-popper--teaching .el-menu--popup,
.navigation-category-popper--students .el-menu--popup {
display: grid; grid-template-columns: repeat(3, minmax(204px, 1fr)); gap: 0 8px;
}
.mobile-navigation {
position: fixed; inset: 0 auto 0 0; z-index: 30; width: 286px;
display: flex; flex-direction: column; overflow-y: auto; padding-top: var(--safe-area-top);
@@ -127,6 +148,10 @@ button { cursor: pointer; }
.mobile-nav-menu .el-menu-item.is-active { color: white; background: #2d478d; box-shadow: inset 3px 0 #46c6b5; }
.mobile-nav-menu .el-sub-menu .el-menu { background: rgba(0,0,0,.1); }
.mobile-nav-menu .el-sub-menu .el-menu-item { min-width: 0; padding-left: 40px !important; font-size: 12px; }
.mobile-nav-menu .el-menu-item-group__title {
padding: 12px 20px 4px 40px; color: #7f8bb1; font-size: 10px; font-weight: 700;
letter-spacing: .08em;
}
.main-area { min-width: 0; }
.menu-toggle {
width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.18);