fix(档案): 保存资料失败要提示 —— 配合后端「先推上游、失败即 400 不落库」(v26092204)
后端方案 A:PUT /profile 改预产期/昵称时先推上游用户中心,推失败返回 400 且不落库。 原来这里 .then() 不看响应、.catch() 静默 —— 用户会以为保存成功,下次加载被上游值覆盖回去 ("改了没生效")。现在:非 200 或网络失败都 toast 提示,且不触发 bustReload。 - §4 硬约定新增第 9 条,说明这个接口的失败语义,避免以后又把失败吞掉 - 版本 v26092203 → v26092204
This commit is contained in:
@@ -61,6 +61,10 @@ nginx:`root /opt/app` + `Cache-Control: no-cache` + `etag on` —— 缓存靠
|
||||
⚠️ **只认「返回回到本页」三种情形**(bfcache 的 `pageshow.persisted`、后退重载的
|
||||
`navigation.type === 'back_forward'`、从应用页 `location.href` 回来的 `document.referrer`);
|
||||
**绝不能改成「每次加载都清」** —— 宿主恢复会把本页当返回落点加载,误清会毁掉刚用上的记录。
|
||||
9. **保存资料失败必须提示,不能静默**(2026-09-22「档案以上游为准」):
|
||||
`PUT /profile` 改**预产期/昵称**时,后端会**先推上游用户中心、成功才落库**,推失败返回 `code=400` 且
|
||||
**不落库**。H5 必须弹提示(`_putProfile` 已按此判断 `res.code`)——静默的话下次加载会被上游值覆盖回去,
|
||||
用户以为"改了没生效"。改这个接口的调用方时别再把失败吞掉。
|
||||
|
||||
## 5. 踩坑
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<title>兜爸心选 · 孕育陪伴</title>
|
||||
<!-- V:26092203 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
|
||||
<!-- V:26092204 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
|
||||
<link rel="stylesheet" href="mama-box.css">
|
||||
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
|
||||
<!-- 共享助手:授权/跳商城/位置上报(分享卡片同步,见 docs/h5-auth-standard.md 第四节) -->
|
||||
|
||||
16
js/app.js
16
js/app.js
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
|
||||
var VER = '26092203';
|
||||
var VER = '26092204';
|
||||
const $ = (s, c) => (c || document).querySelector(s);
|
||||
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
|
||||
|
||||
@@ -1245,10 +1245,20 @@
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
}).then(function () {
|
||||
}).then(function (r) {
|
||||
return r.json().catch(function () { return null; });
|
||||
}).then(function (res) {
|
||||
/* ⚠️ 2026-09-22(档案以上游为准):预产期/昵称会**先推上游、推失败后端返回 400 且不落库**。
|
||||
这里必须让用户看见失败 —— 静默的话下次加载会被上游值覆盖回去,用户以为"改了没生效"。 */
|
||||
if (!res || res.code !== 200) {
|
||||
toast((res && res.message) || '保存失败,请检查网络后重试');
|
||||
return;
|
||||
}
|
||||
/* 新用户首次完善资料:重载页面 → pregnancy 出真实孕周 */
|
||||
if (_wasEmpty) setTimeout(bustReload, 700);
|
||||
}).catch(function () { /* 保持本地值 */ });
|
||||
}).catch(function () {
|
||||
toast('保存失败,请检查网络后重试');
|
||||
});
|
||||
}
|
||||
var newAvatarFile = (avFile.files && avFile.files[0]) || null;
|
||||
if (newAvatarFile && avBig.classList.contains('has-img')) {
|
||||
|
||||
Reference in New Issue
Block a user