From 9d150ee29206c4a25db33f969a2c273cf33fa284 Mon Sep 17 00:00:00 2001 From: rd <1344903914@qq.com> Date: Mon, 8 Sep 2025 17:59:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=AA=8C=E8=AF=81=E7=A0=81=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=99=90=E6=B5=81=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/all/common.ts | 5 +++++ .../login/components/login-form/index.vue | 21 +++++++++++++------ .../login/components/register-form/index.vue | 21 +++++++++++++------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/api/all/common.ts b/src/api/all/common.ts index 574d7e9..fc1e92a 100644 --- a/src/api/all/common.ts +++ b/src/api/all/common.ts @@ -72,3 +72,8 @@ export const getImagePreSignedUrl = (params = {}) => { export const getVideoPreSignedUrl = (params = {}) => { return Http.get('/v1/oss/video-pre-signed-url', params); }; + +// 清除限流 +export const postClearRateLimiter = (params = {}) => { + return Http.post(`/v1/rate-limiter/clear`, params); +}; \ No newline at end of file diff --git a/src/views/login/components/login-form/index.vue b/src/views/login/components/login-form/index.vue index fff1791..0dec9e4 100644 --- a/src/views/login/components/login-form/index.vue +++ b/src/views/login/components/login-form/index.vue @@ -117,6 +117,7 @@ const { TabPane } = Tabs; import PuzzleVerification from '../PuzzleVerification.vue'; import SelectAccountModal from '../select-account-modal/index.vue'; import { fetchLoginCaptCha, fetchAuthorizationsCaptcha, fetchProfileInfo, postLoginPassword } from '@/api/all/login'; +import { postClearRateLimiter } from '@/api/all/common'; import { joinEnterpriseByInviteCode } from '@/api/all'; import { ref, reactive, onUnmounted, computed } from 'vue'; import { useUserStore } from '@/stores'; @@ -239,27 +240,35 @@ const getCode = async () => { if (!canGetCaptcha.value) return; formRef.value.validateFields('mobile').then(() => { - isVerificationVisible.value = true; + getCaptcha(); }); }; -// 验证码验证通过后 -const handleVerificationSubmit = async () => { - isVerificationVisible.value = false; - startCountdown(); - +const getCaptcha = async () => { try { const { code, message: msg } = await fetchLoginCaptCha({ mobile: loginForm.mobile }); if (code === 200) { + startCountdown(); message.success(msg); } } catch (error) { // 重置倒计时 countdown.value = 0; clearInterval(timer.value); + + if (error.status === 429) { + isVerificationVisible.value = true; + } } }; +// 验证码验证通过后 +const handleVerificationSubmit = () => { + isVerificationVisible.value = false; + postClearRateLimiter(); + getCaptcha(); +}; + const onTabChange = () => { errMsg.value = ''; }; diff --git a/src/views/login/components/register-form/index.vue b/src/views/login/components/register-form/index.vue index 5732982..e9a0bb9 100644 --- a/src/views/login/components/register-form/index.vue +++ b/src/views/login/components/register-form/index.vue @@ -103,6 +103,7 @@ const { Link } = Typography; const { TabPane } = Tabs; import PuzzleVerification from '../PuzzleVerification.vue'; import SelectAccountModal from '../select-account-modal/index.vue'; +import { postClearRateLimiter } from '@/api/all/common'; import { postRegisterCaptcha,postForgetPasswordCaptcha, fetchProfileInfo, postRegister, postForgetPassword } from '@/api/all/login'; import { joinEnterpriseByInviteCode } from '@/api/all'; import { ref, reactive, onUnmounted, computed } from 'vue'; @@ -258,28 +259,36 @@ const getCode = async () => { } formRef.value.validateFields('mobile').then(() => { - isVerificationVisible.value = true; + getCaptcha(); }); }; -// 验证码验证通过后 -const handleVerificationSubmit = async () => { - isVerificationVisible.value = false; - startCountdown(); - +const getCaptcha = async () => { try { const fn = isResetPassword.value ? postForgetPasswordCaptcha : postRegisterCaptcha; const { code, message: msg } = await fn({ mobile: formData.value.mobile }); if (code === 200) { + startCountdown() message.success(msg); } } catch (error) { // 重置倒计时 countdown.value = 0; clearInterval(timer.value); + + if (error.status === 429) { + isVerificationVisible.value = true; + } } }; +// 验证码验证通过后 +const handleVerificationSubmit = () => { + isVerificationVisible.value = false; + postClearRateLimiter(); + getCaptcha(); +}; + // 获取用户信息 const getProfileInfo = async () => { const { code, data } = await fetchProfileInfo();