feat(首页): 新增「孕期每日小打卡」——按钮带状态小标签 (v26093012)

- 首页正文最上面加一块「孕期每日小打卡」:数胎动 / 称体重 / 产检三行,
  每行右侧一枚状态标签,点整行进对应应用(复用 data-mini + MINI_APP_MAP + jumpApp)。
- 标签来自工具卡同一个接口(applyRemoteCards → renderDaily),不另打请求:
  今日已记 N 次 / 今天还没记;今日已称 / 今天还没称(按接口 day 判今天);
  距 NT 还有 7 天 / 今天糖耐检查 / 待补记 / 看产检安排。
  抬头右端「今日已完成 x/2」(只数胎动、体重两件每日事)。
- 接口没回、访客态保留中性提示,不写数字;产后态整块收起。
- 首块间距规则改为 .home-body>:first-child,工具托盘并入块间 16px。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 13:10:04 +00:00
parent 62b23af323
commit 9ea9f3c50f
3 changed files with 112 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26093011';
var VER = '26093012';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -1048,6 +1048,8 @@
if (p) p.classList.toggle('is-empty', !!on);
}
function syncPregnancy() {
/* 孕期每日小打卡:产后整块收起;其它状态都显示(标签默认是中性提示,不依赖孕周) */
const _dc = $('#dailyCheck'); if (_dc) _dc.classList.toggle('hide', !!state.postpartum);
/* ---- 产后态:宝宝已出生 → 一律不显示孕周数字(2026-09-22) ----
⚠️ 必须放在 pregEmpty 之前:产后返回体的 week 也是 null,
落到空态分支会给**已经生产**的用户弹「完善孕期信息」引导。
@@ -3056,6 +3058,53 @@
}
mark('curve', cv);
}
renderDaily(r.day, k, w, cal);
}
/* 孕期每日小打卡(2026-09-30):把 kick / weight / cal 三槽翻成一句话的状态标签。
数据就是上面这份卡片接口,不另打请求;槽缺失就保留 HTML 里的中性提示(不造数)。
「今天」以接口顶层 day(上游 YYYY-MM-DD,北京时间)为准,别拿本机时钟比 ——
容器/手机时区不一定是东八区,差一天就会把「今日已称」判成「还没称」。
⚠️ 上游字符串一律 textContent。 */
function renderDaily(day, k, w, cal) {
const tag = (id, text, kind) => {
const el = $(id); if (!el) return;
el.textContent = text;
el.classList.toggle('is-done', kind === 'done');
el.classList.toggle('is-warn', kind === 'warn');
};
const d10 = v => (v ? String(v).slice(0, 10) : '');
let done = 0, total = 0;
if (k) {
total++;
const n = parseInt(k.value, 10) || 0;
if (n > 0) { done++; tag('#dcKick', '今日已记 ' + n + ' 次', 'done'); }
else tag('#dcKick', '今天还没记', '');
}
if (w) {
total++;
if (day && d10(w.at) === day) { done++; tag('#dcWeight', '今日已称', 'done'); }
else tag('#dcWeight', '今天还没称', '');
}
if (cal) {
/* sub 形如「糖耐 · 孕25周」,取「·」前那段当检查名;拿不到就叫「产检」。
NT 这类字母名前后补空格:「距 NT 还有 7 天」。 */
let nm = String(cal.sub || '').split('·')[0].trim() || '产检';
if (/^[A-Za-z]/.test(nm)) nm = ' ' + nm + ' ';
const at = d10(cal.at);
const diff = (at && day) ? Math.round((Date.parse(at) - Date.parse(day)) / 864e5) : NaN;
if (cal.warn) tag('#dcCal', cal.label && cal.label !== '下次产检' ? cal.label : '待补记', 'warn');
else if (cal.empty || isNaN(diff) || diff < 0) tag('#dcCal', '看产检安排', '');
else if (diff === 0) tag('#dcCal', '今天' + nm.trim() + (nm.trim() === '产检' ? '' : '检查'), 'warn');
else tag('#dcCal', '距' + nm + '还有 ' + diff + ' 天', '');
}
/* 抬头右端「今日已完成 1/2」:只数每天要做的两件(胎动、体重),产检不是每天的事 */
const dd = $('#dcDone');
if (dd && total) {
dd.textContent = '今日已完成 ' + done + '/' + total;
dd.classList.toggle('is-all', done === total);
dd.classList.remove('hide');
}
}
/* 拉卡片数据(与其它远程数据一起打;失败静默,卡上保留现有值) */