From cf955b2abb64a928c3b70485144e3c3e93d76af5 Mon Sep 17 00:00:00 2001 From: Hooray <304327508@qq.com> Date: Wed, 2 Oct 2024 18:57:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor!:=20=E9=87=8D=E6=9E=84=E9=89=B4?= =?UTF-8?q?=E6=9D=83=E6=8C=87=E4=BB=A4=E3=80=81=E9=89=B4=E6=9D=83=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Auth/index.vue | 13 ++++++++----- src/components/AuthAll/index.vue | 20 -------------------- src/types/components.d.ts | 1 - src/utils/directive.ts | 23 ++++++++--------------- src/views/components/Menu/index.vue | 2 +- 5 files changed, 17 insertions(+), 42 deletions(-) mode change 100644 => 100755 src/components/Auth/index.vue delete mode 100644 src/components/AuthAll/index.vue diff --git a/src/components/Auth/index.vue b/src/components/Auth/index.vue old mode 100644 new mode 100755 index a25fe087..369fd05c --- a/src/components/Auth/index.vue +++ b/src/components/Auth/index.vue @@ -5,16 +5,19 @@ defineOptions({ const props = defineProps<{ value: string | string[] + all?: boolean }>() +const auth = useAuth() + function check() { - return useAuth().auth(props.value) + return props.all + ? auth.authAll(typeof props.value === 'string' ? [props.value] : props.value) + : auth.auth(props.value) } diff --git a/src/components/AuthAll/index.vue b/src/components/AuthAll/index.vue deleted file mode 100644 index 3c0f36ec..00000000 --- a/src/components/AuthAll/index.vue +++ /dev/null @@ -1,20 +0,0 @@ - - - diff --git a/src/types/components.d.ts b/src/types/components.d.ts index c07c9205..94664a40 100644 --- a/src/types/components.d.ts +++ b/src/types/components.d.ts @@ -9,7 +9,6 @@ declare module 'vue' { export interface GlobalComponents { ActionContainer: typeof import('./../components/ActionContainer/index.vue')['default'] Auth: typeof import('./../components/Auth/index.vue')['default'] - AuthAll: typeof import('./../components/AuthAll/index.vue')['default'] FileUpload: typeof import('./../components/FileUpload/index.vue')['default'] HBadge: typeof import('./../views/ui-kit/HBadge.vue')['default'] HButton: typeof import('./../views/ui-kit/HButton.vue')['default'] diff --git a/src/utils/directive.ts b/src/utils/directive.ts index bbd2481a..93d4df78 100644 --- a/src/utils/directive.ts +++ b/src/utils/directive.ts @@ -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' + } }) } diff --git a/src/views/components/Menu/index.vue b/src/views/components/Menu/index.vue index 1567c7c2..3d25dcb4 100644 --- a/src/views/components/Menu/index.vue +++ b/src/views/components/Menu/index.vue @@ -113,7 +113,7 @@ const handleSubMenuClick: MenuInjection['handleSubMenuClick'] = (index, indexPat function initMenu() { const activeItem = activeIndex.value && items.value[activeIndex.value] setSubMenusActive(activeIndex.value) - if (!activeItem || props.collapse) { + if (!activeItem || isMenuPopup.value || props.collapse) { return } // 展开该菜单项的路径上所有子菜单