This commit is contained in:
2025-02-06 18:13:42 +08:00
commit f4eb06d284
492 changed files with 40280 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import permission from './permission'
import permisaction from './permisaction'
const install = function(Vue) {
Vue.directive('permission', permission)
Vue.directive('permisaction', permisaction)
}
if (window.Vue) {
window['permission'] = permission
window['permisaction'] = permisaction
// eslint-disable-next-line no-undef
Vue.use(install)
}
permission.install = install
export default permission

View File

@ -0,0 +1,23 @@
import store from '@/store'
export default {
inserted(el, binding, vnode) {
const { value } = binding
const all_permission = '*:*:*'
const permissions = store.getters && store.getters.permisaction
if (value && value instanceof Array && value.length > 0) {
const permissionFlag = value
const hasPermissions = permissions.some(permission => {
return all_permission === permission || permissionFlag.includes(permission)
})
if (!hasPermissions) {
el.parentNode && el.parentNode.removeChild(el)
}
} else {
throw new Error(`请设置操作权限标签值`)
}
}
}

View File

@ -0,0 +1,22 @@
import store from '@/store'
export default {
inserted(el, binding, vnode) {
const { value } = binding
const roles = store.getters && store.getters.roles
if (value && value instanceof Array && value.length > 0) {
const permissionRoles = value
const hasPermission = roles.some(role => {
return permissionRoles.includes(role)
})
if (!hasPermission) {
el.parentNode && el.parentNode.removeChild(el)
}
} else {
throw new Error(`need roles! Like v-permission="['admin','editor']"`)
}
}
}