From f77c96cdc276480331fd942748fcf54bf83500b2 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 30 May 2025 14:37:34 +0800 Subject: [PATCH] feat(vben5): Realize mobile phone number login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增手机号码登录api - 新增发送手机登录验证码api - 新增发送手机重置密码验证码api --- apps/vben5/apps/app-antd/src/store/auth.ts | 31 ++++++++++++- .../views/_core/authentication/code-login.vue | 42 +++++++++++++---- .../packages/@abp/account/src/api/index.ts | 1 + .../@abp/account/src/api/useAccountApi.ts | 28 +++++++++++ .../@abp/account/src/api/usePhoneLoginApi.ts | 46 +++++++++++++++++++ .../@abp/account/src/api/useQrCodeLoginApi.ts | 2 +- .../@abp/account/src/types/account.ts | 12 +++++ .../packages/@abp/account/src/types/token.ts | 8 ++++ 8 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 apps/vben5/packages/@abp/account/src/api/usePhoneLoginApi.ts diff --git a/apps/vben5/apps/app-antd/src/store/auth.ts b/apps/vben5/apps/app-antd/src/store/auth.ts index 94227a382..1f0c9c822 100644 --- a/apps/vben5/apps/app-antd/src/store/auth.ts +++ b/apps/vben5/apps/app-antd/src/store/auth.ts @@ -2,13 +2,14 @@ import type { TokenResult } from '@abp/account'; import type { Recordable, UserInfo } from '@vben/types'; -import { ref } from 'vue'; +import { ref, watch } from 'vue'; import { useRouter } from 'vue-router'; import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants'; import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores'; import { + usePhoneLoginApi, useProfileApi, useQrCodeLoginApi, useTokenApi, @@ -25,6 +26,7 @@ export const useAuthStore = defineStore('auth', () => { const { publish } = useEventBus(); const { loginApi } = useTokenApi(); const { loginApi: qrcodeLoginApi } = useQrCodeLoginApi(); + const { loginApi: phoneLoginApi } = usePhoneLoginApi(); const { getUserInfoApi } = useUserInfoApi(); const { getConfigApi } = useAbpConfigApi(); const { getPictureApi } = useProfileApi(); @@ -35,6 +37,17 @@ export const useAuthStore = defineStore('auth', () => { const loginLoading = ref(false); + watch( + () => accessStore.accessToken, + (accessToken) => { + if (accessToken && !loginLoading.value) { + loginLoading.value = true; + fetchUserInfo(); + loginLoading.value = false; + } + }, + ); + async function qrcodeLogin( key: string, tenantId?: string, @@ -49,6 +62,20 @@ export const useAuthStore = defineStore('auth', () => { } } + async function phoneLogin( + phoneNumber: string, + code: string, + onSuccess?: () => Promise | void, + ) { + try { + loginLoading.value = true; + const result = await phoneLoginApi({ phoneNumber, code }); + return await _loginSuccess(result, onSuccess); + } finally { + loginLoading.value = false; + } + } + /** * 异步处理登录操作 * Asynchronously handle the login process @@ -126,7 +153,6 @@ export const useAuthStore = defineStore('auth', () => { ) { // 异步处理用户登录操作并获取 accessToken let userInfo: null | UserInfo = null; - loginLoading.value = true; const { accessToken, tokenType, refreshToken } = loginResult; // 如果成功获取到 accessToken if (accessToken) { @@ -172,6 +198,7 @@ export const useAuthStore = defineStore('auth', () => { return { $reset, authLogin, + phoneLogin, qrcodeLogin, fetchUserInfo, loginLoading, diff --git a/apps/vben5/apps/app-antd/src/views/_core/authentication/code-login.vue b/apps/vben5/apps/app-antd/src/views/_core/authentication/code-login.vue index 556b273af..8238ed31d 100644 --- a/apps/vben5/apps/app-antd/src/views/_core/authentication/code-login.vue +++ b/apps/vben5/apps/app-antd/src/views/_core/authentication/code-login.vue @@ -1,29 +1,42 @@