From 712669c651bb3f4a76753a375ed2283a7abc8c4c Mon Sep 17 00:00:00 2001 From: Karlcarlo Date: Mon, 7 Sep 2026 23:52:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E6=A8=A1=E5=9E=8B=E5=AF=B9?= =?UTF-8?q?=E9=BD=90:=20=E6=96=B0=E5=A2=9E=20/auth/logout=20=E5=8F=AA?= =?UTF-8?q?=E6=B8=85=E6=8E=88=E6=9D=83=E4=B8=89=E5=AD=97=E6=AE=B5(?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E5=AD=95=E8=82=B2=E8=B5=84=E6=96=99);=20?= =?UTF-8?q?=E9=80=80=E5=87=BA=E6=8C=89=E9=92=AE=E6=94=B9=E8=B0=83=E5=90=8E?= =?UTF-8?q?=E7=AB=AF;=20pfSave=20=E8=90=BD=E5=BA=93=20PUT=20/profile=20+?= =?UTF-8?q?=20=E6=8E=88=E6=9D=83=E6=98=B5=E7=A7=B0=E4=BC=98=E5=85=88=20(v2?= =?UTF-8?q?6090708)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 10 ++++----- js/app.js | 65 ++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index 8d59e59..96acbf3 100644 --- a/index.html +++ b/index.html @@ -6,8 +6,8 @@ 妈妈盒子 · 孕育陪伴 - - + + @@ -1758,8 +1758,8 @@ 加载失败/离线时 window.wx 为 undefined,goMall() 会降级为 toast 提示, 不影响应用其余功能。 --> - - -
v26090707
+ + +
v26090708
diff --git a/js/app.js b/js/app.js index bf52237..e2636df 100644 --- a/js/app.js +++ b/js/app.js @@ -1929,14 +1929,18 @@ const day = Math.min(6, Math.max(0, parseInt(pgDay.value, 10) || 0)); const sexBtn = $('#pgSex .pick.is-active'); - /* ---- 妈妈那半 ---- */ - /* 等级徽章已按需求去掉,这里直接写整段文本 */ - $('#meName').textContent = name; + /* ---- 妈妈那半 ---- + 身份模型:展示名「授权登录昵称优先」——state.userName 若来自授权登录 + (applyRemoteProfile 写入且 _authNameFromAuth 标记),弹窗昵称不覆盖它, + 只作本地展示 fallback(state.localName)。 */ + if (!state._authNameFromAuth) { + $('#meName').textContent = name; + state.userName = name; + } if (avBig.classList.contains('has-img')) { meAvatarImg.src = avPreview.src; meAvatar.classList.add('has-img'); } - state.userName = name; /* ⚠️ 这里原来还有一行 state.userBio = bio 和一次 syncBio() 调用。 一句话签名整块已按用户要求删除(输入框 #pfBio、展示行 #meBio、 syncBio()、state.userBio 四处一起删),别只加回其中一处。 */ @@ -1948,6 +1952,17 @@ state.babySex = (sexBtn && sexBtn.dataset.sex) || 'unknown'; state.due = parseDay(pgDue.value); + /* ---- 落库:孕育字段走 PUT /profile(只收 babyName/babySex/dueDate, + 显示字段后端明确不收)→ 刷新/重进后资料不丢。失败静默,本地已生效。 ---- */ + var _oid = hashParam('openid'); + if (_oid) { + fetch('/api/mp/public/mama-box/profile?openid=' + encodeURIComponent(_oid), { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ babyName: babyName, babySex: state.babySex, dueDate: state.due ? toISO(state.due) : '' }) + }).catch(function () { /* 断网时保持本地值,页面照常用 */ }); + } + /* ⚠️ syncPregnancy() 就是用户说的「同步到孕期卡上边」那一步 —— 它把孕周环、剩余天数、预产期、宝宝多大重刷一遍,顺带 syncBabyWords() 把全站写着小名的地方(首页三个模块名、来信页标题、回信按钮…)一起改。 @@ -3994,8 +4009,13 @@ if (_aw) _aw.classList.add('has-img'); } var _box = $('#meAuthBox'); if (_box) _box.style.display = _auth ? 'none' : ''; - /* 退出按钮只在已登录(有 userName)时显示 —— 未登录"退出"没有意义 */ - var _lx = $('#meLogoutBtn'); if (_lx) _lx.style.display = p.userName ? '' : 'none'; + /* 授权信息优先:后端返回的 userName/avatar 即「授权登录信息」(含 CRMEB 同步), + 标记 _authNameFromAuth —— 「我的资料」弹窗保存时不覆盖它(见 pfSave)。 */ + if (p.userName) { + state._authNameFromAuth = true; + } + /* 退出按钮只在已登录(任一授权资料非空)时显示 —— 未登录"退出"没有意义 */ + var _lx = $('#meLogoutBtn'); if (_lx) _lx.style.display = _auth ? '' : 'none'; if (!p.userName) { var _ai2 = $('#meAvatarImg'); if (_ai2) _ai2.removeAttribute('src'); } } if (pg && pg.code === 200 && pg.result) { @@ -4158,8 +4178,10 @@ var meAuth = $('#meAuthCard'); if (meAuth) meAuth.addEventListener('click', goAuth); - /* 「退出登录」(个人资料卡右上角图标按钮):清除本机身份(openid/unionid/资料展示) - → 重新加载页面回到未登录态,便于直接测试授权流程。 + /* 「退出登录」(个人资料卡右上角图标按钮): + 调后端 /api/mp/public/auth/logout 只清「授权登录信息」三字段(昵称/头像/手机号), + openid/unionid(小程序匿名身份)保留,孕育资料(小名/性别/预产期)保留。 + 成功后重载页面 → applyRemoteProfile 重新拉到空显示字段 → 回到未登录态、授权入口重现。 ⚠️ stopPropagation:me-card 整卡是 data-modal="modalProfile",不阻止冒泡 会顺带打开资料弹窗。 */ var meLogout = $('#meLogoutBtn'); @@ -4167,20 +4189,19 @@ e.preventDefault(); e.stopPropagation(); haptic(); - if (!(window.wx && window.wx.miniProgram)) { toast('请在微信小程序中打开'); return; } - try { if (location.hash) location.hash = ''; } catch (e2) {} - // 清除本地读取到的 openid/unionid,回到未登录态 - try { - var base = location.href.split('#')[0]; - // 保留 query 里的结构与版本戳,仅去掉身份参数 - var q = (location.search || '').replace(/([?&])openid=[^&]*(&|$)/g, '$1') - .replace(/([?&])unionid=[^&]*(&|$)/g, '$1').replace(/\?&$/, '?').replace(/&$/, ''); - var url = base + (q && q !== '?' ? q : '') ; - // 重新加载当前 H5(去掉身份)→ applyRemoteProfile 因无 openid 跳过,页面回到未登录占位 - location.replace(url + '?t=' + Date.now()); - } catch (e3) { - toast('已清除身份'); - } + var openid = hashParam('openid'); + if (!openid) { toast('未获得身份,无法退出'); return; } + fetch('/api/mp/public/auth/logout?openid=' + encodeURIComponent(openid), { method: 'POST' }) + .then(function (r) { return r.json(); }) + .then(function (res) { + if (res.code === 200) { + toast('已退出登录'); + setTimeout(function () { location.replace(location.href.split('#')[0] + '?t=' + Date.now()); }, 600); + } else { + toast(res.message || '退出失败,请重试'); + } + }) + .catch(function () { toast('退出失败,请检查网络'); }); }); /* 从商城/后台切回小程序首页时,webview 会再次可见 —— 把 H5 重置回「首页」屏。