feat: 角色认证判断
This commit is contained in:
1 parent
c9f0fbaca5
commit
a5fd5e0fd2
1 file changed
+14
-1
@@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user