2024-08-22 11:27:06 +08:00
|
|
|
/**
|
|
|
|
|
* v-auth
|
|
|
|
|
* 按钮权限指令
|
|
|
|
|
*/
|
2024-10-10 15:45:37 +08:00
|
|
|
import { useAuthStore } from '@/stores/modules/auth'
|
|
|
|
|
import type { Directive, DirectiveBinding } from 'vue'
|
2024-08-22 11:27:06 +08:00
|
|
|
|
|
|
|
|
const auth: Directive = {
|
|
|
|
|
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
2024-10-10 15:45:37 +08:00
|
|
|
const { value } = binding
|
|
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
const currentPageRoles = authStore.authButtonListGet[authStore.routeName] ?? []
|
2024-11-20 15:13:50 +08:00
|
|
|
console.log('1234',authStore.routeName)
|
|
|
|
|
console.log('123',currentPageRoles)
|
2024-08-22 11:27:06 +08:00
|
|
|
if (value instanceof Array && value.length) {
|
2024-10-10 15:45:37 +08:00
|
|
|
const hasPermission = value.every(item => currentPageRoles.includes(item))
|
|
|
|
|
if (!hasPermission) el.remove()
|
2024-08-22 11:27:06 +08:00
|
|
|
} else {
|
2024-10-10 15:45:37 +08:00
|
|
|
if (!currentPageRoles.includes(value)) el.remove()
|
2024-08-22 11:27:06 +08:00
|
|
|
}
|
2024-10-10 15:45:37 +08:00
|
|
|
},
|
|
|
|
|
}
|
2024-08-22 11:27:06 +08:00
|
|
|
|
2024-10-10 15:45:37 +08:00
|
|
|
export default auth
|