身份模型对齐: 新增 /auth/logout 只清授权三字段(保留孕育资料); 退出按钮改调后端; pfSave 落库 PUT /profile + 授权昵称优先 (v26090708)

This commit is contained in:
2026-09-07 23:52:30 +08:00
parent 91db3873ee
commit 712669c651
2 changed files with 48 additions and 27 deletions

View File

@@ -6,8 +6,8 @@
<meta name="theme-color" content="#F4593C"> <meta name="theme-color" content="#F4593C">
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<title>妈妈盒子 · 孕育陪伴</title> <title>妈妈盒子 · 孕育陪伴</title>
<!-- V:26090707 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 --> <!-- V:26090708 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
<link rel="stylesheet" href="mama-box.css?v=26090707"> <link rel="stylesheet" href="mama-box.css?v=26090708">
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head> </head>
<body> <body>
@@ -1758,8 +1758,8 @@
加载失败/离线时 window.wx 为 undefined,goMall() 会降级为 toast 提示, 加载失败/离线时 window.wx 为 undefined,goMall() 会降级为 toast 提示,
不影响应用其余功能。 --> 不影响应用其余功能。 -->
<script src="js/app.js?v=26090707"></script> <script src="js/app.js?v=26090708"></script>
<!-- 页面版本号(排查 webview 缓存):底部会显示 v26090707 --> <!-- 页面版本号(排查 webview 缓存):底部会显示 v26090708 -->
<div id="ver" style="position:fixed;left:0;right:0;bottom:10px;text-align:center;z-index:9999;pointer-events:none;color:#B3A69C;font-size:10px;letter-spacing:.5px">v26090707</div> <div id="ver" style="position:fixed;left:0;right:0;bottom:10px;text-align:center;z-index:9999;pointer-events:none;color:#B3A69C;font-size:10px;letter-spacing:.5px">v26090708</div>
</body> </body>
</html> </html>

View File

