fix: 注册时发送邮件验证码没有等待时间
This commit is contained in:
@@ -80,6 +80,8 @@ const RegisterForm = () => {
|
|||||||
const [verificationCodeLoading, setVerificationCodeLoading] = useState(false);
|
const [verificationCodeLoading, setVerificationCodeLoading] = useState(false);
|
||||||
const [otherRegisterOptionsLoading, setOtherRegisterOptionsLoading] = useState(false);
|
const [otherRegisterOptionsLoading, setOtherRegisterOptionsLoading] = useState(false);
|
||||||
const [wechatCodeSubmitLoading, setWechatCodeSubmitLoading] = useState(false);
|
const [wechatCodeSubmitLoading, setWechatCodeSubmitLoading] = useState(false);
|
||||||
|
const [disableButton, setDisableButton] = useState(false);
|
||||||
|
const [countdown, setCountdown] = useState(30);
|
||||||
|
|
||||||
const logo = getLogo();
|
const logo = getLogo();
|
||||||
const systemName = getSystemName();
|
const systemName = getSystemName();
|
||||||
@@ -106,6 +108,19 @@ const RegisterForm = () => {
|
|||||||
}
|
}
|
||||||
}, [status]);
|
}, [status]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let countdownInterval = null;
|
||||||
|
if (disableButton && countdown > 0) {
|
||||||
|
countdownInterval = setInterval(() => {
|
||||||
|
setCountdown(countdown - 1);
|
||||||
|
}, 1000);
|
||||||
|
} else if (countdown === 0) {
|
||||||
|
setDisableButton(false);
|
||||||
|
setCountdown(30);
|
||||||
|
}
|
||||||
|
return () => clearInterval(countdownInterval); // Clean up on unmount
|
||||||
|
}, [disableButton, countdown]);
|
||||||
|
|
||||||
const onWeChatLoginClicked = () => {
|
const onWeChatLoginClicked = () => {
|
||||||
setWechatLoading(true);
|
setWechatLoading(true);
|
||||||
setShowWeChatLoginModal(true);
|
setShowWeChatLoginModal(true);
|
||||||
@@ -198,6 +213,7 @@ const RegisterForm = () => {
|
|||||||
const { success, message } = res.data;
|
const { success, message } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
showSuccess('验证码发送成功,请检查你的邮箱!');
|
showSuccess('验证码发送成功,请检查你的邮箱!');
|
||||||
|
setDisableButton(true); // 发送成功后禁用按钮,开始倒计时
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
}
|
}
|
||||||
@@ -454,9 +470,10 @@ const RegisterForm = () => {
|
|||||||
<Button
|
<Button
|
||||||
onClick={sendVerificationCode}
|
onClick={sendVerificationCode}
|
||||||
loading={verificationCodeLoading}
|
loading={verificationCodeLoading}
|
||||||
|
disabled={disableButton || verificationCodeLoading}
|
||||||
size="small"
|
size="small"
|
||||||
>
|
>
|
||||||
{t('获取验证码')}
|
{disableButton ? `${t('重新发送')} (${countdown})` : t('获取验证码')}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user