新用户空态补全: 信件空响应清内置样例(不再回退演示信); renderLetterDetail 空守卫; 首次完善资料后重载拉真实数据 (v26090711)

This commit is contained in:
2026-09-08 00:28:06 +08:00
parent e72feb9326
commit f500452d22
2 changed files with 22 additions and 6 deletions

View File

@@ -1306,6 +1306,7 @@
}
function renderLetterDetail(L) {
if (!L) return; /* 新用户空态:没有任何信件可渲染 */
$('#dlWeek').textContent = L.weekTxt;
$('#dlTitle').textContent = L.title;
$('#dlDate').textContent = L.dateFull;
@@ -1989,6 +1990,7 @@
若弹窗里新选了头像(avFile 有文件),先 POST /upload 换正式 URL 再一起提交;
上传失败则跳过头像字段(昵称/孕育照存)。断网/接口失败静默,本地已生效。 ---- */
var _oid = hashParam('openid');
var _wasEmpty = state.pregEmpty; /* 新用户完善资料后 → 重载拉真实孕周+播种信 */
function _putProfile(avatarUrl) {
if (!_oid) return;
var body = {
@@ -2005,6 +2007,9 @@
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
}).then(function () {
/* 新用户首次完善资料:重载页面 → pregnancy 出真实孕周、样例信播种 */
if (_wasEmpty) setTimeout(function () { location.replace(location.href.split('#')[0] + '?t=' + Date.now()); }, 700);
}).catch(function () { /* 保持本地值 */ });
}
var newAvatarFile = (avFile.files && avFile.files[0]) || null;
@@ -4165,7 +4170,18 @@
var base = '/api/mp/public/mama-box/';
var j = function (u) { return fetch(u).then(function (r) { return r.ok ? r.json() : null; }).catch(function () { return null; }); };
j(base + 'letters?openid=' + encodeURIComponent(openid)).then(function (lj) {
if (!lj || lj.code !== 200 || !lj.result || !lj.result.items || !lj.result.items.length) return;
if (!lj || lj.code !== 200 || !lj.result || !lj.result.items) return;
/* 新用户空态:后端成功返回空列表 → 清掉内置样例信,展示「这里还没有内容」。
⚠️ 不能直接 return —— 那会把 LETTERS 留在内置样例上,新用户看到演示信。 */
if (!lj.result.items.length) {
LETTERS.splice(0, LETTERS.length);
state.curLetter = '';
state.homeLetter = '';
renderLetters();
syncLetterCounts();
pushLatestToHome();
return;
}
Promise.all(lj.result.items.map(function (it) {
return j(base + 'letters/' + encodeURIComponent(it.key) + '?openid=' + encodeURIComponent(openid));
})).then(function (dets) {