Просмотр исходного кода

fix(login): 返回修改手机号后再点获取验证码无反应

## 现象

发送验证码 → 点「返回修改手机号」→ 再点「获取验证码」→ 没有任何反应。

## 根因(三个问题叠加)

1. backToPhone() 返回时**没停倒计时**,countdown 继续往下跑
2. 手机号页的按钮只判 !phoneValid() || busy(),看起来**可点**
3. sendCode() 第一行 countdown() > 0 直接 return,**不给任何提示**

用户看到的就是「点了没反应」,分不清是没点中、坏了、还是在等冷却。

## 修复

① backToPhone() 调用新增的 stopCountdown() —— 返回即视为放弃这次验证码
② sendCode() 在倒计时中给出明确提示「请等待 N 秒后再试」

## 真机验证(小米 M2102K1AC)

发码(55s 倒计时)→ 返回手机号页 → 再点获取验证码
→ ✅ 显示「发送过于频繁,请稍后再试(同一号码通常 60 秒内只能发一次)」

(这条是服务端 60s 限流的真实原因,现在如实告知用户)

单测 1861/1861 通过。

Co-Authored-By: Claude Code <noreply@anthropic.com>
Huccct 4 дней назад
Родитель
Сommit
85635679f2
1 измененных файлов с 41 добавлено и 1 удалено
  1. 41 1
      src/app/mobile/pages/login/login.ts

+ 41 - 1
src/app/mobile/pages/login/login.ts

@@ -390,12 +390,52 @@ export class MbLoginPage implements OnDestroy {
     this.stage.set('phone');
     this.code.set('');
     this.error.set(null);
+    /*
+     * 🔴 返回手机号页时**停掉倒计时**(2026-11-18 用户实测 bug)。
+     *
+     * ## 现象
+     *
+     * 发完验证码 → 点「返回修改手机号」→ 再点「获取验证码」→ **没有任何反应**。
+     *
+     * ## 根因
+     *
+     * 这里没停倒计时,`countdown` 还在往下跑;而手机号页的按钮只判
+     * `!phoneValid() || busy()`,看起来是**可点的**。
+     * 点下去 `sendCode()` 第一行 `countdown() > 0` 直接 return、**不给任何提示** ——
+     * 用户看到的就是「点了没反应」。
+     *
+     * ## 修法
+     *
+     * 返回即视为「放弃这次验证码」:停掉定时器、清零倒计时。
+     * 用户重新点发送时是完整的新一轮,不会再被上一轮挡住。
+     */
+    this.stopCountdown();
     this.focus(this.phoneEl());
   }
 
+  /** 停止倒计时并清零(返回 / 卸载 / 重发时调用) */
+  private stopCountdown(): void {
+    if (this.codeTimer) {
+      clearInterval(this.codeTimer);
+      this.codeTimer = null;
+    }
+    this.countdown.set(0);
+  }
+
   /** 发送验证码:真实接口 + 60s 倒计时(Demo 无倒计时,此处按规范补齐防刷) */
   protected async sendCode(): Promise<void> {
-    if (this.sending() || this.countdown() > 0 || this.busy()) return;
+    /*
+     * 🔴 倒计时未结束时给出**明确提示**,不再静默返回(2026-11-18 用户实测)。
+     *
+     * 原来这里直接 `return` —— 用户点了按钮什么都没发生,
+     * 分不清「是没点中」「是坏了」还是「在等冷却」。
+     * 现在告诉他还剩几秒。
+     */
+    if (this.countdown() > 0) {
+      this.error.set(`请等待 ${this.countdown()} 秒后再试`);
+      return;
+    }
+    if (this.sending() || this.busy()) return;
     this.error.set(null);
     if (!this.phoneValid()) {
       this.error.set('请输入正确的 11 位手机号');