重构鉴权指令、鉴权组件

This commit is contained in:
Hooray
2024-10-08 15:18:20 +08:00
parent 18242685bc
commit e662e9a095
5 changed files with 52 additions and 79 deletions
+8 -15
View File
@@ -1,19 +1,12 @@
import type { App } from 'vue'
import type { App, DirectiveBinding } from 'vue'
export default function directive(app: App) {
// 注册 v-auth 和 v-auth-all 指令
app.directive('auth', {
mounted: (el, binding) => {
if (!useAuth().auth(binding.value)) {
el.remove()
}
},
})
app.directive('auth-all', {
mounted: (el, binding) => {
if (!useAuth().authAll(binding.value)) {
el.remove()
}
},
app.directive('auth', (el: HTMLElement, binding: DirectiveBinding) => {
if (binding.modifiers.all ? useAuth().authAll(binding.value) : useAuth().auth(binding.value)) {
el.style.display = ''
}
else {
el.style.display = 'none'
}
})
}