Pre Merge pull request !180 from 痴货/master

pull/180/MERGE
痴货 2025-07-23 05:24:31 +00:00 committed by Gitee
commit 17f259ce1c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 21 additions and 11 deletions

View File

@ -44,16 +44,26 @@ export const useAuthStore = defineStore('auth', () => {
// 异步处理用户登录操作并获取 accessToken // 异步处理用户登录操作并获取 accessToken
let userInfo: null | UserInfo = null; let userInfo: null | UserInfo = null;
try { try {
let loginResult: AuthApi.LoginResult;
loginLoading.value = true; loginLoading.value = true;
const { accessToken, refreshToken } = switch (type) {
type === 'mobile' case 'mobile': {
? await smsLogin(params as AuthApi.SmsLoginParams) loginResult = await smsLogin(params as AuthApi.SmsLoginParams);
: type === 'register' break;
? await register(params as AuthApi.RegisterParams) }
: // eslint-disable-next-line unicorn/no-nested-ternary case 'register': {
type === 'social' loginResult = await register(params as AuthApi.RegisterParams);
? await socialLogin(params as AuthApi.SocialLoginParams) break;
: await loginApi(params); }
case 'social': {
loginResult = await socialLogin(params as AuthApi.SocialLoginParams);
break;
}
default: {
loginResult = await loginApi(params);
}
}
const { accessToken, refreshToken } = loginResult;
// 如果成功获取到 accessToken // 如果成功获取到 accessToken
if (accessToken) { if (accessToken) {
@ -122,8 +132,8 @@ export const useAuthStore = defineStore('auth', () => {
async function fetchUserInfo() { async function fetchUserInfo() {
// 加载 // 加载
let authPermissionInfo: AuthPermissionInfo | null; const authPermissionInfo: AuthPermissionInfo | null =
authPermissionInfo = await getAuthPermissionInfoApi(); await getAuthPermissionInfoApi();
// userStore // userStore
userStore.setUserInfo(authPermissionInfo.user); userStore.setUserInfo(authPermissionInfo.user);
userStore.setUserRoles(authPermissionInfo.roles); userStore.setUserRoles(authPermissionInfo.roles);