wip: 迁移 v3-admin v3.1.3 版本代码
This commit is contained in:
21
src/directives/permission/index.ts
Normal file
21
src/directives/permission/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useUserStoreHook } from '@/store/modules/user'
|
||||
import { Directive } from 'vue'
|
||||
|
||||
/** 权限指令 */
|
||||
export const permission: Directive = {
|
||||
mounted(el, binding) {
|
||||
const { value } = binding
|
||||
const roles = useUserStoreHook().roles
|
||||
if (value && value instanceof Array && value.length > 0) {
|
||||
const permissionRoles = value
|
||||
const hasPermission = roles.some((role: any) => {
|
||||
return permissionRoles.includes(role)
|
||||
})
|
||||
if (!hasPermission) {
|
||||
el.style.display = 'none'
|
||||
}
|
||||
} else {
|
||||
throw new Error("need roles! Like v-permission=\"['admin','editor']\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user