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 */