@@ -1929,14 +1929,18 @@
const day = Math.min(6, Math.max(0, parseInt(pgDay.value, 10) || 0)); const day = Math.min(6, Math.max(0, parseInt(pgDay.value, 10) || 0));
const sexBtn = $('#pgSex .pick.is-active'); const sexBtn = $('#pgSex .pick.is-active');
/* ---- 妈妈那半 ---- */ /* ---- 妈妈那半 ----
/* 等级徽章已按需求去掉,这里直接写整段文本 */ 身份模型:展示名「授权登录昵称优先」——state.userName 若来自授权登录
$('#meName').textContent = name; (applyRemoteProfile 写入且 _authNameFromAuth 标记),弹窗昵称不覆盖它,
只作本地展示 fallback(state.localName)。 */
if (!state._authNameFromAuth) {
$('#meName').textContent = name;
state.userName = name;
}
if (avBig.classList.contains('has-img')) { if (avBig.classList.contains('has-img')) {
meAvatarImg.src = avPreview.src; meAvatarImg.src = avPreview.src;
meAvatar.classList.add('has-img'); meAvatar.classList.add('has-img');
} }
state.userName = name;
/* ⚠️ 这里原来还有一行 state.userBio = bio 和一次 syncBio() 调用。 /* ⚠️ 这里原来还有一行 state.userBio = bio 和一次 syncBio() 调用。
一句话签名整块已按用户要求删除(输入框 #pfBio、展示行 #meBio、 一句话签名整块已按用户要求删除(输入框 #pfBio、展示行 #meBio、
syncBio()、state.userBio 四处一起删),别只加回其中一处。 */ syncBio()、state.userBio 四处一起删),别只加回其中一处。 */
@@ -1948,6 +1952,17 @@
state.babySex = (sexBtn && sexBtn.dataset.sex) || 'unknown'; state.babySex = (sexBtn && sexBtn.dataset.sex) || 'unknown';
state.due = parseDay(pgDue.value); 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() 就是用户说的「同步到孕期卡上边」那一步 —— /* ⚠️ syncPregnancy() 就是用户说的「同步到孕期卡上边」那一步 ——
它把孕周环、剩余天数、预产期、宝宝多大重刷一遍,顺带 syncBabyWords() 它把孕周环、剩余天数、预产期、宝宝多大重刷一遍,顺带 syncBabyWords()
把全站写着小名的地方(首页三个模块名、来信页标题、回信按钮…)一起改。 把全站写着小名的地方(首页三个模块名、来信页标题、回信按钮…)一起改。
@@ -3994,8 +4009,13 @@
if (_aw) _aw.classList.add('has-img'); if (_aw) _aw.classList.add('has-img');
} }
var _box = $('#meAuthBox'); if (_box) _box.style.display = _auth ? 'none' : ''; var _box = $('#meAuthBox'); if (_box) _box.style.display = _auth ? 'none' : '';
/* 退出按钮只在已登录(有 userName)时显示 —— 未登录"退出"没有意义 */ /* 授权信息优先:后端返回的 userName/avatar 即「授权登录信息」(含 CRMEB 同步),
var _lx = $('#meLogoutBtn'); if (_lx) _lx.style.display = p.userName ? '' : 'none'; 标记 _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 (!p.userName) { var _ai2 = $('#meAvatarImg'); if (_ai2) _ai2.removeAttribute('src'); }
} }
if (pg && pg.code === 200 && pg.result) { if (pg && pg.code === 200 && pg.result) {
@@ -4158,8 +4178,10 @@
var meAuth = $('#meAuthCard'); var meAuth = $('#meAuthCard');
if (meAuth) meAuth.addEventListener('click', goAuth); if (meAuth) meAuth.addEventListener('click', goAuth);
/* 「退出登录」(个人资料卡右上角图标按钮):清除本机身份(openid/unionid/资料展示) /* 「退出登录」(个人资料卡右上角图标按钮):
→ 重新加载页面回到未登录态,便于直接测试授权流程。 调后端 /api/mp/public/auth/logout 只清「授权登录信息」三字段(昵称/头像/手机号),
openid/unionid(小程序匿名身份)保留,孕育资料(小名/性别/预产期)保留。
成功后重载页面 → applyRemoteProfile 重新拉到空显示字段 → 回到未登录态、授权入口重现。
⚠️ stopPropagation:me-card 整卡是 data-modal="modalProfile",不阻止冒泡 ⚠️ stopPropagation:me-card 整卡是 data-modal="modalProfile",不阻止冒泡
会顺带打开资料弹窗。 */ 会顺带打开资料弹窗。 */
var meLogout = $('#meLogoutBtn'); var meLogout = $('#meLogoutBtn');
@@ -4167,20 +4189,19 @@
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
haptic(); haptic();
if (!(window.wx && window.wx.miniProgram)) { toast('请在微信小程序中打开'); return; } var openid = hashParam('openid');
try { if (location.hash) location.hash = ''; } catch (e2) {} if (!openid) { toast('未获得身份,无法退出'); return; }
// 清除本地读取到的 openid/unionid,回到未登录态 fetch('/api/mp/public/auth/logout?openid=' + encodeURIComponent(openid), { method: 'POST' })
try { .then(function (r) { return r.json(); })
var base = location.href.split('#')[0]; .then(function (res) {
// 保留 query 里的结构与版本戳,仅去掉身份参数 if (res.code === 200) {
var q = (location.search || '').replace(/([?&])openid=[^&]*(&|$)/g, '$1') toast('已退出登录');
.replace(/([?&])unionid=[^&]*(&|$)/g, '$1').replace(/\?&$/, '?').replace(/&$/, ''); setTimeout(function () { location.replace(location.href.split('#')[0] + '?t=' + Date.now()); }, 600);
var url = base + (q && q !== '?' ? q : '') ; } else {
// 重新加载当前 H5(去掉身份)→ applyRemoteProfile 因无 openid 跳过,页面回到未登录占位 toast(res.message || '退出失败,请重试');
location.replace(url + '?t=' + Date.now()); }
} catch (e3) { })
toast('已清除身份'); .catch(function () { toast('退出失败,请检查网络'); });
}
}); });
/* 从商城/后台切回小程序首页时,webview 会再次可见 —— 把 H5 重置回「首页」屏。 /* 从商城/后台切回小程序首页时,webview 会再次可见 —— 把 H5 重置回「首页」屏。