index.ts 482 B

1234567891011121314151617
  1. import { usePermissionStoreHook } from "/@/store/modules/permission";
  2. import { Directive } from "vue";
  3. export const auth: Directive = {
  4. mounted(el, binding) {
  5. const { value } = binding;
  6. if (value) {
  7. const authRoles = value;
  8. const hasAuth = usePermissionStoreHook().buttonAuth.includes(authRoles);
  9. if (!hasAuth) {
  10. el.style.display = "none";
  11. }
  12. } else {
  13. throw new Error("need roles! Like v-auth=\"['admin','test']\"");
  14. }
  15. }
  16. };