侧边栏改用函数式渲染,移除弹出菜单滚动条,个性设置中`侧边栏折叠`不再与`折叠时显示父菜单`关联

master
toesbieya 6 years ago
parent 3d9b18c77a
commit 11efced693
  1. 8
      vue/src/assets/styles/sidebar.scss
  2. 5
      vue/src/layout/components/Navbar/components/SettingDrawer.vue
  3. 118
      vue/src/layout/components/Sidebar/components/SidebarItem.vue
  4. 1
      vue/src/layout/components/Sidebar/index.vue

@ -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;

@ -20,7 +20,7 @@
</div>
<div class="drawer-item">
<span>折叠菜单显示上级</span>
<el-switch v-model="sidebarShowParent" :disabled="!sidebarCollapse" class="drawer-switch"/>
<el-switch v-model="sidebarShowParent" class="drawer-switch"/>
</div>
<div class="drawer-item">
<span>左侧菜单自动隐藏</span>
@ -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: {

@ -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
}
if (showingChildren.length <= 0) {
this.onlyOneChild = {...this.item, path: undefined, children: undefined}
return true
}
const showSingle = onlyOneChild && !onlyOneChild.children && !item.alwaysShow
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
if (showSingle) {
const index = resolvePath(basePath, onlyOneChild.path)
const icon = onlyOneChild.meta.icon || (item.meta && item.meta.icon)
const title = onlyOneChild.meta.title
return (
<el-menu-item index={index} class={{'submenu-title-noDropdown': !this.isNest}}>
<sidebar-item-content icon={icon} title={title}/>
<el-menu-item
index={index}
class={{'submenu-title-noDropdown': !isNest, 'nest-menu': isNest}}
>
<SidebarItemContent icon={icon} title={title}/>
</el-menu-item>
)
}
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 index = resolvePath(basePath, item.path)
const icon = (item.meta && item.meta.icon) || (onlyOneChild.meta && onlyOneChild.meta.icon)
const title = item.meta.title
const children = this.item.children.map(child => (
<sidebar-item
is-nest
item={child}
base-path={this.resolvePath(child.path)}
class="nest-menu"
/>
))
//
const popoverMenu = [<el-scrollbar wrap-class="popover-menu__wrap">{children}</el-scrollbar>]
const children = item.children.map(child => renderNode({
isNest: true,
item: child,
basePath: resolvePath(basePath, child.path),
showParent,
collapse
}))
//mouseleavemouseleave
if (collapse) {
//
if (this.rootMenu.collapse && this.showParent) {
popoverMenu.unshift(
if (showParent) {
children.unshift(
<el-menu-item class="popover-menu__title" disabled>
<sidebar-item-content icon={icon} title={title}/>
<SidebarItemContent icon={icon} title={title}/>
</el-menu-item>
)
}
//el-submenuthis.$parent.$el.dispatch
}
return (
<li>
<el-submenu index={index} popper-append-to-body>
<sidebar-item-content slot="title" icon={icon} title={title}/>
{this.rootMenu.collapse ? popoverMenu : children}
<el-submenu class={{'nest-menu': isNest}} index={index} popper-append-to-body>
<SidebarItemContent slot="title" icon={icon} title={title}/>
{children}
</el-submenu>
</li>
)
}
}
return renderNode(context.props)
}
}
</script>

@ -23,6 +23,7 @@
v-for="route in routes"
:key="route.path"
:show-parent="sidebarShowParent"
:collapse="sidebarCollapse"
:base-path="route.path"
:item="route"
/>

Loading…
Cancel
Save