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, }; }