From 4c4c00f636f69953fcea579b662dcec20d1ed44d Mon Sep 17 00:00:00 2001 From: Karlcarlo Date: Tue, 22 Sep 2026 13:23:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=A1=A3=E6=A1=88):=20=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E8=B5=84=E6=96=99=E5=A4=B1=E8=B4=A5=E8=A6=81=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=20=E2=80=94=E2=80=94=20=E9=85=8D=E5=90=88=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E3=80=8C=E5=85=88=E6=8E=A8=E4=B8=8A=E6=B8=B8=E3=80=81=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=8D=B3=20400=20=E4=B8=8D=E8=90=BD=E5=BA=93=E3=80=8D?= =?UTF-8?q?(v26092204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端方案 A:PUT /profile 改预产期/昵称时先推上游用户中心,推失败返回 400 且不落库。 原来这里 .then() 不看响应、.catch() 静默 —— 用户会以为保存成功,下次加载被上游值覆盖回去 ("改了没生效")。现在:非 200 或网络失败都 toast 提示,且不触发 bustReload。 - §4 硬约定新增第 9 条,说明这个接口的失败语义,避免以后又把失败吞掉 - 版本 v26092203 → v26092204 --- AGENTS.md | 4 ++++ index.html | 2 +- js/app.js | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 160eb3c..095a96c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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. 踩坑 diff --git a/index.html b/index.html index 9934141..85fa0df 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ 兜爸心选 · 孕育陪伴 - + diff --git a/js/app.js b/js/app.js index 02f26f4..8db916f 100644 --- a/js/app.js +++ b/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')) {