jazz
2022-03-04 5dfa4aae98c53f1f3d5f8b9fa5308f359bfea104
提交 | 用户 | 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
5dfa4a 36       routes = this.jun_filterAuth(routes, () => {})
J 37       // routes = this.jun_filterAuth(routes, this.getAuthDataFN())
2a61f6 38       // console.log('this.getAuthDataFN()', this.getAuthDataFN())
L 39       // console.log('$router.options.routes', this.$router.options.routes)
40       // console.log('routes', routes)
41       return routes
42     },
43     activeMenu() {
44       const route = this.$route
45       const { meta, path } = route
46       // if set path, the sidebar will highlight the path you set
47       if (meta.activeMenu) {
48         return meta.activeMenu
49       }
50       return path
51     },
52     showLogo() {
53       return this.$store.state.settings.sidebarLogo
54     },
55     variables() {
56       return variables
57     },
58     isCollapse() {
59       return !this.sidebar.opened
60     }
61   },
62   methods: {
63     // 过滤侧边栏权限
64     jun_filterAuth(menuData, authData) {
65       return menuData.filter((menu) => {
66         // 仅有一级菜单
67         if (!menu.children) {
c2b28e 68           // mock模式 全显示
d8f5a1 69           if (isMock) return true
2a61f6 70           // 不存在权限的话,默认显示
L 71           // console.log(menu.auth, menu.auth ? !!authData[menu.auth] : true)
72           // 忽视hidden=true
73           return menu.auth ? !!authData[menu.auth] : !menu.hidden
74         }
75         // 有二级菜单
76         if (menu.children.length) {
77           // 递归
78           menu.children = this.jun_filterAuth(menu.children, authData)
c2b28e 79           // mock模式 全显示
d8f5a1 80           if (isMock) return true
2a61f6 81           return menu.children.length
L 82         }
83       })
84     }
85   }
86 }
87 </script>