@degal-helper/permission
Version:
权限校验
38 lines (30 loc) • 925 B
JavaScript
import _ from 'lodash-es'
export default function initPermission(Vue, store) {
Vue.prototype.$checkPermission = (value, confirm = false) => {
if (value) {
const permissions = _.get(store, 'getters.permissions', {}) || {}
let hasPermission = true
if (value instanceof Array) {
hasPermission =
value.length > 0
? _.flattenDeep(value).some((role) => {
return permissions[role]
})
: true
} else {
hasPermission = value ? permissions[value] : true
}
if (hasPermission || !confirm) {
return hasPermission
}
Vue.prototype.$alert('您没有操作权限', '温馨提示', {
confirmButtonText: '我已了解',
callback: () => {
return hasPermission
}
})
return hasPermission
}
return true
}
}