Skip to content

Commit cf955b2

Browse files
committed
refactor!: 重构鉴权指令、鉴权组件
1 parent d3f99b0 commit cf955b2

File tree

5 files changed

+17
-42
lines changed

5 files changed

+17
-42
lines changed

src/components/Auth/index.vue

100644100755
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ defineOptions({
55
66
const props = defineProps<{
77
value: string | string[]
8+
all?: boolean
89
}>()
910
11+
const auth = useAuth()
12+
1013
function check() {
11-
return useAuth().auth(props.value)
14+
return props.all
15+
? auth.authAll(typeof props.value === 'string' ? [props.value] : props.value)
16+
: auth.auth(props.value)
1217
}
1318
</script>
1419

1520
<template>
16-
<div>
17-
<slot v-if="check()" />
18-
<slot v-else name="no-auth" />
19-
</div>
21+
<slot v-if="check()" />
22+
<slot v-else name="no-auth" />
2023
</template>

src/components/AuthAll/index.vue

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/types/components.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ declare module 'vue' {
99
export interface GlobalComponents {
1010
ActionContainer: typeof import('./../components/ActionContainer/index.vue')['default']
1111
Auth: typeof import('./../components/Auth/index.vue')['default']
12-
AuthAll: typeof import('./../components/AuthAll/index.vue')['default']
1312
FileUpload: typeof import('./../components/FileUpload/index.vue')['default']
1413
HBadge: typeof import('./../views/ui-kit/HBadge.vue')['default']
1514
HButton: typeof import('./../views/ui-kit/HButton.vue')['default']

src/utils/directive.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
import type { App } from 'vue'
1+
import type { App, DirectiveBinding } from 'vue'
22

33
export default function directive(app: App) {
4-
// 注册 v-auth 和 v-auth-all 指令
5-
app.directive('auth', {
6-
mounted: (el, binding) => {
7-
if (!useAuth().auth(binding.value)) {
8-
el.remove()
9-
}
10-
},
11-
})
12-
app.directive('auth-all', {
13-
mounted: (el, binding) => {
14-
if (!useAuth().authAll(binding.value)) {
15-
el.remove()
16-
}
17-
},
4+
app.directive('auth', (el: HTMLElement, binding: DirectiveBinding) => {
5+
if (binding.modifiers.all ? useAuth().authAll(binding.value) : useAuth().auth(binding.value)) {
6+
el.style.display = ''
7+
}
8+
else {
9+
el.style.display = 'none'
10+
}
1811
})
1912
}

src/views/components/Menu/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const handleSubMenuClick: MenuInjection['handleSubMenuClick'] = (index, indexPat
113113
function initMenu() {
114114
const activeItem = activeIndex.value && items.value[activeIndex.value]
115115
setSubMenusActive(activeIndex.value)
116-
if (!activeItem || props.collapse) {
116+
if (!activeItem || isMenuPopup.value || props.collapse) {
117117
return
118118
}
119119
// 展开该菜单项的路径上所有子菜单

0 commit comments

Comments
 (0)