新用户空态补全: 信件空响应清内置样例(不再回退演示信); 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

@@ -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:26090710 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 --> <!-- V:26090711 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
<link rel="stylesheet" href="mama-box.css?v=26090710"> <link rel="stylesheet" href="mama-box.css?v=26090711">
<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=26090710"></script> <script src="js/app.js?v=26090711"></script>
<!-- 页面版本号(排查 webview 缓存):底部会显示 v26090710 --> <!-- 页面版本号(排查 webview 缓存):底部会显示 v26090711 -->
<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">v26090710</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">v26090711</div>
</body> </body>
</html> </html>

View File

@@ -1306,6 +1306,7 @@
} }
function renderLetterDetail(L) { function renderLetterDetail(L) {
if (!L) return; /* 新用户空态:没有任何信件可渲染 */
$('#dlWeek').textContent = L.weekTxt; $('#dlWeek').textContent = L.weekTxt;
$('#dlTitle').textContent = L.title; $('#dlTitle').textContent = L.title;
$('#dlDate').textContent = L.dateFull; $('#dlDate').textContent = L.dateFull;
@@ -1989,6 +1990,7 @@
若弹窗里新选了头像(avFile 有文件),先 POST /upload 换正式 URL 再一起提交; 若弹窗里新选了头像(avFile 有文件),先 POST /upload 换正式 URL 再一起提交;
上传失败则跳过头像字段(昵称/孕育照存)。断网/接口失败静默,本地已生效。 ---- */ 上传失败则跳过头像字段(昵称/孕育照存)。断网/接口失败静默,本地已生效。 ---- */
var _oid = hashParam('openid'); var _oid = hashParam('openid');
var _wasEmpty = state.pregEmpty; /* 新用户完善资料后 → 重载拉真实孕周+播种信 */
function _putProfile(avatarUrl) { function _putProfile(avatarUrl) {
if (!_oid) return; if (!_oid) return;
var body = { var body = {
@@ -2005,6 +2007,9 @@
method: 'PUT', method: 'PUT',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body) body: JSON.stringify(body)
}).then(function () {
/* 新用户首次完善资料:重载页面 → pregnancy 出真实孕周、样例信播种 */
if (_wasEmpty) setTimeout(function () { location.replace(location.href.split('#')[0] + '?t=' + Date.now()); }, 700);
}).catch(function () { /* 保持本地值 */ }); }).catch(function () { /* 保持本地值 */ });
} }
var newAvatarFile = (avFile.files && avFile.files[0]) || null; var newAvatarFile = (avFile.files && avFile.files[0]) || null;
@@ -4165,7 +4170,18 @@
var base = '/api/mp/public/mama-box/'; 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; }); }; 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) { 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) { Promise.all(lj.result.items.map(function (it) {
return j(base + 'letters/' + encodeURIComponent(it.key) + '?openid=' + encodeURIComponent(openid)); return j(base + 'letters/' + encodeURIComponent(it.key) + '?openid=' + encodeURIComponent(openid));
})).then(function (dets) { })).then(function (dets) {