From 26647222e28b6c6871611c887510b39926921287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E5=90=8C=E5=AD=A6?= Date: Wed, 20 Aug 2025 10:15:09 +0800 Subject: [PATCH] =?UTF-8?q?UPDATE:=E4=BC=98=E5=8C=96v-auth=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/directives/modules/auth.ts | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) 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