mirror of
https://github.com/iczer/vue-antd-admin
synced 2025-04-06 04:00:06 +08:00
feat: add function of filtering menu data through authority; ⭐
新增:增加通过权限过滤菜单数据的功能;
This commit is contained in:
parent
cbda23e3db
commit
1fb75f491d
@ -18,6 +18,7 @@ module.exports = {
|
|||||||
copyright: '2018 ICZER 工作室出品', //copyright
|
copyright: '2018 ICZER 工作室出品', //copyright
|
||||||
asyncRoutes: false, //异步加载路由,true:开启,false:不开启
|
asyncRoutes: false, //异步加载路由,true:开启,false:不开启
|
||||||
showPageTitle: true, //是否显示页面标题(PageLayout 布局中的页面标题),true:显示,false:不显示
|
showPageTitle: true, //是否显示页面标题(PageLayout 布局中的页面标题),true:显示,false:不显示
|
||||||
|
filterMenu: true, //根据权限过滤菜单,true:过滤,false:不过滤
|
||||||
animate: { //动画设置
|
animate: { //动画设置
|
||||||
disabled: false, //禁用动画,true:禁用,false:启用
|
disabled: false, //禁用动画,true:禁用,false:启用
|
||||||
name: 'bounce', //动画效果,支持的动画效果可参考 ./animate.config.js
|
name: 'bounce', //动画效果,支持的动画效果可参考 ./animate.config.js
|
||||||
|
@ -56,8 +56,8 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState('setting', ['isMobile', 'theme', 'layout', 'footerLinks', 'copyright', 'fixedHeader', 'fixedSideBar',
|
...mapState('setting', ['isMobile', 'theme', 'layout', 'footerLinks', 'copyright', 'fixedHeader', 'fixedSideBar',
|
||||||
'hideSetting', 'menuData']),
|
'hideSetting']),
|
||||||
...mapGetters('setting', ['firstMenu', 'subMenu']),
|
...mapGetters('setting', ['firstMenu', 'subMenu', 'menuData']),
|
||||||
sideMenuWidth() {
|
sideMenuWidth() {
|
||||||
return this.collapsed ? '80px' : '256px'
|
return this.collapsed ? '80px' : '256px'
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
import {ADMIN} from '@/config/default'
|
import {ADMIN} from '@/config/default'
|
||||||
import {formatFullPath} from '@/utils/i18n'
|
import {formatFullPath} from '@/utils/i18n'
|
||||||
|
import {filterMenu} from '@/utils/authority-utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: {
|
state: {
|
||||||
@ -13,6 +15,13 @@ export default {
|
|||||||
...config,
|
...config,
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
menuData(state, getters, rootState) {
|
||||||
|
if (state.filterMenu) {
|
||||||
|
const {permissions, roles} = rootState.account
|
||||||
|
filterMenu(state.menuData, permissions, roles)
|
||||||
|
}
|
||||||
|
return state.menuData
|
||||||
|
},
|
||||||
firstMenu(state) {
|
firstMenu(state) {
|
||||||
const {menuData} = state
|
const {menuData} = state
|
||||||
if (!menuData[0].fullPath) {
|
if (!menuData[0].fullPath) {
|
||||||
@ -30,7 +39,7 @@ export default {
|
|||||||
formatFullPath(menuData)
|
formatFullPath(menuData)
|
||||||
}
|
}
|
||||||
const current = menuData.find(menu => menu.fullPath === activatedFirst)
|
const current = menuData.find(menu => menu.fullPath === activatedFirst)
|
||||||
return current ? current.children : []
|
return current && current.children ? current.children : []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
@ -47,4 +47,19 @@ function hasAnyRole(required, roles) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {hasPermission, hasRole}
|
/**
|
||||||
|
* 根据权限配置过滤菜单数据
|
||||||
|
* @param menuData
|
||||||
|
* @param permissions
|
||||||
|
* @param roles
|
||||||
|
*/
|
||||||
|
function filterMenu(menuData, permissions, roles) {
|
||||||
|
menuData.forEach(menu => {
|
||||||
|
menu.meta.invisible = !hasPermission(menu, permissions) && !hasRole(menu, roles)
|
||||||
|
if (menu.children && menu.children.length > 0) {
|
||||||
|
filterMenu(menu.children, permissions, roles)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export {hasPermission, hasRole, filterMenu}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user