首页:工具与孕期数据合成一个模块+用户自定义首页工具(排序/增删);其他妈妈也在搜加热搜榜样式 v26110101

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deploy
2026-11-01 03:35:12 +00:00
parent 72131f98c6
commit c57546f9ba
3 changed files with 507 additions and 149 deletions

354
js/app.js
View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26103112';
var VER = '26110101';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -421,47 +421,147 @@
function swapArt(id) {
return '<svg class="sw-art" viewBox="2 2 20 20" aria-hidden="true" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' + (SWAP_ART[id] || '') + '</svg>';
}
/* 首页宫格图标 = 各应用在 App 表里的正式 logo(2026-10-31 用户定);替补坑位取替补应用的 logo,拿不到就保留现有图形 */
function toolLogo(id) { const a = APP_BY_ID[id]; return a && (a.logo || a.icon) || ''; }
/* ================= 首页「我的孕期工具」:数据卡 + 图标宫格,用户自选(2026-11-01) =================
用户:「我的孕期数据和上面那个工具结合在一起时,是一个模块……上面所有的工具,用户可以去选择放哪一个,放到什么位置上。」
· 一个模块两层:#vitals 数据卡(2 列,列表里最靠前的 HT_CARDS 个记录类工具)+ #htGrid 小图标宫格(其余工具 + 固定「全部工具」)。
数据卡只在有身份、非产后时出现(原 #vitals 的口径);访客 / 产后全部按小图标排。
· 顺序 = localStorage HT_KEY(identifier 数组)。没存过 = HT_DEFAULT + 孕周替补(原 swapHomeCards 规则:没到门槛的坑位按 SWAP_POOL 换);
存过 = 完全以用户为准,没到门槛的不替换,显示「孕N周开放」、点了由 jumpApp 弹原提示。
· 能放哪些工具:App 表 category=孕期工具 的已上架应用(APP_BY_ID)。应用列表回来前,用 HT_META_KEY 里上次缓存的名字 / logo / url 先画,
回来后下架的自动不出现(不在前端写名单)。
· 7 个老格子(data-mini)和 6 张数据卡的 DOM 一直都在,只挪位置 / 显隐 —— 卡片接口回填、此刻 tapMini 点它们照旧能用。 */
const HT_KEY = 'mmbox.homeTools.v1', HT_META_KEY = 'mmbox.homeTools.meta.v1';
const HT_MAX = 11, HT_MIN = 1, HT_CARDS = 4;
const HT_DEFAULT = ['taidong', 'yunqitizhong', 'yun', 'yunqixuetang', 'chanjianrili', 'taierguzhong', 'gongsuopinlv'];
const HT_DATA = { taidong: 'kick', yunqitizhong: 'weight', yun: 'bp', yunqixuetang: 'glu', gongsuopinlv: 'curve', taierguzhong: 'fweight' };
let htAppsLoaded = false;
let htMeta = {};
try { htMeta = JSON.parse(localStorage.getItem(HT_META_KEY) || '{}') || {}; } catch (e) { htMeta = {}; }
function htApps() { try { return APP_BY_ID; } catch (e) { return null; } } /* APP_BY_ID 定义在下面,早于它调用时返回 null */
function htInfo(id) {
const A = htApps(), a = A && A[id], m = htMeta[id] || {};
const sw = SWAP_POOL.find(x => x.id === id);
return {
id: id,
name: (a && a.name) || m.n || (sw && sw.name) || '',
short: (sw && sw.name) || (a && a.name) || m.n || '',
logo: (a && (a.logo || a.icon)) || m.l || '',
url: (a && a.url) || m.u || '',
btn: (sw && sw.btn) || '去看看',
};
}
function htCacheMeta(apps) {
htAppsLoaded = true;
htMeta = {};
apps.forEach(a => { htMeta[a.identifier] = { n: a.name || '', l: a.logo || a.icon || '', u: a.url || '' }; });
try { localStorage.setItem(HT_META_KEY, JSON.stringify(htMeta)); } catch (e) {}
}
function htLoad() {
try {
const a = JSON.parse(localStorage.getItem(HT_KEY) || 'null');
if (Array.isArray(a)) { const r = a.filter((x, i) => typeof x === 'string' && x && a.indexOf(x) === i).slice(0, HT_MAX); if (r.length) return r; }
} catch (e) {}
return null;
}
function htStore(a) { try { if (a) localStorage.setItem(HT_KEY, JSON.stringify(a)); else localStorage.removeItem(HT_KEY); } catch (e) {} }
/* 默认顺序 + 孕周替补(替补顺序 / 不重复的规则同原 swapHomeCards) */
function htDefault() {
const A = htApps() || {}, used = new Set(HT_DEFAULT);
return HT_DEFAULT.map(id => {
if (!stageLocked(STAGE_GATE.find(x => x.id === id))) return id;
const sub = SWAP_POOL.find(x => !used.has(x.id) && A[x.id] && A[x.id].url) || SWAP_POOL.find(x => !used.has(x.id));
if (!sub) return id;
used.add(sub.id);
return sub.id;
});
}
/* 当前该显示的列表:用户的 / 默认的,去掉认不出来的(应用列表回来后以 App 表为准) */
function htKnown(id) {
const A = htApps();
if (htAppsLoaded && A) return !!(A[id] && A[id].url);
return !!($('#htGrid .tg[data-tool="' + id + '"]') || htMeta[id] || SWAP_POOL.some(x => x.id === id));
}
function htCurrent() { return (htLoad() || htDefault()).filter(htKnown); }
function htVtOn() { return !!hashParam('openid') && !state.postpartum; }
function htCardIds(list) { return htVtOn() ? list.filter(id => HT_DATA[id]).slice(0, HT_CARDS) : []; }
function htRel(u) { /* 同源相对路径(AGENTS §13):本站或 mp 业务域名的绝对地址 → /<slug>/… */
try { const x = new URL(u, location.href); if (x.host === location.host || x.host === 'mp.yizhezhe.com') return x.pathname + x.search + x.hash; } catch (e) {}
return u;
}
/* 不是 data-mini 的普通应用格(能不能吃、补水补剂、待产清单、宝宝相册……) */
function htMakeCell(id) {
const f = htInfo(id);
if (!f.short && !f.url) return null;
const b = document.createElement('button');
b.type = 'button';
b.className = 'tg tg-app ripple';
b.dataset.tool = id;
b.setAttribute('aria-label', f.name || f.short);
b.innerHTML = '<i class="tg-ic">' + swapArt(id) + '</i><span class="tg-n"></span><span class="tg-s"></span>';
b.querySelector('.tg-n').textContent = f.short;
b.querySelector('.tg-s').textContent = f.btn;
b.addEventListener('click', () => {
const g = htInfo(id);
if (g.url) { jumpApp(htRel(g.url), id); return; }
toast('「' + (g.short || '这个工具') + '」即将上线');
});
return b;
}
function toolLogo(id) { return htInfo(id).logo; }
/* 首页宫格 / 数据卡图标 = 各应用在 App 表里的正式 logo(2026-10-31 用户定);拿不到就保留现有图形 */
function applyToolLogos() {
try { MINI_APP_MAP; } catch (e) { return; } /* 早于 MINI_APP_MAP 定义被调用(替补首次计算)时先跳过,应用列表回来会再调 */
$$('.tg[data-mini]').forEach(b => {
const u = toolLogo(b.dataset.swap || MINI_APP_MAP[b.dataset.mini]);
const ic = b.querySelector('.tg-ic');
$$('#htGrid .tg[data-tool], #vitals .vt-it[data-tool]').forEach(b => {
const u = toolLogo(b.dataset.tool);
const ic = b.querySelector('.tg-ic, .vt-ic');
if (!u || !ic) return;
let im = ic.querySelector('img');
if (!im || ic.querySelector('svg')) { ic.innerHTML = '<img alt="" aria-hidden="true">'; im = ic.querySelector('img'); }
ic.classList.add('lg');
if (ic.classList.contains('tg-ic')) ic.classList.add('lg');
if (im.getAttribute('src') !== u) im.src = u;
});
}
function swapHomeCards() {
const used = new Set();
let restored = false;
SWAP_SLOTS.forEach(([slot, id]) => {
const el = $('.tg[data-mini="' + slot + '"]');
if (!el) return;
const g = STAGE_GATE.find(x => x.id === id);
if (!stageLocked(g)) {
if (el.dataset.swap) { el.innerHTML = el._orig; delete el.dataset.swap; el.classList.remove('is-swap'); el.removeAttribute('aria-label'); restored = true; }
return;
}
const sub = SWAP_POOL.find(x => !used.has(x.id) && APP_BY_ID[x.id] && APP_BY_ID[x.id].url) ||
SWAP_POOL.find(x => !used.has(x.id));
if (!sub) return;
used.add(sub.id);
if (el.dataset.swap === sub.id) return;
if (!el.dataset.swap) el._orig = el.innerHTML;
el.dataset.swap = sub.id;
el.classList.add('is-swap');
el.classList.remove('is-warn');
el.setAttribute('aria-label', sub.name + ',' + sub.sub);
/* 2026-10-31 宫格改版:替补也是「图标 + 名字 + 胶囊」,底色沿用坑位的颜色 */
el.innerHTML = '<i class="tg-ic">' + swapArt(sub.id) + '</i><span class="tg-n">' + sub.name + '</span><span class="tg-s">' + sub.btn + '</span>';
function htLockMark(el, g) {
const on = stageLocked(g);
el.classList.toggle('is-locked', on);
if (on) el.dataset.lock = '孕' + g.wk + '周开放'; else delete el.dataset.lock;
if (el.classList.contains('vt-it')) {
const lk = el.querySelector('.vt-lk');
if (lk) lk.innerHTML = on ? '<b>孕 ' + g.wk + ' 周开放</b>' + (function () { const left = g.wk * 7 - knownGA(); return left >= 7 ? '还有 ' + Math.ceil(left / 7) + ' 周' : '还有 ' + left + ' 天'; })() : '';
}
return on;
}
function renderHomeTools() {
const grid = $('#htGrid'), cards = $('#vitals');
if (!grid || !cards) return;
const list = htCurrent(), cardIds = htCardIds(list);
const allBtn = grid.querySelector('.tg.all');
const want = new Set();
cardIds.forEach(id => { const it = cards.querySelector('.vt-it[data-tool="' + id + '"]'); if (it) { want.add(it); cards.appendChild(it); } });
$$('.vt-it[data-tool]', cards).forEach(it => it.classList.toggle('hide', !want.has(it)));
const vis = $$('.vt-it[data-tool]', cards).filter(it => want.has(it));
vis.forEach((it, i) => it.classList.toggle('span2', vis.length % 2 === 1 && i === vis.length - 1));
cards.classList.toggle('hide', !vis.length);
const shown = new Set();
list.forEach(id => {
if (cardIds.indexOf(id) >= 0) return;
const t = grid.querySelector('.tg[data-tool="' + id + '"]') || htMakeCell(id);
if (!t) return;
shown.add(t);
grid.insertBefore(t, allBtn);
});
if (restored && lastCards) applyRemoteCards(lastCards);
grid.appendChild(allBtn);
$$('.tg[data-tool]', grid).forEach(t => t.classList.toggle('hide', !shown.has(t)));
/* 孕周门槛角标:只有用户自己放上来的才会锁着出现(默认列表里锁着的已经换成替补) */
let anyLock = false;
$$('.tg[data-tool], .vt-it[data-tool]', grid.parentNode).forEach(el => {
const on = htLockMark(el, STAGE_GATE.find(x => x.id === el.dataset.tool));
if (on && !el.classList.contains('hide') && el.classList.contains('tg')) anyLock = true;
});
grid.classList.toggle('has-locked', anyLock);
applyToolLogos();
}
/* 原「首页工具卡按孕周换替补」入口(markStageLocks 调):现在替补并进 htDefault,这里只重排 */
function swapHomeCards() { renderHomeTools(); }
/* 跳转到其它 H5 应用。identifier 可选(来自 App 表),用于 last_app 上报的服务端在架校验;
缺省时服务端按 URL 前缀反查,效果一致。 */
@@ -516,6 +616,7 @@
.filter(a => a.url && a.category === '孕期工具')
.sort((x, y) => (y.seq || 0) - (x.seq || 0) || (y.no || 0) - (x.no || 0));
apps.forEach(a => { APP_BY_ID[a.identifier] = a; }); /* 供首页工具卡按 identifier 取 URL */
htCacheMeta(apps); /* 首页自选工具:记下名字 / logo / url,下次应用列表回来前先用(renderAppGrid → markStageLocks 会重排首页) */
applyToolLogos();
renderAppGrid(apps);
})
@@ -816,6 +917,158 @@
toast('「' + (sw ? (SWAP_POOL.find(x => x.id === sw) || {}).name : map[b.dataset.mini]) + '」即将上线');
}));
renderHomeTools(); /* 首屏就按用户自选 / 默认顺序排好(应用列表、孕周、卡片数据回来后会再排) */
/* ================= 编辑首页工具(#htSheet,2026-11-01) =================
· 上半「首页显示的工具」:长按整行 300ms 或按住右侧把手拖动排序;↑↓ 兜底;「−」移除(至少留 HT_MIN 个)。
· 下半「更多孕期工具」:APP_BY_ID 里没放上首页的孕期工具,点「+」加到末尾(最多 HT_MAX 个)。
· 关弹层(完成 / 叉 / 遮罩)即保存,首页立即重排;「恢复默认」= 删 HT_KEY,回到默认顺序 + 孕周替补。
· 拖动用 pointer 事件 + 列表上非被动 touchmove 拦滚动(长按触发后第一下 touchmove 就拦,浏览器来不及接管成滚动)。 */
(function htEditor() {
const sh = $('#htSheet'), scr = $('#htScrim'), list = $('#htsList'), more = $('#htsMore'), box = $('#htsScroll');
const openBtn = $('#htEdit');
if (!sh || !list || !openBtn) return;
let draft = [], dirty = false, resetAsked = false, hd = null;
const ICO = {
rm: '<svg viewBox="0 0 12 12"><path d="M2.5 6h7" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
up: '<svg viewBox="0 0 16 16"><path d="M4 10l4-4 4 4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
dn: '<svg viewBox="0 0 16 16"><path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
hd: '<svg viewBox="0 0 20 20"><path d="M4 6.5h12M4 10h12M4 13.5h12" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>',
};
const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c]);
const icoHtml = f => f.logo ? '<img class="hts-ic" src="' + esc(f.logo) + '" alt="" aria-hidden="true">' : '<span class="hts-ic ph" aria-hidden="true">' + esc((f.short || f.name || '工').slice(0, 1)) + '</span>';
function pool() { /* 能加的全部孕期工具:App 表顺序;列表没回来时用缓存 + 7 个老格子 */
const A = htApps();
const ids = (A && Object.keys(A).length) ? Object.keys(A).filter(id => A[id].url) : Object.keys(htMeta);
HT_DEFAULT.forEach(id => { if (ids.indexOf(id) < 0 && !htAppsLoaded) ids.push(id); });
return ids;
}
function render() {
const cards = htCardIds(draft);
list.innerHTML = draft.map((id, i) => {
const f = htInfo(id), g = STAGE_GATE.find(x => x.id === id), lk = stageLocked(g);
const nm = f.name || f.short || id;
return '<li class="hts-row" data-id="' + esc(id) + '">' +
'<button type="button" class="hts-rm" data-act="rm" aria-label="从首页移除' + esc(nm) + '">' + ICO.rm + '</button>' +
icoHtml(f) +
'<span class="hts-n"><i>' + esc(nm) + '</i>' + (cards.indexOf(id) >= 0 ? '<em class="hts-tag">显示数据</em>' : '') + (lk ? '<em class="hts-tag lk">孕' + g.wk + '周开放</em>' : '') + '</span>' +
'<button type="button" class="hts-mv" data-act="up" aria-label="上移"' + (i === 0 ? ' disabled' : '') + '>' + ICO.up + '</button>' +
'<button type="button" class="hts-mv" data-act="dn" aria-label="下移"' + (i === draft.length - 1 ? ' disabled' : '') + '>' + ICO.dn + '</button>' +
'<span class="hts-hd" aria-hidden="true">' + ICO.hd + '</span></li>';
}).join('');
const rest = pool().filter(id => draft.indexOf(id) < 0);
const full = draft.length >= HT_MAX;
more.innerHTML = rest.length ? rest.map(id => {
const f = htInfo(id);
return '<button type="button" class="hts-add' + (full ? ' is-full' : '') + '" data-id="' + esc(id) + '" aria-label="加到首页:' + esc(f.name || f.short) + '">' + icoHtml(f) + '<span>' + esc(f.short || f.name) + '</span><b aria-hidden="true">+</b></button>';
}).join('') : '<div class="hts-empty">孕期工具都已经放在首页啦</div>';
$('#htsCnt').textContent = draft.length + ' / ' + HT_MAX;
$('#htsSub').textContent = htVtOn()
? '长按拖动排序,前 ' + HT_CARDS + ' 个记录类工具直接显示数据'
: '长按拖动排序,点「−」移出首页';
}
function change(next) { draft = next; dirty = true; resetAsked = false; render(); }
function open() {
draft = htCurrent().slice(0, HT_MAX);
dirty = false; resetAsked = false;
render();
box.scrollTop = 0;
scr.classList.add('show'); sh.classList.add('show'); sh.setAttribute('aria-hidden', 'false');
haptic();
}
function close() {
if (!sh.classList.contains('show')) return;
scr.classList.remove('show'); sh.classList.remove('show'); sh.setAttribute('aria-hidden', 'true');
if (resetAsked) { htStore(null); renderHomeTools(); toast('已恢复默认工具'); return; }
if (!dirty) return;
htStore(draft.slice());
renderHomeTools();
toast('首页工具已更新');
}
openBtn.addEventListener('click', e => { e.stopPropagation(); open(); });
$('#htsDone').addEventListener('click', close);
$('#htsX').addEventListener('click', close);
$('#htsGrip').addEventListener('click', close);
scr.addEventListener('click', close);
$('#htsReset').addEventListener('click', () => {
/* 只换草稿;真正删 HT_KEY 在 close 里 */
draft = htDefault().filter(htKnown);
dirty = false; resetAsked = true;
render();
toast('已换回默认顺序,点完成生效');
});
list.addEventListener('click', e => {
const btn = e.target.closest('button[data-act]'); if (!btn) return;
const id = btn.closest('.hts-row').dataset.id, i = draft.indexOf(id), d = draft.slice();
if (btn.dataset.act === 'rm') {
if (d.length <= HT_MIN) { toast('首页至少留 ' + HT_MIN + ' 个工具'); return; }
d.splice(i, 1); change(d); haptic(); return;
}
const j = btn.dataset.act === 'up' ? i - 1 : i + 1;
if (j < 0 || j >= d.length) return;
d[i] = d[j]; d[j] = id; change(d); haptic();
});
more.addEventListener('click', e => {
const b = e.target.closest('.hts-add'); if (!b) return;
if (draft.length >= HT_MAX) { toast('首页最多放 ' + HT_MAX + ' 个工具,先移掉一个吧'); return; }
change(draft.concat(b.dataset.id)); haptic();
});
/* —— 拖动排序 —— */
const GAP = 6;
function dStart() {
if (!hd) return;
hd.on = true; hd.st0 = box.scrollTop;
hd.row.classList.add('is-drag'); list.classList.add('is-dragging');
try { hd.row.setPointerCapture(hd.pid); } catch (e) {}
haptic();
}
function dEnd() {
if (!hd) return;
clearTimeout(hd.timer);
const was = hd.on, row = hd.row;
hd = null;
if (!was) return;
row.style.transform = '';
row.classList.remove('is-drag'); list.classList.remove('is-dragging');
const next = $$('.hts-row', list).map(r => r.dataset.id);
if (next.join() !== draft.join()) change(next); else render();
}
list.addEventListener('pointerdown', e => {
const row = e.target.closest('.hts-row');
if (!row || e.target.closest('button') || hd) return;
if (e.pointerType === 'mouse' && e.button !== 0) return;
hd = { row: row, pid: e.pointerId, x0: e.clientX, y0: e.clientY, on: false, timer: 0 };
if (e.target.closest('.hts-hd')) { e.preventDefault(); dStart(); } else hd.timer = setTimeout(dStart, 300);
});
list.addEventListener('pointermove', e => {
if (!hd || e.pointerId !== hd.pid) return;
if (!hd.on) { /* 还没到长按就动了 = 在滚列表,放弃 */
if (Math.abs(e.clientY - hd.y0) > 8 || Math.abs(e.clientX - hd.x0) > 8) { clearTimeout(hd.timer); hd = null; }
return;
}
e.preventDefault();
/* 贴近滚动区上下沿时顺带滚一下 */
const br = box.getBoundingClientRect();
if (e.clientY < br.top + 36) box.scrollTop -= 8; else if (e.clientY > br.bottom - 36) box.scrollTop += 8;
/* ⚠️ 只挪「旁边那行」,不挪正在拖的这行:被拖的节点一离开 DOM 就会丢 pointer capture,拖到一半断掉 */
const rows = $$('.hts-row', list), i = rows.indexOf(hd.row), step = hd.row.offsetHeight + GAP;
let dy = e.clientY - hd.y0 + (box.scrollTop - hd.st0);
if (dy > step / 2 && i < rows.length - 1) { list.insertBefore(rows[i + 1], hd.row); hd.y0 += step; dy -= step; haptic(); }
else if (dy < -step / 2 && i > 0) { list.insertBefore(rows[i - 1], hd.row.nextSibling); hd.y0 -= step; dy += step; haptic(); }
hd.row.style.transform = 'translateY(' + dy + 'px) scale(1.02)';
});
list.addEventListener('pointerup', dEnd);
list.addEventListener('pointercancel', dEnd);
list.addEventListener('lostpointercapture', () => { if (hd && hd.on) dEnd(); });
list.addEventListener('contextmenu', e => e.preventDefault());
/* 长按触发后拦掉滚动;弹层里滚动区以外的地方也不让带着整页动(禁止下拉回弹规则) */
sh.addEventListener('touchmove', e => {
if (hd && hd.on) { if (e.cancelable) e.preventDefault(); return; }
if (!e.target.closest('.hts-scroll') && e.cancelable) e.preventDefault();
}, { passive: false });
scr.addEventListener('touchmove', e => { if (e.cancelable) e.preventDefault(); }, { passive: false });
})();
/* 记一下弹层只保留「全部孕期工具」,不再提供输入框 */
/* ================= 滑入详情页(栈式,可多层返回) ================= */
@@ -1854,7 +2107,8 @@
妈妈是在替谁做,标题里就该有谁。
⚠️ 气泡上原来那枚 .ab-badge「AI」角标,2026-10-02 用户明确要求去掉(首页便签不再标 AI)。
详情页 #detailAI 的说明仍在;以后要恢复机器生成提示,回 index.html 的 .fn-top 里加回来。 */
$('#dockTitle').textContent = babyWord('的孕育工具');
/* 2026-11-01 工具和数据合成一个模块,标题定为「我的孕期工具」(不再拼小名) */
$('#dockTitle').textContent = '我的孕期工具';
$('#abTag').textContent = babyWord('今天想说');
$('#tlTitle').textContent = babyWord('的今日脚印');
/* 2026-10-03 用户:婴儿房角标「往里看看 · 3D 婴儿房」→「往里看看 · 豆豆的婴儿房」;同日又改成「进去看看」,没填小名就是「宝宝的婴儿房」 */
@@ -5086,6 +5340,7 @@
}
const qaHref = h => h + location.search + location.hash;
const MS_FIRE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12.6 2.5c.4 3-1.6 4.6-3 6.2C8 10.4 7 12 7 14.3A5 5 0 0012 19.5a5 5 0 005-5.2c0-2-1-3.6-1.9-4.6-.2 1.3-.9 2.2-1.9 2.6.6-3.4-.2-7-.6-9.8z" fill="currentColor"/><path d="M12 19.5a2.6 2.6 0 01-2.6-2.6c0-1.6 1.3-2.5 2-3.6.3 1 .9 1.6 1.6 1.9.9.4 1.6 1.2 1.6 2.1A2.6 2.6 0 0112 19.5z" fill="#FFD36B"/></svg>';
const MS_FIRE_W = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12.6 2.5c.4 3-1.6 4.6-3 6.2C8 10.4 7 12 7 14.3A5 5 0 0012 19.5a5 5 0 005-5.2c0-2-1-3.6-1.9-4.6-.2 1.3-.9 2.2-1.9 2.6.6-3.4-.2-7-.6-9.8z" fill="#FFE07A"/></svg>';
function msHeat() {
const p = window.__mbPulse, tot = (p && p.total && +p.total.value) || 1510000;
$$('#msList .ms-h').forEach(h => {
@@ -5129,7 +5384,8 @@
/* 热度行:火苗 + 「N 万人看过」。人数 = 「此刻」同一个总人数(后台 pulseBase)× 每条固定比例,和首页其它人数同一口径 */
if (it.heat) { const h = document.createElement('span'); h.className = 'ms-h'; h.dataset.heat = it.heat; h.innerHTML = MS_FIRE + '<b></b>'; m.appendChild(h); }
el.appendChild(no); el.appendChild(m);
if (it.badge) { const g = document.createElement('span'); g.className = 'ms-bd' + (it.badge === '爆' ? ' bao' : it.badge === '新' ? ' new' : ''); g.textContent = it.badge; el.appendChild(g); }
/* 2026-11-01 爆 = 红橙渐变 + 小火苗 + 光泽;热 = 橙色实底;新 = 绿(样式在 index.html .ms-bd) */
if (it.badge) { const g = document.createElement('span'); g.className = 'ms-bd' + (it.badge === '爆' ? ' bao' : it.badge === '新' ? ' new' : ''); g.textContent = it.badge; if (it.badge === '爆') g.insertAdjacentHTML('afterbegin', MS_FIRE_W); el.appendChild(g); }
const go = document.createElement('i'); go.className = 'ms-go'; go.textContent = '›'; el.appendChild(go);
L.appendChild(el);
});
@@ -5283,7 +5539,7 @@
return n === 0 ? '今天' : n === 1 ? '昨天' : (b.getMonth() + 1) + '月' + b.getDate() + '日';
}
const VT_ID = { kick: 'vtK', weight: 'vtW', bp: 'vtP', glu: 'vtG', curve: 'vtC', fweight: 'vtE' };
const VT_EXTRA = { curve: 1, fweight: 1 };
const VT_TG = { bp: '量一量', glu: '记一笔' }; /* 小图标格上的默认胶囊(同 index.html) */
/* 2026-10-31 用户:去掉「示例」两个字,没记过的格直接按正常数据的样子显示(值 / 胶囊 / 胶囊样式 / 时间) */
const VT_DEMO = { kick: ['12', '今天', '', '最近 14:20'], weight: ['58.2', '比孕前 +4.6', '', '今天记录'], bp: ['115/75', '正常', 'ok', '昨天记录'], glu: ['5.1', '达标', 'ok', '今天 空腹'] }; /* 这两格有记录才出现 */
function vtSet(key, val, pill, cls, when) {
@@ -5295,23 +5551,16 @@
const dm = !val && VT_DEMO[key];
it.classList.toggle('demo', !!dm);
$('#' + id).textContent = val || (dm ? dm[0] : '--');
const s = $('#' + id + 's'); s.textContent = val ? (pill || '') : (dm ? dm[1] : (key === 'kick' ? '去数一数 ›' : '去记一笔 ›')); s.className = 'vt-s' + (val && cls ? ' ' + cls : dm && dm[2] ? ' ' + dm[2] : '');
const s = $('#' + id + 's'); s.textContent = val ? (pill || '') : (dm ? dm[1] : (key === 'kick' ? '去数一数 ›' : key === 'fweight' ? '去测算 ›' : '去记一笔 ›')); s.className = 'vt-s' + (val && cls ? ' ' + cls : dm && dm[2] ? ' ' + dm[2] : '');
$('#' + id + 'd').textContent = val ? (when || '') : (dm ? dm[3] : '');
/* 2026-11-01 血压 / 血糖没排进数据卡、落在小图标宫格里时,胶囊也显示最近一次(体重等由卡片接口写) */
const tgS = VT_TG[key] && $('.tg[data-mini="' + key + '"] .tg-s');
if (tgS) tgS.textContent = val || VT_TG[key];
vtLayout();
}
/* 记过的格排前面;数宫缩 / 胎儿估重没记录就不出现;孕周没到的数胎动没记录也先不出现;单数时最后一格占满一行 */
function vtLayout() {
const its = $$('.vt-it[data-vt]');
const kg = STAGE_GATE.find(x => x.id === 'taidong');
its.forEach(it => {
const k = it.dataset.vt, has = !!it.dataset.has;
it.classList.toggle('hide', !has && (VT_EXTRA[k] || (k === 'kick' && stageLocked(kg))));
it.style.order = has ? 0 : 1;
it.classList.remove('span2');
});
const vis = its.filter(it => !it.classList.contains('hide')).sort((a, b) => (+a.style.order - +b.style.order) || (its.indexOf(a) - its.indexOf(b)));
if (vis.length % 2) vis[vis.length - 1].classList.add('span2');
}
/* 2026-11-01 起数据卡出哪几张、什么顺序由首页工具列表决定(renderHomeTools):不再「记过的排前面 / 没记录就藏」,
用户放在哪就在哪;单数时最后一格占满一行也在那边算。 */
function vtLayout() { renderHomeTools(); }
/* 胎动 / 数宫缩 / 胎儿估重 来自卡片接口(tool-cards),applyRemoteCards 收到就喂进来 */
function vtCards(r) {
const by = {}; ((r && r.cards) || []).forEach(c => { if (c && c.slot) by[c.slot] = c; });
@@ -5323,11 +5572,10 @@
if (f) vtSet('fweight', !f.empty && (f.value || f.text) ? (f.value ? f.value + (f.unit || '') : f.text) : '', '', '', f.sub || '');
}
function loadVitals() {
const box = $('#vitals'); if (!box) return;
if (!hashParam('openid') || state.postpartum) { box.classList.add('hide'); return; }
box.classList.remove('hide');
if (!$('#vitals')) return;
renderHomeTools(); /* 数据卡显隐跟身份 / 产后走(htVtOn),这里按最新状态排一次 */
if (!htVtOn()) return;
_vtAt = Date.now();
vtLayout();
vtGet('yunqi-tizhong', '/state').then(j => {
const pw = vtVal(j && j.items, 'pw_data_v1');
const ws = ((pw && pw.weights) || []).filter(w => w && !w.demo && +w.weight > 0).sort((a, b) => String(a.date).localeCompare(String(b.date)) || (a.updatedAt || 0) - (b.updatedAt || 0));