提交 | 用户 | age
|
2a61f6
|
1 |
<template> |
L |
2 |
<div :class="{'has-logo':showLogo}"> |
|
3 |
<logo v-if="showLogo" :collapse="isCollapse" /> |
|
4 |
<el-scrollbar wrap-class="scrollbar-wrapper"> |
|
5 |
<el-menu |
|
6 |
:default-active="activeMenu" |
|
7 |
:collapse="isCollapse" |
|
8 |
:background-color="variables.menuBg" |
|
9 |
:text-color="variables.menuText" |
|
10 |
:unique-opened="false" |
|
11 |
:active-text-color="variables.menuActiveText" |
|
12 |
:collapse-transition="false" |
|
13 |
mode="vertical" |
|
14 |
> |
|
15 |
<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" /> |
|
16 |
</el-menu> |
|
17 |
</el-scrollbar> |
|
18 |
</div> |
|
19 |
</template> |
|
20 |
|
|
21 |
<script> |
|
22 |
import { mapGetters } from 'vuex' |
|
23 |
import Logo from './Logo' |
|
24 |
import SidebarItem from './SidebarItem' |
|
25 |
import variables from '@/styles/variables.scss' |
d8f5a1
|
26 |
var isMock = require('@/config/baseConfig').isMock // 全局配置文件 |
2a61f6
|
27 |
|
L |
28 |
export default { |
|
29 |
components: { SidebarItem, Logo }, |
|
30 |
computed: { |
|
31 |
...mapGetters([ |
|
32 |
'sidebar' |
|
33 |
]), |
|
34 |
routes() { |
|
35 |
let routes = this.$router.options.routes |
|
36 |
routes = this.jun_filterAuth(routes, this.getAuthDataFN()) |
|
37 |
// console.log('this.getAuthDataFN()', this.getAuthDataFN()) |
|
38 |
// console.log('$router.options.routes', this.$router.options.routes) |
|
39 |
// console.log('routes', routes) |
|
40 |
return routes |
|
41 |
}, |
|
42 |
activeMenu() { |
|
43 |
const route = this.$route |
|
44 |
const { meta, path } = route |
|
45 |
// if set path, the sidebar will highlight the path you set |
|
46 |
if (meta.activeMenu) { |
|
47 |
return meta.activeMenu |
|
48 |
} |
|
49 |
return path |
|
50 |
}, |
|
51 |
showLogo() { |
|
52 |
return this.$store.state.settings.sidebarLogo |
|
53 |
}, |
|
54 |
variables() { |
|
55 |
return variables |
|
56 |
}, |
|
57 |
isCollapse() { |
|
58 |
return !this.sidebar.opened |
|
59 |
} |
|
60 |
}, |
|
61 |
methods: { |
|
62 |
// 过滤侧边栏权限 |
|
63 |
jun_filterAuth(menuData, authData) { |
|
64 |
return menuData.filter((menu) => { |
|
65 |
// 仅有一级菜单 |
|
66 |
if (!menu.children) { |
c2b28e
|
67 |
// mock模式 全显示 |
d8f5a1
|
68 |
if (isMock) return true |
2a61f6
|
69 |
// 不存在权限的话,默认显示 |
L |
70 |
// console.log(menu.auth, menu.auth ? !!authData[menu.auth] : true) |
|
71 |
// 忽视hidden=true |
|
72 |
return menu.auth ? !!authData[menu.auth] : !menu.hidden |
|
73 |
} |
|
74 |
// 有二级菜单 |
|
75 |
if (menu.children.length) { |
|
76 |
// 递归 |
|
77 |
menu.children = this.jun_filterAuth(menu.children, authData) |
c2b28e
|
78 |
// mock模式 全显示 |
d8f5a1
|
79 |
if (isMock) return true |
2a61f6
|
80 |
return menu.children.length |
L |
81 |
} |
|
82 |
}) |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
</script> |