mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2025-12-14 22:30:31 +08:00
19 lines
562 B
TypeScript
19 lines
562 B
TypeScript
import { usePermissionStoreHook } from "/@/store/modules/permission";
|
|
import { Directive } from "vue";
|
|
import type { DirectiveBinding } from "vue";
|
|
|
|
export const auth: Directive = {
|
|
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
|
const { value } = binding;
|
|
if (value) {
|
|
const authRoles = value;
|
|
const hasAuth = usePermissionStoreHook().buttonAuth.includes(authRoles);
|
|
if (!hasAuth) {
|
|
el.parentNode.removeChild(el);
|
|
}
|
|
} else {
|
|
throw new Error("need roles! Like v-auth=\"['admin','test']\"");
|
|
}
|
|
}
|
|
};
|