fix(login): 验证码发送失败时同样进入60s倒计时并禁用按钮,配合服务端冷却避免触发阿里云流控
This commit is contained in:
@@ -267,21 +267,27 @@ export default function LoginPage() {
|
||||
const res = await authApi.sendCode(phone);
|
||||
message.success("验证码已发送");
|
||||
setSmsStub(res.stub_code || "");
|
||||
setSmsCountdown(60);
|
||||
const timer = window.setInterval(() => {
|
||||
setSmsCountdown((c) => {
|
||||
if (c <= 1) {
|
||||
window.clearInterval(timer);
|
||||
return 0;
|
||||
}
|
||||
return c - 1;
|
||||
});
|
||||
}, 1000);
|
||||
startSmsCountdown();
|
||||
} catch (err) {
|
||||
message.error(err instanceof Error ? err.message : "发送失败");
|
||||
// 服务端存在 60s 发送冷却(阿里云分钟级流控),失败也进入倒计时,避免继续触发
|
||||
startSmsCountdown();
|
||||
}
|
||||
};
|
||||
|
||||
const startSmsCountdown = () => {
|
||||
setSmsCountdown(60);
|
||||
const timer = window.setInterval(() => {
|
||||
setSmsCountdown((c) => {
|
||||
if (c <= 1) {
|
||||
window.clearInterval(timer);
|
||||
return 0;
|
||||
}
|
||||
return c - 1;
|
||||
});
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
const onSmsLogin = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user