2023-10-09 11:03:41 +00:00
|
|
|
import type { App } from 'vue'
|
2023-10-13 08:11:54 +00:00
|
|
|
import { hasPermission } from '@/utils/permission'
|
2023-10-09 11:03:41 +00:00
|
|
|
|
|
|
|
|
const display = async (el: any, binding: any) => {
|
|
|
|
|
const has = hasPermission(
|
2023-10-12 08:36:16 +00:00
|
|
|
binding.value?.permission || binding.value,
|
|
|
|
|
binding.value?.compare || 'OR'
|
2023-10-09 11:03:41 +00:00
|
|
|
)
|
|
|
|
|
if (!has) {
|
|
|
|
|
el.style.display = 'none'
|
|
|
|
|
} else {
|
|
|
|
|
delete el.style.display
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
install: (app: App) => {
|
|
|
|
|
app.directive('hasPermission', {
|
|
|
|
|
async created(el: any, binding: any) {
|
|
|
|
|
display(el, binding)
|
|
|
|
|
},
|
|
|
|
|
async beforeUpdate(el: any, binding: any) {
|
|
|
|
|
display(el, binding)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|