From 107fcaca8465dfb7f3606e3c7cf880d894aa8b2c Mon Sep 17 00:00:00 2001 From: karlcarlo Date: Sun, 11 Oct 2026 15:41:22 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AD=95=E5=91=A8=E7=BB=9F=E4=B8=80=EF=BC=9A?= =?UTF-8?q?=E5=9B=9E=E5=88=B0=E5=89=8D=E5=8F=B0/=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=AD=95=E6=9C=9F=E6=A1=A3=E6=A1=88=E9=87=8D=E6=8B=89=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=E5=AD=95=E6=9C=9F=EF=BC=9B=E4=BF=9D=E5=AD=98=E6=97=B6?= =?UTF-8?q?=E9=A2=84=E4=BA=A7=E6=9C=9F=E6=9C=AA=E6=94=B9=E4=B8=8D=E5=9B=9E?= =?UTF-8?q?=E5=86=99=20v26101030?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: AI 助手 --- index.html | 2 +- js/app.js | 94 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/index.html b/index.html index f34de80..a63218e 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ 兜爸心选 · 孕育陪伴 - + diff --git a/js/app.js b/js/app.js index 24b1835..72016b7 100644 --- a/js/app.js +++ b/js/app.js @@ -3,7 +3,7 @@ (function () { 'use strict'; /* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */ - var VER = '26101029'; + var VER = '26101030'; const $ = (s, c) => (c || document).querySelector(s); const $$ = (s, c) => Array.from((c || document).querySelectorAll(s)); @@ -980,7 +980,10 @@ m.classList.add('show'); haptic(); /* 「我的资料」打开时按服务端档案回填表单(新用户全空,不残留演示默认值) */ - if (id === 'modalProfile') fillProfileForm(); + if (id === 'modalProfile') { + fillProfileForm(); + refreshPregnancy().then(function (changed) { if (changed && openedModal === m) fillProfileForm(); }); + } /* 有些弹窗的主角不是输入框。企业微信那个弹窗正中间是一张二维码, 用户要做的第一件事是**举起另一台手机去扫它**;自动聚焦输入框会把 手机键盘顶上来,恰好盖住二维码的下半截。所以给一个显式的退出口, @@ -1255,6 +1258,7 @@ /* 打开资料弹窗时的表单回填:全部以服务端档案为准(最后写入者胜)。 新用户(未完善资料):昵称/小名/预产期/孕周全空 + 孕周锁定,只留 placeholder。 */ + let filledDue = ''; function fillProfileForm() { pickedAvatar = ''; $('#pfName').value = state.userName || ''; @@ -1283,6 +1287,7 @@ pgDay.value = ''; lockWeekFields(true); } + filledDue = pgDue.value || ''; syncDuePh(); setPgMode('due'); if (pgLmp) { pgLmp.value = ''; pgLmp.dispatchEvent(new Event('change')); } @@ -1977,8 +1982,10 @@ var body = { babyName: babyName, babySex: state.babySex, - dueDate: state.due ? toISO(state.due) : '' }; + /* 预产期没改就不传:表单可能是几分钟前回填的,别的应用这期间改过的话会被旧值盖回去 */ + var _due = state.due ? toISO(state.due) : ''; + if (_due !== filledDue || _wasEmpty) body.dueDate = _due; if (!_unauth) body.userName = name; if (avatarUrl && !_unauth) { body.avatar = avatarUrl; @@ -3454,6 +3461,59 @@ /* ② 资料最多等这么久(ms)就让 ③ 应用数据照常发出:上游慢/挂住时首页不能空等 */ const REMOTE_PROFILE_WAIT_MS = 10000; + /* 孕期状态写进 state(/pregnancy 返回体)。首屏和「回到前台 / 打开孕期档案」重拉共用。 + 2026-10-11 用户:所有应用孕周必须统一 —— 别的应用改了预产期,回到首页要跟着变。 */ + function applyPregnancy(pg) { + if (pg && pg.code === 200 && pg.result) { + if (pg.result.postpartum) { + /* 产后态(2026-09-22):上游 journey_stage=postpartum / 有 baby_birth_date。 + ⚠️ 必须**先**判它再判 empty/week==null —— 产后返回体的 week 也是 null, + 落到下面那个分支会被当成「未完善资料」,给已生产的用户弹建档引导。 */ + state.postpartum = true; + state.pregEmpty = false; + state.week = null; + state.day = null; + state.babyAgeTxt = pg.result.babyAgeTxt || '宝宝已出生'; + state.babyAgeDays = (pg.result.babyAgeDays == null ? null : pg.result.babyAgeDays); + state.babyBirthDate = pg.result.babyBirthDate || ''; + if (pg.result.due) { const d = parseDay(pg.result.due); if (d) state.due = d; } + } else if (pg.result.empty || pg.result.week == null) { + state.postpartum = false; + state.pregEmpty = true; + state.due = null; + state.week = null; + state.day = null; + } else { + state.postpartum = false; + state.pregEmpty = false; + state.week = pg.result.week; + state.day = pg.result.day; + if (pg.result.due) { const d = parseDay(pg.result.due); if (d) state.due = d; } + } + } + } + let _pregAt = 0; + function refreshPregnancy() { + const openid = hashParam('openid'); + if (!openid || DEMO) return Promise.resolve(false); + return fetch('/api/mp/public/mama-box/pregnancy?openid=' + encodeURIComponent(openid)) + .then(r => (r.ok ? r.json() : null)) + .then(function (pg) { + if (!pg || pg.code !== 200 || !pg.result) return false; + const before = state.due ? toISO(state.due) : ''; + applyPregnancy(pg); + _pregAt = Date.now(); + if ((state.due ? toISO(state.due) : '') === before) return false; + syncPregnancy(); + if (!state.pregEmpty && !state.postpartum) { syncBabyWords(); syncStaticDates(); } + return true; + }).catch(function () { return false; }); + } + document.addEventListener('visibilitychange', function () { + if (document.visibilityState === 'visible' && Date.now() - _pregAt > 5000) refreshPregnancy(); + }); + window.addEventListener('pageshow', function (e) { if (e.persisted) refreshPregnancy(); }); + let _profileApplied = false; /* ⚠️ 返回 Promise:调用方要**等资料落地**再取应用数据(预产期/小名来自上游同步, 它决定 state.pregEmpty,而今日脚印的显隐依赖它)。别改成 fire-and-forget。 */ @@ -3525,33 +3585,7 @@ if (_aw2) _aw2.classList.remove('has-img'); } } - if (pg && pg.code === 200 && pg.result) { - if (pg.result.postpartum) { - /* 产后态(2026-09-22):上游 journey_stage=postpartum / 有 baby_birth_date。 - ⚠️ 必须**先**判它再判 empty/week==null —— 产后返回体的 week 也是 null, - 落到下面那个分支会被当成「未完善资料」,给已生产的用户弹建档引导。 */ - state.postpartum = true; - state.pregEmpty = false; - state.week = null; - state.day = null; - state.babyAgeTxt = pg.result.babyAgeTxt || '宝宝已出生'; - state.babyAgeDays = (pg.result.babyAgeDays == null ? null : pg.result.babyAgeDays); - state.babyBirthDate = pg.result.babyBirthDate || ''; - if (pg.result.due) { const d = parseDay(pg.result.due); if (d) state.due = d; } - } else if (pg.result.empty || pg.result.week == null) { - state.postpartum = false; - state.pregEmpty = true; - state.due = null; - state.week = null; - state.day = null; - } else { - state.postpartum = false; - state.pregEmpty = false; - state.week = pg.result.week; - state.day = pg.result.day; - if (pg.result.due) { const d = parseDay(pg.result.due); if (d) state.due = d; } - } - } + applyPregnancy(pg); if (DEMO) { // 示例模式:固定孕 29 周 0 天,预产期 = 今天 + (280 - 203) 天 state.postpartum = false; state.pregEmpty = false; state.week = DEMO_WEEK; state.day = 0;