feat:增加 social-login.vue 社交登录

This commit is contained in:
YunaiV
2025-04-10 22:23:41 +08:00
parent 2c105a21aa
commit 9fc51f085d
8 changed files with 310 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
import { notification } from 'ant-design-vue';
import { defineStore } from 'pinia';
import { type AuthApi, getAuthPermissionInfoApi, loginApi, logoutApi, smsLogin, register } from '#/api';
import { type AuthApi, getAuthPermissionInfoApi, loginApi, logoutApi, smsLogin, register, socialLogin } from '#/api';
import { $t } from '#/locales';
export const useAuthStore = defineStore('auth', () => {
@@ -27,7 +27,7 @@ export const useAuthStore = defineStore('auth', () => {
* @param onSuccess 登录成功后的回调函数
*/
async function authLogin(
type: 'mobile' | 'username' | 'register',
type: 'mobile' | 'username' | 'register' | 'social',
params: Recordable<any>,
onSuccess?: () => Promise<void> | void,
) {
@@ -37,6 +37,7 @@ export const useAuthStore = defineStore('auth', () => {
loginLoading.value = true;
const { accessToken, refreshToken } = type === 'mobile' ? await smsLogin(params as AuthApi.SmsLoginParams)
: type === 'register' ? await register(params as AuthApi.RegisterParams)
: type === 'social' ? await socialLogin(params as AuthApi.SocialLoginParams)
: await loginApi(params);
// 如果成功获取到 accessToken