项目微调

优化封装的自定义指令,其中按钮权限控制可用
This commit is contained in:
2024-10-10 15:45:37 +08:00
parent 0b03088397
commit 507ea137e4

View File

@@ -2,21 +2,21 @@
* v-auth * v-auth
* 按钮权限指令 * 按钮权限指令
*/ */
import { useAuthStore } from "@/stores/modules/auth"; import { useAuthStore } from '@/stores/modules/auth'
import type { Directive, DirectiveBinding } from "vue"; import type { Directive, DirectiveBinding } from 'vue'
const auth: Directive = { const auth: Directive = {
mounted(el: HTMLElement, binding: DirectiveBinding) { mounted(el: HTMLElement, binding: DirectiveBinding) {
const { value } = binding; const { value } = binding
const authStore = useAuthStore(); const authStore = useAuthStore()
const currentPageRoles = authStore.authButtonListGet[authStore.routeName] ?? []; const currentPageRoles = authStore.authButtonListGet[authStore.routeName] ?? []
if (value instanceof Array && value.length) { if (value instanceof Array && value.length) {
const hasPermission = value.every(item => currentPageRoles.includes(item)); const hasPermission = value.every(item => currentPageRoles.includes(item))
if (!hasPermission) el.remove(); if (!hasPermission) el.remove()
} else { } else {
if (!currentPageRoles.includes(value)) el.remove(); if (!currentPageRoles.includes(value)) el.remove()
} }
},
} }
};
export default auth; export default auth