mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-21 14:13:36 +08:00
feat: 添加按钮权限
This commit is contained in:
17
src/directives/permission/index.ts
Normal file
17
src/directives/permission/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { usePermissionStoreHook } from "/@/store/modules/permission";
|
||||
import { Directive } from "vue";
|
||||
|
||||
export const auth: Directive = {
|
||||
mounted(el, binding) {
|
||||
const { value } = binding;
|
||||
if (value) {
|
||||
const authRoles = value;
|
||||
const hasAuth = usePermissionStoreHook().buttonAuth.includes(authRoles);
|
||||
if (!hasAuth) {
|
||||
el.style.display = "none";
|
||||
}
|
||||
} else {
|
||||
throw new Error("need roles! Like v-auth=\"['admin','test']\"");
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user