feat: 添加按钮权限

This commit is contained in:
xiaoxian521
2021-06-30 14:29:40 +08:00
parent a8bc76ed9c
commit ad1de9530a
11 changed files with 137 additions and 72 deletions

View 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']\"");
}
},
};