fix: match installed by both id and name

This commit is contained in:
2026-07-27 08:51:31 +08:00
parent 2a51026587
commit ae4bffd79f
+9 -4
View File
@@ -36,10 +36,14 @@ const PageMarket = {
const items = data.items || [];
let localIds = [];
try { const lr = await fetch('/api/dashboards?category=all'); const ld = await lr.json(); if (Array.isArray(ld)) localIds = ld.map(d => d.id); } catch(e) {}
let localNames = [];
try { const lr = await fetch('/api/dashboards?category=all'); const ld = await lr.json(); if (Array.isArray(ld)) { localIds = ld.map(d => d.id); localNames = ld.map(d => d.name); } } catch(e) {}
if (!items.length) { grid.innerHTML = this._emptyHtml(isScene ? '暂无场景' : '暂无仪表盘'); return; }
grid.innerHTML = items.map(d => this._cardHtml(d, isScene, localIds.includes(d.name || d.id))).join('');
grid.innerHTML = items.map(d => {
const installed = localIds.includes(d.name || d.id) || localNames.includes(d.name);
return this._cardHtml(d, isScene, installed);
}).join('');
} catch (e) { grid.innerHTML = '<div style="text-align:center;padding:40px;color:var(--danger);">加载失败</div>'; }
},
@@ -111,11 +115,12 @@ const PageMarket = {
if (e.target.closest('.btn-m-uninstall')) {
const ubtn = e.target.closest('.btn-m-uninstall');
if (!confirm('确定卸载 "' + (ubtn.dataset.name||'') + '"')) return;
const uname = ubtn.dataset.name||'';
if (!confirm('确定卸载 "' + uname + '"')) return;
try {
const r = await fetch('/api/dashboards?category=all');
const list = (await r.json()) || [];
const dash = list.find(d => d.id === ubtn.dataset.name || d.name === ubtn.dataset.name);
const dash = list.find(d => d.id === uname || d.name === uname);
if (dash) {
await fetch('/api/dashboards/' + dash.id, { method: 'DELETE' });
Toast.show('已卸载', 'success');