diff --git a/vue/src/assets/styles/sidebar.scss b/vue/src/assets/styles/sidebar.scss index b0b0a45..be77b4e 100644 --- a/vue/src/assets/styles/sidebar.scss +++ b/vue/src/assets/styles/sidebar.scss @@ -100,8 +100,8 @@ } } - & .nest-menu .el-submenu > .el-submenu__title, - & .el-submenu .el-menu-item { + .nest-menu > .el-submenu__title, + .el-submenu .el-menu-item { background-color: $subMenuBg !important; &:hover { @@ -116,9 +116,9 @@ } //侧边菜单折叠时弹出菜单的滚动条高度 - .popover-menu__wrap { + /*.popover-menu__wrap { max-height: 80vh; - } + }*/ .popover-menu__title { cursor: auto; diff --git a/vue/src/layout/components/Navbar/components/SettingDrawer.vue b/vue/src/layout/components/Navbar/components/SettingDrawer.vue index 778776d..f070412 100644 --- a/vue/src/layout/components/Navbar/components/SettingDrawer.vue +++ b/vue/src/layout/components/Navbar/components/SettingDrawer.vue @@ -20,7 +20,7 @@
折叠菜单显示上级 - +
左侧菜单自动隐藏 @@ -78,9 +78,6 @@ if (v && this.sidebarAutoHidden) { this.$store.commit('setting/sidebarAutoHidden', false) } - if (!v && this.sidebarShowParent) { - this.$store.commit('setting/sidebarShowParent', false) - } } }, sidebarShowParent: { diff --git a/vue/src/layout/components/Sidebar/components/SidebarItem.vue b/vue/src/layout/components/Sidebar/components/SidebarItem.vue index 79c9524..77eed8b 100644 --- a/vue/src/layout/components/Sidebar/components/SidebarItem.vue +++ b/vue/src/layout/components/Sidebar/components/SidebarItem.vue @@ -2,93 +2,85 @@ import path from 'path' import SidebarItemContent from './SidebarItemContent' + function resolvePath(basePath, routePath = '') { + const indexOf = basePath.indexOf(routePath) + const samePath = basePath.length === indexOf + routePath.length + return indexOf && samePath ? basePath : path.resolve(basePath, routePath) + } + + function getOnlyChild(item) { + const showingChildren = item.children || [] + + if (showingChildren.length === 1) return showingChildren[0] + + if (showingChildren.length <= 0) return {...item, path: undefined, children: undefined} + + return null + } + export default { - name: 'SidebarItem', - inject: ['rootMenu'], - components: {SidebarItemContent}, + functional: true, props: { item: Object, isNest: Boolean, showParent: Boolean, - basePath: { - type: String, - default: '' - } - }, - data: () => ({onlyOneChild: {}}), - methods: { - resolvePath(routePath = '') { - const indexOf = this.basePath.indexOf(routePath) - if (indexOf > 0 && this.basePath.length === indexOf + routePath.length) { - return this.basePath - } - return path.resolve(this.basePath, routePath) - } + collapse: Boolean, + basePath: {type: String, default: ''} }, - render() { - const hasOnlyOneShowingChild = () => { - const showingChildren = this.item.children || [] + render(h, context) { + function renderNode({item, isNest, showParent, collapse, basePath}) { + let onlyOneChild = getOnlyChild(item) - if (showingChildren.length === 1) { - this.onlyOneChild = showingChildren[0] - return true - } + const showSingle = onlyOneChild && !onlyOneChild.children && !item.alwaysShow - if (showingChildren.length <= 0) { - this.onlyOneChild = {...this.item, path: undefined, children: undefined} - return true + if (showSingle) { + const index = resolvePath(basePath, onlyOneChild.path) + const icon = onlyOneChild.meta.icon || (item.meta && item.meta.icon) + const title = onlyOneChild.meta.title + return ( + + + + ) } + else { + const index = resolvePath(basePath, item.path) + const icon = (item.meta && item.meta.icon) || (onlyOneChild.meta && onlyOneChild.meta.icon) + const title = item.meta.title - return false - } - const showSingle = () => { - return hasOnlyOneShowingChild() && (!this.onlyOneChild.children) && !this.item.alwaysShow - } - if (showSingle()) { - const index = this.resolvePath(this.onlyOneChild.path) - const icon = this.onlyOneChild.meta.icon || (this.item.meta && this.item.meta.icon) - const title = this.onlyOneChild.meta.title - return ( - - - - ) - } - else { - const index = this.resolvePath(this.item.path) - const icon = (this.item.meta && this.item.meta.icon) || (this.onlyOneChild.meta && this.onlyOneChild.meta.icon) - const title = this.item.meta.title + const children = item.children.map(child => renderNode({ + isNest: true, + item: child, + basePath: resolvePath(basePath, child.path), + showParent, + collapse + })) - const children = this.item.children.map(child => ( - - )) + //弹出菜单如果包裹滚动条,则在触发mouseleave时,不会触发父菜单的mouseleave事件 + if (collapse) { + //弹出菜单显示父级信息 + if (showParent) { + children.unshift( + + + + ) + } + } - //弹出菜单包裹滚动条 - const popoverMenu = [{children}] - - //弹出菜单显示父级信息 - if (this.rootMenu.collapse && this.showParent) { - popoverMenu.unshift( - - - + return ( + + + {children} + ) } - //外面需要额外包裹一层,否则el-submenu调用this.$parent.$el.dispatch时会死循环 - return ( -
  • - - - {this.rootMenu.collapse ? popoverMenu : children} - -
  • - ) } + + return renderNode(context.props) } } diff --git a/vue/src/layout/components/Sidebar/index.vue b/vue/src/layout/components/Sidebar/index.vue index b95196e..4a1f465 100644 --- a/vue/src/layout/components/Sidebar/index.vue +++ b/vue/src/layout/components/Sidebar/index.vue @@ -23,6 +23,7 @@ v-for="route in routes" :key="route.path" :show-parent="sidebarShowParent" + :collapse="sidebarCollapse" :base-path="route.path" :item="route" />