Files
pqs-9100_client/frontend/src/directives/modules/auth.ts
2025-01-13 18:12:36 +08:00

27 lines
826 B
TypeScript

/**
* v-auth
* 按钮权限指令
*/
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()
}
},
}
export default auth