今日孕期小知识 emoji 换成手绘图标库(库没加载退回 emoji)v26101205

Co-Authored-By: AI 助手
This commit is contained in:
karlcarlo
2026-10-12 09:36:45 +00:00
parent 62b36aab8d
commit 6808975750
3 changed files with 33 additions and 5 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26101204';
var VER = '26101205';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -4972,6 +4972,24 @@
}
return tipsLoading;
}
/* 手绘图标:el 里放一张 <img>(装饰,aria-hidden);没有库 / 没有这个 id / 图片加载失败 → 写回 emoji */
function setHandIco(el, id, emoji) {
if (!el) return;
if (!id || !window.handIcons || !handIcons.has(id)) { el.textContent = emoji; return; }
const cur = el.querySelector('img');
if (cur && cur.dataset.hi === id) return;
const im = handIcons.img(id);
im.removeAttribute('width'); im.removeAttribute('height'); // 尺寸跟着各处的 font-size(css 里 1em 起算)
im.dataset.hi = id;
im.onerror = function () { el.textContent = emoji; };
el.textContent = '';
el.appendChild(im);
}
/* 小知识四个固定入口(首页那排 + 详情页四张卡):妈妈 / 吃 / 留心固定图标;「宝宝这周」跟孕周走,在 renderTips 里写 */
$$('[data-pt="mom"] > i, [data-pt="mom"] > .pt-ico').forEach(el => setHandIco(el, 'mom', '🤰'));
$$('[data-pt="eat"] > i, [data-pt="eat"] > .pt-ico').forEach(el => setHandIco(el, 'eat', '🥗'));
$$('[data-pt="care"] > i, [data-pt="care"] > .pt-ico').forEach(el => setHandIco(el, 'care', '📋'));
function renderTips() {
const sec = $('#pregTips');
if (!sec) return;
@@ -4984,14 +5002,17 @@
const size = babySize(w);
$('#ptWk').textContent = '孕 ' + state.week + ' 周';
$('#ptWhen').textContent = '本周第 ' + (today + 1) + ' 天';
$('#ptFloat').textContent = size.emoji;
$('#ptBabyIco').textContent = size.emoji;
/* 2026-10-12 用户:小知识里的 emoji 换成兜爸手绘图标库(/_bridge/hand-icons.js,小程序后台 375797cf 维护);
图标按孕周从 handIcons.week() 取,SIZE 表只管文字;库没加载 / 图片挂了 → 退回原来的 emoji,位置不空 */
const hw = window.handIcons && handIcons.week(w);
setHandIco($('#ptFloat'), hw && hw.id, size.emoji);
setHandIco($('#ptBabyIco'), hw && hw.id, size.emoji);
/* 四张卡全文只在详情页 #detailTips;首页那排入口只有图标 + 标题 */
$('#ptBaby').textContent = '像' + size.name + '那么大。' + (wk.baby || '');
$('#ptMom').textContent = wk.mom || '';
$('#ptEat').textContent = wk.eat || '';
$('#ptCare').textContent = wk.care || '';
$('#ptChipBaby').textContent = size.emoji;
setHandIco($('#ptChipBaby'), hw && hw.id, size.emoji);
$('#ptDtTitle').textContent = '孕 ' + state.week + ' 周 · 这一周';
/* 一周 7 个圆点:以前可回看,今天实心,以后锁着 */
const box = $('#ptDays');