feat: 角色认证判断
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user