mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-07 13:07:58 +08:00
修复权限验证bug
This commit is contained in:
@@ -48,12 +48,12 @@ const getters = {
|
||||
|
||||
const actions = {
|
||||
// 根据权限动态生成路由
|
||||
generateRoutes({state, dispatch, commit}, data) {
|
||||
generateRoutes({rootState, dispatch, commit}, data) {
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise(async resolve => {
|
||||
let accessedRoutes
|
||||
// 判断权限功能是否开启
|
||||
if (state.openPermission) {
|
||||
if (rootState.settings.openPermission) {
|
||||
const permissions = await dispatch('user/getPermissions', null, { root: true })
|
||||
accessedRoutes = filterAsyncRoutes(data.asyncRoutes, permissions)
|
||||
} else {
|
||||
|
||||
@@ -17,15 +17,6 @@ const getters = {
|
||||
}
|
||||
}
|
||||
return retn
|
||||
},
|
||||
hasPermission: state => permissions => {
|
||||
if (state.openPermission) {
|
||||
return state.permissions.some(v => {
|
||||
return v === permissions
|
||||
})
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,14 +51,14 @@ const actions = {
|
||||
return new Promise(resolve => {
|
||||
// 模拟权限数据
|
||||
let permissions
|
||||
if (state.user.account == 'admin') {
|
||||
if (state.account == 'admin') {
|
||||
permissions = [
|
||||
'permission.browse',
|
||||
'permission.create',
|
||||
'permission.edit',
|
||||
'permission.remove'
|
||||
]
|
||||
} else if (state.user.account == 'test') {
|
||||
} else if (state.account == 'test') {
|
||||
permissions = [
|
||||
'permission.browse'
|
||||
]
|
||||
|
||||
+16
-3
@@ -33,13 +33,26 @@ export function deepClone(target) {
|
||||
return result
|
||||
}
|
||||
|
||||
function hasPermission(permission) {
|
||||
if (store.state.settings.openPermission) {
|
||||
console.log(permission, store.state.user.permissions.some(v => {
|
||||
return v === permission
|
||||
}))
|
||||
return store.state.user.permissions.some(v => {
|
||||
return v === permission
|
||||
})
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export function auth(value) {
|
||||
let auth
|
||||
if (typeof value === 'string') {
|
||||
auth = store.getters['user/hasPermission'](value)
|
||||
auth = hasPermission(value)
|
||||
} else {
|
||||
auth = value.some(item => {
|
||||
return store.getters['user/hasPermission'](item)
|
||||
return hasPermission(item)
|
||||
})
|
||||
}
|
||||
return auth
|
||||
@@ -47,7 +60,7 @@ export function auth(value) {
|
||||
|
||||
export function authAll(value) {
|
||||
const auth = value.every(item => {
|
||||
return store.getters['user/hasPermission'](item)
|
||||
return hasPermission(item)
|
||||
})
|
||||
return auth
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user