diff --git a/frontend/src/directives/modules/auth.ts b/frontend/src/directives/modules/auth.ts index 546c883..30d0c1e 100644 --- a/frontend/src/directives/modules/auth.ts +++ b/frontend/src/directives/modules/auth.ts @@ -6,21 +6,24 @@ import { useAuthStore } from '@/stores/modules/auth' import type { Directive, DirectiveBinding } from 'vue' const auth: Directive = { - mounted(el: HTMLElement, binding: DirectiveBinding) { - const { value } = binding - const authStore = useAuthStore() - const currentPageRoles = authStore.authButtonListGet[authStore.routeName] ?? [] - // console.log('1234',authStore.routeName) - // console.log('123',currentPageRoles) - if (value instanceof Array && value.length) { - //console.log('123456',value) - const hasPermission = value.every(item => currentPageRoles.includes(item)) - if (!hasPermission) el.remove() - } else { - //console.log('12345',value) - if (!currentPageRoles.includes(value)) el.remove() + mounted(el: HTMLElement, binding: DirectiveBinding) { + //console.log('binding',binding) + const { value, modifiers } = binding + let currentPageRoles = [] + const authStore = useAuthStore() + if (modifiers && Object.keys(modifiers).length) { + currentPageRoles = authStore.authButtonListGet[Object.keys(modifiers)[0]] ?? [] + } else { + currentPageRoles = authStore.authButtonListGet[authStore.routeName] ?? [] + } + console.log('currentPageRoles', currentPageRoles) + if (value instanceof Array && value.length) { + const hasPermission = value.every(item => currentPageRoles.includes(item)) + if (!hasPermission) el.remove() + } else { + if (!currentPageRoles.includes(value)) el.remove() + } } - }, } export default auth