From 958110cc73dce3c53bfeaa52bc017f7ef794fa89 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 1 Jun 2026 18:54:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp):=20=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= =?UTF-8?q?=20API=20=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=B8=8D=E5=BA=94=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=89=8B=E6=9C=BA=E7=BB=91=E5=AE=9A=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:login() 的 catch 块把所有错误都返回 false, 导致 handleWechatLogin 误判为'未绑定'并显示手机绑定按钮。 用户点击绑定后因 wechat_openid 从未写入而报'登录态丢失'。 修复: - API 失败时 throw 而非 return false,让调用方区分错误和未绑定 - 增加 resp.openid 空值校验,防止后端返回空 openid 进入绑定流程 - 现在后端不可用时用户会看到正确的错误提示而非误导性的绑定按钮 --- apps/miniprogram/src/stores/auth.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/miniprogram/src/stores/auth.ts b/apps/miniprogram/src/stores/auth.ts index 159db24..2348a83 100644 --- a/apps/miniprogram/src/stores/auth.ts +++ b/apps/miniprogram/src/stores/auth.ts @@ -148,13 +148,19 @@ export const useAuthStore = create((set, get) => ({ get().loadPatients(); return true; } + // 未绑定:存储 openid 供后续绑定流程使用 + if (!resp.openid) { + set({ loading: false }); + throw new Error('登录失败:服务器未返回用户标识'); + } secureSet('wechat_openid', resp.openid); set({ loading: false }); return false; } catch (err) { console.warn('[auth] 微信登录失败:', err); set({ loading: false }); - return false; + // 不吞掉错误 — 让调用方区分"未绑定"和"真正的错误" + throw err; } },