其他妈妈也在搜按孕周分 6 段:首条固定生娃计算器 + 本段 4 条 + 通用 1 条;新增 50 个分段专题页(问题库共 100);全部问题页加「孕 N 周」筛选;v26110201

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deploy
2026-11-02 05:28:58 +00:00
parent be74d7cf35
commit 7e02da209b
106 changed files with 14995 additions and 67 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26110127';
var VER = '26110201';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -5484,6 +5484,26 @@
return qaLoading;
}
const qaHref = h => h + location.search + location.hash;
/* 2026-11-02 用户定:「其他妈妈也在搜」按孕周分 6 段(按产检节点)—— 首页 6 条 = 第 1 条固定生娃计算器 + 当前孕周段 4 条(段内按热度)
+ 通用 1 条(每天按北京日期轮换)。问题库条目带 st:[段…] 的是分段题,不带的是通用题;测一测里已有的测试不进列表。
段:①4~8 周 刚怀上 ②9~13 建档+NT ③14~20 孕中前段 ④21~28 大排畸+糖耐 ⑤29~36 孕晚前段 ⑥37+ 足月待产。没孕周(未设/产后)→ 按库里原顺序。 */
const QA_FIXED = 'topic/huafei/', QA_SKIP = ['topic/ceshi/', 'topic/duiyou/'];
const qaBand = w => (!w ? 0 : w <= 8 ? 1 : w <= 13 ? 2 : w <= 20 ? 3 : w <= 28 ? 4 : w <= 36 ? 5 : 6);
function qaPick(bank, week, n) {
n = n || 6;
const b = qaBand(week), fixed = bank.filter(x => x.href === QA_FIXED);
const ok = x => x.href !== QA_FIXED && QA_SKIP.indexOf(x.href) < 0;
if (!b) return fixed.concat(bank.filter(ok)).slice(0, n);
const byHeat = (a, c) => (+c.heat || 0) - (+a.heat || 0);
const stage = bank.filter(x => ok(x) && x.st && x.st.indexOf(b) >= 0).sort(byHeat).slice(0, n - 2);
const gen = bank.filter(x => ok(x) && !x.st);
const day = Math.floor((Date.now() + 288e5) / 864e5);
const g = gen.length ? [gen[day % gen.length]] : [];
const out = fixed.concat(stage, g);
bank.filter(x => ok(x) && out.indexOf(x) < 0).forEach(x => { if (out.length < n) out.push(x); });
return out.slice(0, n);
}
window.__mbQaPick = qaPick; window.__mbQaBand = qaBand;
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() {
@@ -5505,7 +5525,7 @@
const bank = QA || [];
let items;
if (bank.length) {
items = bank.slice(0, 6).map((x, i) => ({ q: x.q, href: x.href ? qaHref(x.href) : '', qa: i, badge: x.badge, heat: x.heat }));
items = qaPick(bank, W).map(x => ({ q: x.q, href: x.href ? qaHref(x.href) : '', qa: bank.indexOf(x), badge: x.badge, heat: x.heat }));
} else {
const q = t => /[??吗呢]$/.test(t) ? t : t + (/怎么办|什么|多少|怎么|几/.test(t) ? '?' : '');
const d0 = wk.days[today];
@@ -5546,28 +5566,36 @@
const bank = QA || [];
if (!bank.length) { openTips(); return; }
$('#qaTitle').textContent = '其他妈妈也在搜';
$('#qaHeroT').textContent = '妈妈们最常问的 ' + bank.length + ' 个问题';
$('#qaHeroT').textContent = band ? '孕 ' + state.week + ' 周,妈妈们最常问的问题' : '妈妈们最常问的 ' + bank.length + ' 个问题';
$('#qaHeroD').textContent = '点开问题看答案';
$('#qaTopic').classList.add('hide');
/* 2026-11-02 按孕周排:生娃计算器 → 当前孕周段(按热度)→ 其余按库里顺序;分类条第 2 个是「孕 N 周」只看本段 */
const band = (state.postpartum || state.pregEmpty) ? 0 : qaBand(state.week);
const inBand = x => !!(band && x.st && x.st.indexOf(band) >= 0);
const order = bank.filter(x => x.href === QA_FIXED)
.concat(bank.filter(x => x.href !== QA_FIXED && inBand(x)).sort((a, c) => (+c.heat || 0) - (+a.heat || 0)))
.concat(bank.filter(x => x.href !== QA_FIXED && !inBand(x)));
const cats = [];
bank.forEach(x => { if (x.tag && cats.indexOf(x.tag) < 0) cats.push(x.tag); });
if (band) cats.unshift('__st');
const cb = $('#qaCats');
cb.textContent = '';
['全部'].concat(cats).forEach(c => {
const b = document.createElement('button');
b.type = 'button'; b.className = 'qa-cat'; b.dataset.cat = c;
b.textContent = c;
const sm = document.createElement('small'); sm.textContent = c === '全部' ? bank.length : bank.filter(x => x.tag === c).length;
b.textContent = c === '__st' ? '孕 ' + state.week + ' 周' : c;
const sm = document.createElement('small'); sm.textContent = c === '全部' ? bank.length : c === '__st' ? bank.filter(inBand).length : bank.filter(x => x.tag === c).length;
b.appendChild(sm);
b.addEventListener('click', () => qaFilter(c));
cb.appendChild(b);
});
const L = $('#qaList');
L.textContent = '';
bank.forEach((x, i) => {
order.forEach((x, i) => {
const it = document.createElement('div');
it.className = 'qa-it' + (i < 6 ? ' top' : '');
it.dataset.cat = x.tag || '';
if (inBand(x)) it.dataset.st = '1';
const h = document.createElement('button'); h.type = 'button'; h.className = 'qa-q';
const no = document.createElement('i'); no.className = 'qa-no'; no.textContent = i + 1;
const t = document.createElement('span'); t.className = 'qa-tx'; t.textContent = x.q;
@@ -5585,8 +5613,9 @@
openPanel('detailQA');
const body = $('#detailQA .detail-body');
body.scrollTop = 0;
if (focus != null && L.children[focus] && !bank[focus].href) {
const c = L.children[focus];
const fi = focus != null ? order.indexOf(bank[focus]) : -1;
if (fi >= 0 && L.children[fi] && !bank[focus].href) {
const c = L.children[fi];
c.classList.add('open');
setTimeout(() => {
body.scrollTo({ top: Math.max(0, c.getBoundingClientRect().top - body.getBoundingClientRect().top + body.scrollTop - 12), behavior: 'smooth' });
@@ -5596,10 +5625,10 @@
}
function qaFilter(c) {
$$('#qaCats .qa-cat').forEach(b => b.classList.toggle('on', b.dataset.cat === c));
$$('#qaList .qa-it').forEach(it => it.classList.toggle('hide', c !== '全部' && it.dataset.cat !== c));
$$('#qaList .qa-it').forEach(it => it.classList.toggle('hide', c === '__st' ? it.dataset.st !== '1' : c !== '全部' && it.dataset.cat !== c));
}
(function () {
const all = $('#msAll'); if (all) all.addEventListener('click', () => openQA());
const all = $('#msAll'); if (all) all.addEventListener('click', () => loadQA().then(() => openQA())); /* 11-02 合并版里原模块可能没渲染过,先确保问题库到手 */
const tp = $('#qaTips'); if (tp) tp.addEventListener('click', () => openTips());
})();
/* 首页四个入口 → 详情页,滚到对应那张卡并闪一下 */