<template>
|
<div :class="{'has-logo':showLogo}">
|
<logo v-if="showLogo" :collapse="isCollapse" />
|
<el-scrollbar wrap-class="scrollbar-wrapper">
|
<el-menu
|
:default-active="activeMenu"
|
:collapse="isCollapse"
|
:background-color="variables.menuBg"
|
:text-color="variables.menuText"
|
:unique-opened="false"
|
:active-text-color="variables.menuActiveText"
|
:collapse-transition="false"
|
mode="vertical"
|
>
|
<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
|
</el-menu>
|
</el-scrollbar>
|
</div>
|
</template>
|
|
<script>
|
import { mapGetters } from 'vuex'
|
import Logo from './Logo'
|
import SidebarItem from './SidebarItem'
|
import variables from '@/styles/variables.scss'
|
var isMock = require('@/config/baseConfig').isMock // 全局配置文件
|
|
export default {
|
components: { SidebarItem, Logo },
|
computed: {
|
...mapGetters([
|
'sidebar'
|
]),
|
routes() {
|
let routes = this.$router.options.routes
|
routes = this.jun_filterAuth(routes, () => {})
|
// routes = this.jun_filterAuth(routes, this.getAuthDataFN())
|
// console.log('this.getAuthDataFN()', this.getAuthDataFN())
|
// console.log('$router.options.routes', this.$router.options.routes)
|
// console.log('routes', routes)
|
return routes
|
},
|
activeMenu() {
|
const route = this.$route
|
const { meta, path } = route
|
// if set path, the sidebar will highlight the path you set
|
if (meta.activeMenu) {
|
return meta.activeMenu
|
}
|
return path
|
},
|
showLogo() {
|
return this.$store.state.settings.sidebarLogo
|
},
|
variables() {
|
return variables
|
},
|
isCollapse() {
|
return !this.sidebar.opened
|
}
|
},
|
methods: {
|
// 过滤侧边栏权限
|
jun_filterAuth(menuData, authData) {
|
return menuData.filter((menu) => {
|
// 仅有一级菜单
|
if (!menu.children) {
|
// mock模式 全显示
|
if (isMock) return true
|
// 不存在权限的话,默认显示
|
// console.log(menu.auth, menu.auth ? !!authData[menu.auth] : true)
|
// 忽视hidden=true
|
return menu.auth ? !!authData[menu.auth] : !menu.hidden
|
}
|
// 有二级菜单
|
if (menu.children.length) {
|
// 递归
|
menu.children = this.jun_filterAuth(menu.children, authData)
|
// mock模式 全显示
|
if (isMock) return true
|
return menu.children.length
|
}
|
})
|
}
|
}
|
}
|
</script>
|