!180 refactor: 重构authLogin代码逻辑
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled

Merge pull request !180 from 痴货/master
This commit is contained in:
xingyu
2025-07-23 07:41:44 +00:00
committed by Gitee

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);