diff --git a/static/js/pages/market.js b/static/js/pages/market.js index b87be2a..100bfea 100644 --- a/static/js/pages/market.js +++ b/static/js/pages/market.js @@ -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 = '
加载失败
'; } }, @@ -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');