Files
pqs-9100_client/frontend/src/directives/modules/auth.ts

30 lines
1019 B
TypeScript
Raw Normal View History

2024-08-22 11:27:06 +08:00
/**
* v-auth
*
*/
import { useAuthStore } from '@/stores/modules/auth'
import type { Directive, DirectiveBinding } from 'vue'
2024-08-22 11:27:06 +08:00
const auth: Directive = {
2025-08-20 10:15:09 +08:00
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()
}
2024-08-22 11:27:06 +08:00
}
}
2024-08-22 11:27:06 +08:00
export default auth