我的页:未授权/退出登录后显示「未登录」,点资料卡去授权;资料弹窗妈妈栏换授权提示 v26101007

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 06:14:30 +00:00
parent 7f1a7d5aaa
commit b4e80def9e
3 changed files with 40 additions and 12 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26101006';
var VER = '26101007';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -1138,6 +1138,10 @@
新用户(未完善资料):昵称/小名/预产期/孕周全空 + 孕周锁定,只留 placeholder。 */
function fillProfileForm() {
$('#pfName').value = state.userName || '';
/* 方案A(2026-10-10):未授权 → 妈妈栏换成授权提示,旧昵称/头像不露出 */
var _ua = state.authorized === false;
['#pfMe', '#pfMeTip'].forEach(function (sel) { var el = $(sel); if (el) el.style.display = _ua ? 'none' : ''; });
var _uh = $('#pfUnauth'); if (_uh) _uh.style.display = _ua ? '' : 'none';
pgName.value = state.babyName || '';
$$('#pgSex .pick').forEach(b => b.classList.toggle('is-active', (b.dataset.sex || 'unknown') === (state.babySex || 'unknown')));
if (state.postpartum) {
@@ -1676,8 +1680,12 @@
/* ---- 妈妈那半(本地即时生效)----
身份模型:卡片统一读档案;资料编辑的昵称/头像也是档案的一部分(最后写者胜)。
落库在下方 fetch(头像需先上传换 URL)。 */
$('#meName').textContent = name;
state.userName = name;
/* 未授权时妈妈栏是隐藏的:不写昵称/头像,否则会把旧昵称重新存回去 */
const _unauth = state.authorized === false;
if (!_unauth) {
$('#meName').textContent = name;
state.userName = name;
}
/* ⚠️ 这里原来还有一行 state.userBio = bio 和一次 syncBio() 调用。
一句话签名整块已按用户要求删除(输入框 #pfBio、展示行 #meBio、
syncBio()、state.userBio 四处一起删),别只加回其中一处。 */
@@ -1699,10 +1707,10 @@
var body = {
babyName: babyName,
babySex: state.babySex,
dueDate: state.due ? toISO(state.due) : '',
userName: name
dueDate: state.due ? toISO(state.due) : ''
};
if (avatarUrl) {
if (!_unauth) body.userName = name;
if (avatarUrl && !_unauth) {
body.avatar = avatarUrl;
meAvatarImg.src = avatarUrl; /* 用正式 URL 替换 base64 预览 */
}
@@ -3222,8 +3230,10 @@
if (p.dueDate) { const d = parseDay(p.dueDate); if (d) state.due = d; }
/* 状态化「我的」页:未授权→占位+显示授权入口;已授权→资料+隐藏授权入口;已建档(B→C)由孕期信息卡引导 */
var _authorized = !!p.authorized || !!p.isAuthorized;
var _n = $('#meName'); if (_n) _n.textContent = p.userName || '未登录';
if (p.avatar) {
state.authorized = _authorized;
/* 方案A:显示看 authorized 而不是 userName —— 后端退出只置 authorized=false,昵称/头像仍在库里 */
var _n = $('#meName'); if (_n) _n.textContent = (_authorized && p.userName) || '未登录';
if (p.avatar && _authorized) {
var _ai = $('#meAvatarImg'), _aw = $('#meAvatar');
if (_ai) _ai.src = p.avatar;
if (_aw) _aw.classList.add('has-img');
@@ -3231,7 +3241,11 @@
/* 授权入口:未授权时显示(引导先授权);退出按钮:已授权时显示 */
var _box = $('#meAuthBox'); if (_box) _box.style.display = _authorized ? 'none' : '';
['#meLogoutCard', '#pfLogout'].forEach(function (sel) { var _lx = $(sel); if (_lx) _lx.style.display = _authorized ? '' : 'none'; });
if (!p.userName) { var _ai2 = $('#meAvatarImg'); if (_ai2) _ai2.removeAttribute('src'); }
if (!p.userName || !_authorized) {
var _ai2 = $('#meAvatarImg'), _aw2 = $('#meAvatar');
if (_ai2) _ai2.removeAttribute('src');
if (_aw2) _aw2.classList.remove('has-img');
}
}
if (pg && pg.code === 200 && pg.result) {
if (pg.result.postpartum) {
@@ -5406,6 +5420,15 @@
}
var meAuth = $('#meAuthCard');
if (meAuth) meAuth.addEventListener('click', goAuth);
/* 方案A:未授权时点「我的」页顶部资料卡 → 直接去授权,不打开资料弹窗(捕获阶段拦在 data-modal 之前) */
var meCard = $('.me-card');
if (meCard) meCard.addEventListener('click', function (e) {
if (state.authorized !== false) return;
if (e.target.closest && e.target.closest('#meLogoutCard')) return;
e.preventDefault(); e.stopImmediatePropagation(); goAuth();
}, true);
var pfUnauth = $('#pfUnauth');
if (pfUnauth) pfUnauth.addEventListener('click', function () { closeModal(); goAuth(); });
/* 「退出登录」(个人资料卡右上角图标按钮):
调后端 /api/mp/public/auth/logout 只清「授权登录信息」三字段(昵称/头像/手机号),