From a5fd5e0fd2f72a67edb69fb0c03aafdd4030a3fd Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 2 Dec 2024 20:00:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=92=E8=89=B2=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/business/auth.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/hooks/business/auth.ts b/src/hooks/business/auth.ts index f8fc749..d324223 100644 --- a/src/hooks/business/auth.ts +++ b/src/hooks/business/auth.ts @@ -1,4 +1,4 @@ -import { useAuthStore } from '@/store/modules/auth'; +import {useAuthStore} from '@/store/modules/auth'; export function useAuth() { const authStore = useAuthStore(); @@ -15,7 +15,20 @@ export function useAuth() { return codes.some(code => authStore.userInfo.buttons.includes(code)); } + function hasRole(role: string | string[]) { + if (!authStore.isLogin) { + return false; + } + + if (typeof role === 'string') { + return authStore.userInfo.roles.includes(role); + } + + return role.some(code => authStore.userInfo.roles.includes(code)); + } + return { - hasAuth + hasAuth, + hasRole, }; }