2
0
Files
fe.wfc.user/src/hooks/business/auth.ts
2024-12-02 20:00:07 +08:00

35 lines
721 B
TypeScript

import {useAuthStore} from '@/store/modules/auth';
export function useAuth() {
const authStore = useAuthStore();
function hasAuth(codes: string | string[]) {
if (!authStore.isLogin) {
return false;
}
if (typeof codes === 'string') {
return authStore.userInfo.buttons.includes(codes);
}
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,
hasRole,
};
}