2
0

feat: 角色认证判断

This commit is contained in:
TsMask
2024-12-02 20:00:07 +08:00
parent c9f0fbaca5
commit a5fd5e0fd2

View File

@@ -1,4 +1,4 @@
import { useAuthStore } from '@/store/modules/auth'; import {useAuthStore} from '@/store/modules/auth';
export function useAuth() { export function useAuth() {
const authStore = useAuthStore(); const authStore = useAuthStore();
@@ -15,7 +15,20 @@ export function useAuth() {
return codes.some(code => authStore.userInfo.buttons.includes(code)); 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 { return {
hasAuth hasAuth,
hasRole,
}; };
} }