2
0
Files
fe.wfc/src/hooks/business/auth.ts
2024-12-04 17:48:39 +08:00

35 lines
729 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.permissions.includes(codes);
}
return codes.some(code => authStore.userInfo.permissions.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,
};
}