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:
parent
1bf9c07ab7
commit
c23a89d222
@ -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); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user