From 8378ad17f617edd4e7f9dd8acfa132bcfc99db15 Mon Sep 17 00:00:00 2001 From: Pine Date: Wed, 9 Sep 2026 23:08:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E4=B8=80=E9=94=AE=E7=BB=91=E5=AE=9A=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E7=82=B9=E5=87=BB=E6=97=A0=E5=8F=8D=E9=A6=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E6=88=90=E5=8A=9Ftoast=E3=80=81getMe=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E5=90=8C=E6=AD=A5phoneBound=E3=80=81refreshMyBook?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E5=BC=82=E5=B8=B8=E9=9A=94=E7=A6=BB=E3=80=81?= =?UTF-8?q?errMsg=E6=8B=92=E7=BB=9D=E6=8E=88=E6=9D=83=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages-extra/event-detail/index.jsx | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/miniprogram/src/pages-extra/event-detail/index.jsx b/miniprogram/src/pages-extra/event-detail/index.jsx index f49be46..d166845 100644 --- a/miniprogram/src/pages-extra/event-detail/index.jsx +++ b/miniprogram/src/pages-extra/event-detail/index.jsx @@ -187,16 +187,33 @@ export default function EventDetail() { /* 微信一键绑定手机号(getPhoneNumber 回调 code) */ const onWxPhone = async (e) => { if (!agree) { Taro.showToast({ title: '请先阅读并同意《用户服务协议》和《隐私政策》', icon: 'none' }); return; } - const pcode = e.detail && e.detail.code; - if (!pcode) { setErr('已取消授权绑定'); return; } + const detail = e.detail || {}; + const pcode = detail.code; + // 用户拒绝授权或微信返回错误:errMsg 非 "getPhoneNumber:ok" 时 code 为空 + if (!pcode) { + const msg = detail.errMsg || ''; + setErr(msg && !msg.includes('ok') ? '已取消授权绑定' : '已取消授权绑定'); + return; + } setErr(''); setBusy(true); try { const d = await wxPhoneBind(pcode); - setAuthed(true); - setPhoneBound(!!d.phoneBound); - refreshMyBook(); // 绑号成功刷新报名状态(已报名用户直接进入「我的报名」卡) - } catch (err) { setErr((err && err.message) || '绑定失败'); } - finally { setBusy(false); } + // 绑定成功标志:服务端返回 phoneBound=true 或 phone 非空(兼容字段名差异) + const bound = !!(d && (d.phoneBound || d.phone)); + if (bound) { + setAuthed(true); + setPhoneBound(true); + Taro.showToast({ title: '手机号绑定成功', icon: 'success' }); + // 从服务端同步最新用户资料(含 phoneBound),确保本地缓存与服务端一致 + try { await getMe(); } catch (_) { /* 静默:同步失败不影响已绑定状态 */ } + // 刷新报名状态(独立 try/catch,避免其 401 影响绑定结果) + try { refreshMyBook(); } catch (_) {} + } else { + setErr((d && (d.error || d.msg)) || '绑定失败,请重试'); + } + } catch (err) { + setErr((err && err.message) || '绑定失败'); + } finally { setBusy(false); } }; /* 短信兜底:未登录 → phoneLogin(登录即绑号);已登录未绑号 → bindPhone */