纠正: 应用列表渲染到「记一下」弹层的全部孕期工具宫格(#appsGrid), 首页 bento 恢复原样 (v26090722)
This commit is contained in:
39
js/app.js
39
js/app.js
@@ -170,10 +170,10 @@
|
||||
location.href = u;
|
||||
}
|
||||
|
||||
/* ================= 首页工具区 = 已上架应用宫格 =================
|
||||
/* ================= 「记一下」弹层 · 全部孕期工具 = 已上架应用列表 =================
|
||||
数据:box_app /api/mp/apps(应用管理统一维护图标/名称/链接)。
|
||||
范围:isPublished=1 且有 url;排除授权示例(wx-h5-demo,开发者用的)。
|
||||
交互:默认前 8 个,「所有工具 ›/展开全部工具」展开收起;点击带身份跳转。 */
|
||||
交互:全量铺进弹层宫格(沿用 .apps-grid/.app 样式),点击带身份跳转对应 H5。 */
|
||||
function appTileColor(name) {
|
||||
const PALETTE = ['#F2917A', '#E8A2B8', '#8FB4E3', '#7FC8A9', '#E3B771', '#A99BD1', '#73BFB2', '#DE8F6E'];
|
||||
let h = 0;
|
||||
@@ -192,36 +192,25 @@
|
||||
location.href = url;
|
||||
}
|
||||
function renderAppGrid(apps) {
|
||||
const grid = $('#appGrid'), moreBtn = $('#appMore'), dockAll = $('#dockAll');
|
||||
const grid = $('#appsGrid');
|
||||
if (!grid) return;
|
||||
grid.innerHTML = apps.map(a => {
|
||||
const ico = a.logo || a.icon || '';
|
||||
const name = a.name || a.identifier || '应用';
|
||||
/* 有 logo:白底让图盖满;无 logo:用 colorTheme/调色板 + 首字彩色块。
|
||||
⚠️ colorTheme 目前全是 'blue' 这种颜色名 —— 有图时别拿它当底色,
|
||||
不然 37 个磁贴清一色蓝块,图加载前像坏了。 */
|
||||
/* 有 logo:白底圆角让图盖满;无 logo:colorTheme/调色板 + 首字彩色块。
|
||||
⚠️ colorTheme 目前全是 'blue' 颜色名 —— 有图时别拿它当底色,否则清一色蓝。 */
|
||||
const bg = ico ? 'background:#fff' : 'background:' + (a.colorTheme || appTileColor(name));
|
||||
const img = ico ? '<img src="' + ico + '" alt="" loading="lazy">' : (name.slice(0, 1));
|
||||
return '<button class="app-tile ripple" data-url="' + encodeURIComponent(a.url) + '">' +
|
||||
'<span class="app-ico" style="' + bg + '">' + img + '</span>' +
|
||||
'<span class="app-tile-name">' + name + '</span></button>';
|
||||
const img = ico ? '<img class="a-ico" src="' + ico + '" alt="" loading="lazy">' : '<span class="a-ico a-ico-letter" style="background:' + bg + '">' + name.slice(0, 1) + '</span>';
|
||||
return '<button class="app ripple" data-url="' + encodeURIComponent(a.url) + '">' + img + name + '</button>';
|
||||
}).join('');
|
||||
/* 磁贴点击(事件委托,innerHTML 重建后不用重绑) */
|
||||
grid.onclick = function (e) {
|
||||
const t = e.target.closest('.app-tile');
|
||||
const t = e.target.closest('.app');
|
||||
if (t && t.dataset.url) jumpApp(decodeURIComponent(t.dataset.url));
|
||||
};
|
||||
if (apps.length > 8) {
|
||||
moreBtn.style.display = 'block';
|
||||
dockAll.style.display = '';
|
||||
}
|
||||
}
|
||||
function toggleAppGrid() {
|
||||
const grid = $('#appGrid'), moreBtn = $('#appMore'), dockAll = $('#dockAll');
|
||||
const ex = grid.classList.toggle('expanded');
|
||||
moreBtn.style.display = ex ? 'none' : 'block';
|
||||
dockAll.textContent = ex ? '收起 ›' : '所有工具 ›';
|
||||
haptic();
|
||||
/* 角标「共 N 个」同步真实数量 */
|
||||
const cnt = $('.apps-head.for-all .sec-more');
|
||||
if (cnt) cnt.textContent = '共 ' + apps.length + ' 个 ›';
|
||||
}
|
||||
function loadPublishedApps() {
|
||||
fetch('/api/mp/apps?isPublished=1&pageSize=200')
|
||||
@@ -233,10 +222,8 @@
|
||||
.sort((x, y) => (x.seq || 0) - (y.seq || 0) || (x.no || 0) - (y.no || 0));
|
||||
renderAppGrid(apps);
|
||||
})
|
||||
.catch(function () { /* 拉不到就保持空宫格,不影响其余页面 */ });
|
||||
.catch(function () { /* 拉不到就保留弹层原有占位,不影响其余页面 */ });
|
||||
}
|
||||
$('#appMore').addEventListener('click', toggleAppGrid);
|
||||
$('#dockAll').addEventListener('click', toggleAppGrid);
|
||||
loadPublishedApps();
|
||||
|
||||
function go(name) {
|
||||
@@ -1858,7 +1845,7 @@
|
||||
n.textContent = n.dataset.wk === 'cn' ? '孕 ' + state.week + ' 周' : state.week;
|
||||
});
|
||||
const next = CHECKUPS.find(w => w * 7 > gaNow);
|
||||
/* #calNext 原在首页孕检日历卡上 —— 那批演示卡已换成应用宫格,元素没了,别再写 */
|
||||
$('#calNext').textContent = mdTxt(next ? gaToDate(next * 7) : state.due);
|
||||
const t = new Date();
|
||||
$('#noteWhen').textContent = mdTxt(t) + ' ' + WEEKDAY[t.getDay()] + ' · ' + gaTxt(gaNow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user