feat(navMenuHorizontal): add secondary menu navigation and styling fixes; align submenu to left, dropdown to right, and correct icon alignment

This commit is contained in:
Asoka 2025-06-05 14:21:39 +08:00
parent 1bf9c07ab7
commit c23a89d222

View File

@ -1,5 +1,22 @@
<template> <template>
<div class="el-menu-horizontal-warp"> <div class="el-menu-horizontal-warp">
<!-- 新增二级菜单导航 -->
<el-menu
class="sub-menu"
mode="horizontal"
:default-active="currentSubMenuPath"
background-color="transparent"
@select="onSubMenuClick"
>
<el-menu-item
v-for="item in subMenuList"
:index="item.path"
:key="item.path"
>
<SvgIcon :name="item.meta?.icon" class="submenu-icon" :size="20" />
<span>{{ $t(item.meta?.title) }}</span>
</el-menu-item>
</el-menu>
<!-- 将四个模块合并为一个下拉菜单类似语言切换 --> <!-- 将四个模块合并为一个下拉菜单类似语言切换 -->
<el-dropdown <el-dropdown
:show-timeout="70" :show-timeout="70"
@ -9,7 +26,7 @@
class="module-dropdown" class="module-dropdown"
> >
<div class="module-selector"> <div class="module-selector">
<SvgIcon :name="currentModule.icon" /> <SvgIcon :name="currentModule.icon" :size="20" />
<span class="module-title">{{ currentModule.title }}</span> <span class="module-title">{{ currentModule.title }}</span>
<el-icon class="el-icon--right"> <el-icon class="el-icon--right">
<ele-ArrowDown /> <ele-ArrowDown />
@ -174,26 +191,65 @@ const onModuleCommand = (path: string) => {
return return
} }
// //
if (selectedModule.children && selectedModule.children.length > 0) { if (selectedModule.children && selectedModule.children.length > 0) {
const firstChild = selectedModule.children.find((child: RouteItem) => !child.meta?.isHide) const firstChild = selectedModule.children.find((child: RouteItem) => !child.meta?.isHide)
if (firstChild) { if (firstChild) {
router.push(firstChild.path) router.push(firstChild.path)
//
mittBus.emit('setSendColumnsChildren', setSendSubMenuChildren(firstChild.path))
} else { } else {
router.push(selectedModule.path) router.push(selectedModule.path)
mittBus.emit('setSendColumnsChildren', { children: [] })
} }
} else { } else {
//
router.push(selectedModule.path) router.push(selectedModule.path)
mittBus.emit('setSendColumnsChildren', { children: [] })
} }
// //
mittBus.emit('getBreadcrumbIndexSetFilterRoutes') mittBus.emit('getBreadcrumbIndexSetFilterRoutes')
if (themeConfig.value.layout === 'classic' && themeConfig.value.isClassicSplitMenu) { if (themeConfig.value.layout === 'classic' && themeConfig.value.isClassicSplitMenu) {
mittBus.emit('setSendClassicChildren', setSendClassicChildren(path)) mittBus.emit('setSendClassicChildren', setSendClassicChildren(path))
} }
} }
//
const subMenuList = computed(() => {
const module = menuLists.value.find(item => item.path === state.currentModulePath)
return module && module.children
? module.children.filter((child: RouteRecordRaw) => !child.meta?.isHide)
: []
})
//
const currentSubMenuPath = computed(() => {
const sub = subMenuList.value.find((child: RouteRecordRaw) => route.path.startsWith(child.path))
return sub?.path || subMenuList.value[0]?.path || ''
})
//
const setSendSubMenuChildren = (path: string) => {
let res: MittMenu = { children: [] }
const module = menuLists.value.find(item => item.path === state.currentModulePath)
if (module && module.children) {
const sub = module.children.find((child: RouteRecordRaw) => child.path === path)
if (sub) {
res.item = { ...sub }
res.children = sub.children ? [...sub.children] : []
}
}
return res
}
//
const onSubMenuClick = (path: string) => {
router.push(path)
//
mittBus.emit('getBreadcrumbIndexSetFilterRoutes')
mittBus.emit('setSendColumnsChildren', setSendSubMenuChildren(path))
}
// //
const isCurrentModule = (path: string): boolean => { const isCurrentModule = (path: string): boolean => {
return state.currentModulePath === path || route.path.startsWith(path) return state.currentModulePath === path || route.path.startsWith(path)
@ -242,42 +298,90 @@ onBeforeRouteUpdate((to) => {
<style scoped lang="scss"> <style scoped lang="scss">
.el-menu-horizontal-warp { .el-menu-horizontal-warp {
height: 100%;
display: flex;
align-items: center;
flex: 1; flex: 1;
overflow: hidden; padding: 0 16px;
margin-right: 30px; background: var(--el-bg-color);
border-bottom: 1px solid var(--el-border-color-light);
/* 二级菜单,左侧 */
.sub-menu {
padding: 0 !important;
margin: 0 !important;
height: 100%;
overflow-x: auto;
white-space: nowrap;
&::-webkit-scrollbar { display: none; }
.el-menu-item {
min-width: 150px;
height: 100%;
line-height: initial;
margin: 0 12px;
padding: 0;
color: var(--next-bg-topBarColor);
display: flex;
align-items: center;
gap: 6px;
font-size: 14px;
border-bottom: 2px solid transparent;
transition: color 0.3s, border-color 0.3s;
.submenu-icon {
margin-top: 0;
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 4px;
}
&.is-active {
color: var(--el-color-primary);
border-color: var(--el-color-primary);
font-weight: 600;
}
&:hover { color: var(--el-color-primary); }
}
}
/* 模块切换下拉,右侧 */
.module-dropdown {
flex: none;
margin-left: 16px;
height: 100%;
display: flex;
align-items: center;
.module-selector {
display: flex; display: flex;
align-items: center; align-items: center;
height: 100%; height: 100%;
line-height: initial;
.module-dropdown { padding: 0 12px;
.module-selector { gap: 8px;
height: 50px;
line-height: 50px;
padding: 0 10px;
cursor: pointer;
display: flex;
align-items: center;
gap: 5px;
color: var(--next-bg-topBarColor); color: var(--next-bg-topBarColor);
background: transparent; background: var(--el-bg-color);
border: none;
border-radius: 6px;
font-size: 14px; font-size: 14px;
transition: all 0.3s; transition: background 0.3s, color 0.3s, border-color 0.3s;
white-space: nowrap;
.module-title {
font-weight: 500;
}
.module-title { font-weight: 500; }
&:hover { &:hover {
background: var(--next-color-user-hover); background: var(--el-color-primary-light-9);
color: var(--next-bg-topBarColor); color: var(--el-color-primary);
border-color: var(--el-color-primary-light-7);
} }
/* ensure module icon and dropdown arrow align */
.el-icon, i.el-icon {
font-size: 20px;
line-height: 20px;
} }
} }
//
:deep(.el-dropdown-menu) { :deep(.el-dropdown-menu) {
border-radius: 8px; border-radius: 8px;
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
@ -288,9 +392,9 @@ onBeforeRouteUpdate((to) => {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 12px 16px; padding: 12px 16px;
transition: all 0.3s;
border-radius: 6px;
margin: 4px 6px; margin: 4px 6px;
border-radius: 6px;
transition: background 0.3s, color 0.3s;
.dropdown-icon { .dropdown-icon {
margin-right: 10px; margin-right: 10px;
@ -298,44 +402,15 @@ onBeforeRouteUpdate((to) => {
width: 16px; width: 16px;
height: 16px; height: 16px;
} }
&:hover { &:hover {
background: var(--next-color-user-hover); background: var(--el-color-primary-light-9);
color: var(--next-bg-topBarColor); color: var(--el-color-primary);
} }
&.is-active { &.is-active {
background: var(--next-color-user-hover); background: var(--el-color-primary-light-8);
color: var(--next-bg-topBarColor); color: var(--el-color-primary);
font-weight: 600; font-weight: 600;
.dropdown-icon { color: var(--el-color-primary); }
.dropdown-icon {
color: var(--next-bg-topBarColor);
}
}
}
}
//
:deep(.el-scrollbar__bar.is-vertical) {
display: none;
}
:deep(a) {
width: 100%;
}
//
@media (max-width: 768px) {
.module-dropdown {
.module-selector {
padding: 0 12px;
height: 40px;
line-height: 40px;
font-size: 14px;
.module-title {
margin-left: 6px;
margin-right: 6px;
} }
} }
} }