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,100 +298,119 @@ onBeforeRouteUpdate((to) => {
<style scoped lang="scss"> <style scoped lang="scss">
.el-menu-horizontal-warp { .el-menu-horizontal-warp {
flex: 1; height: 100%;
overflow: hidden;
margin-right: 30px;
display: flex; display: flex;
align-items: center; align-items: center;
height: 100%; flex: 1;
padding: 0 16px;
background: var(--el-bg-color);
border-bottom: 1px solid var(--el-border-color-light);
.module-dropdown { /* 二级菜单,左侧 */
.module-selector { .sub-menu {
height: 50px; padding: 0 !important;
line-height: 50px; margin: 0 !important;
padding: 0 10px; height: 100%;
cursor: pointer; overflow-x: auto;
display: flex; white-space: nowrap;
align-items: center; &::-webkit-scrollbar { display: none; }
gap: 5px;
.el-menu-item {
min-width: 150px;
height: 100%;
line-height: initial;
margin: 0 12px;
padding: 0;
color: var(--next-bg-topBarColor); color: var(--next-bg-topBarColor);
background: transparent;
border: none;
border-radius: 6px;
font-size: 14px;
transition: all 0.3s;
white-space: nowrap;
.module-title {
font-weight: 500;
}
&:hover {
background: var(--next-color-user-hover);
color: var(--next-bg-topBarColor);
}
}
}
//
:deep(.el-dropdown-menu) {
border-radius: 8px;
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
border: 1px solid var(--el-border-color-light);
min-width: 180px;
.el-dropdown-menu__item {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 12px 16px; gap: 6px;
transition: all 0.3s; font-size: 14px;
border-radius: 6px; border-bottom: 2px solid transparent;
margin: 4px 6px; transition: color 0.3s, border-color 0.3s;
.dropdown-icon { .submenu-icon {
margin-right: 10px; margin-top: 0;
font-size: 16px; width: 20px;
width: 16px; height: 20px;
height: 16px; display: flex;
} align-items: center;
justify-content: center;
&:hover { margin-right: 4px;
background: var(--next-color-user-hover);
color: var(--next-bg-topBarColor);
} }
&.is-active { &.is-active {
background: var(--next-color-user-hover); color: var(--el-color-primary);
color: var(--next-bg-topBarColor); border-color: var(--el-color-primary);
font-weight: 600; font-weight: 600;
.dropdown-icon {
color: var(--next-bg-topBarColor);
}
} }
&:hover { color: var(--el-color-primary); }
} }
} }
// /* 模块切换下拉,右侧 */
:deep(.el-scrollbar__bar.is-vertical) { .module-dropdown {
display: none; flex: none;
} margin-left: 16px;
:deep(a) { height: 100%;
width: 100%; display: flex;
} align-items: center;
// .module-selector {
@media (max-width: 768px) { display: flex;
.module-dropdown { align-items: center;
.module-selector { height: 100%;
padding: 0 12px; line-height: initial;
height: 40px; padding: 0 12px;
line-height: 40px; gap: 8px;
font-size: 14px; color: var(--next-bg-topBarColor);
background: var(--el-bg-color);
font-size: 14px;
transition: background 0.3s, color 0.3s, border-color 0.3s;
.module-title { .module-title { font-weight: 500; }
margin-left: 6px; &:hover {
margin-right: 6px; background: var(--el-color-primary-light-9);
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) {
border-radius: 8px;
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
border: 1px solid var(--el-border-color-light);
min-width: 180px;
.el-dropdown-menu__item {
display: flex;
align-items: center;
padding: 12px 16px;
margin: 4px 6px;
border-radius: 6px;
transition: background 0.3s, color 0.3s;
.dropdown-icon {
margin-right: 10px;
font-size: 16px;
width: 16px;
height: 16px;
}
&:hover {
background: var(--el-color-primary-light-9);
color: var(--el-color-primary);
}
&.is-active {
background: var(--el-color-primary-light-8);
color: var(--el-color-primary);
font-weight: 600;
.dropdown-icon { color: var(--el-color-primary); }
} }
} }
} }