feat: 概览改为纯仪表盘,全部应用独立视图

This commit is contained in:
jinghui committed 2026-10-26 18:13:47 +08:00
1 parent 6817e8c87f
commit d153dec29d
4 files changed
+40 -15

No files matched your search

+30 -14
View File
@@ -70,7 +70,7 @@ function toast(msg, err) {
}
/* ---------------- 路由 ---------------- */
const TITLES = { apps: '概览', containers: '运行的容器', stopped: '停止的容器', images: '本地镜像', registry: '镜像仓库', networks: '网络', settings: '告警设置' };
const TITLES = { apps: '概览', 'apps-all': '全部应用', containers: '运行的容器', stopped: '停止的容器', images: '本地镜像', registry: '镜像仓库', networks: '网络', settings: '告警设置' };
const SORTS = {
apps: [['severity', '异常优先'], ['cpu', 'CPU 占用'], ['mem', '内存占用'], ['containers', '容器数'], ['name', '名称']],
containers: [['cpu', 'CPU 占用'], ['mem', '内存占用'], ['net', '网络速率'], ['io', '磁盘 IO'], ['pids', '进程数'], ['name', '名称']],
@@ -79,12 +79,13 @@ const SORTS = {
function go(view) {
state.view = view;
state.currentApp = null;
$$('#nav a').forEach(a => a.classList.toggle('active', a.dataset.view === view));
const navView = view === 'apps-all' ? 'apps' : view;
$$('#nav a').forEach(a => a.classList.toggle('active', a.dataset.view === navView));
$('#pageTitle').textContent = TITLES[view] || view;
const isList = ['apps', 'containers', 'stopped'].includes(view);
const isList = ['apps', 'apps-all', 'containers', 'stopped'].includes(view);
$('#search').style.display = isList || view === 'images' ? '' : 'none';
$('#sortbox').style.display = isList ? '' : 'none';
const opts = SORTS[view] || SORTS.containers;
const opts = SORTS[view] || SORTS[navView] || SORTS.containers;
if (state.sort && !opts.some(o => o[0] === state.sort)) state.sort = opts[0][0];
$('#sort').innerHTML = opts.map(([v, t]) => `<option value="${v}">${t}</option>`).join('');
$('#sort').value = state.sort;
@@ -103,7 +104,7 @@ async function render(silent) {
if (state.appTab === 'containers' && state.currentApp) return openApp(state.currentApp);
return;
}
if (state.view === 'apps') return renderApps(silent);
if (state.view === 'apps' || state.view === 'apps-all') return renderApps(silent);
if (state.view === 'containers') return renderContainers(silent, 'running');
if (state.view === 'stopped') return renderContainers(silent, 'stopped');
if (state.view === 'images') return renderImages();
@@ -158,7 +159,7 @@ async function renderApps(silent) {
const pill = (a) => `<span class="pill ${a.severity === 2 ? 'bad' : a.severity === 1 ? 'warn' : 'ok'}">${a.statusText}</span>`;
const chips = [['all', '全部', s.total], ['issues', '有问题', s.critical + s.warning], ['stopped', '已停止', s.stopped], ['high', '高占用', '']];
const cards = data.items.map(a => `
const cardOf = (a) => `
<div class="app-card ${a.severity === 2 ? 'sev2' : a.severity === 1 ? 'sev1' : ''}" data-app="${esc(a.key)}">
<div class="app-head">
${avatar(a.name)}
@@ -184,7 +185,8 @@ async function renderApps(silent) {
<button class="mini danger" data-app-act="stop">停止</button>
<button class="mini primary" data-app-act="detail">详情</button>
</div>
</div>`).join('');
</div>`;
const cards = data.items.map(cardOf).join('');
const allApps = (full && full.items) || data.items || [];
const topCpu = [...allApps].sort((x, y) => (y.cpuPctOfMachine || 0) - (x.cpuPctOfMachine || 0)).slice(0, 5);
@@ -244,7 +246,22 @@ async function renderApps(silent) {
</div>
</div>`;
$('#view').innerHTML = `
const isAll = state.view === 'apps-all';
const attn = allApps.filter(a => a.severity > 0).slice(0, 6);
const totalApps = s.total;
if (isAll) {
$('#view').innerHTML = `
<div class="sec-head"><b>全部应用</b><span class="muted">共 ${totalApps} 个 · 点击卡片查看详情</span>
<button class="mini" id="backOverview" style="margin-left:auto">← 返回概览</button></div>
<div class="filters">
${chips.map(([k, t2, n]) => `<button class="chip ${state.filter === k ? 'on' : ''}" data-filter="${k}">${t2}${n !== '' ? ` <b>${n}</b>` : ''}</button>`).join('')}
<span class="muted" style="margin-left:auto">按状态异常优先、其次资源占用排序</span>
</div>
<div class="app-grid">${cards || '<div class="empty">没有匹配的应用</div>'}</div>`;
$('#backOverview').onclick = () => go('apps');
} else {
$('#view').innerHTML = `
<div class="stat-strip">
<div class="s-card"><div class="k">应用总数</div><div class="v">${s.total}</div><div class="s">${s.containers} 个容器</div></div>
<div class="s-card ${s.critical ? 'bad' : ''}"><div class="k">异常</div><div class="v">${s.critical}</div><div class="s">需要立即处理</div></div>
@@ -256,17 +273,16 @@ async function renderApps(silent) {
${topHtml}
${insHtml}
<div class="filters">
${chips.map(([k, t, n]) => `<button class="chip ${state.filter === k ? 'on' : ''}" data-filter="${k}">${t}${n !== '' ? ` <b>${n}</b>` : ''}</button>`).join('')}
<span class="muted" style="margin-left:auto">按状态异常优先、其次资源占用排序</span>
</div>
<div class="app-grid">${cards || '<div class="empty">没有匹配的应用</div>'}</div>
<div class="sec-head"><b>需要关注的应用</b><span class="muted">${attn.length ? `${attn.length} 个异常或需要注意` : '全部正常'}</span>
<button class="mini" id="openAllApps" style="margin-left:auto">查看全部应用 ${totalApps} 个 →</button></div>
${attn.length ? `<div class="app-grid">${attn.map(cardOf).join('')}</div>` : '<div class="empty ok-empty">所有应用运行正常,无需处理</div>'}
<div class="section-title"><h2>最近事件</h2><span class="muted">状态变化与重启记录</span></div>
<div class="timeline">
${ev.items.length ? ev.items.map(e => `<div class="ev ${e.level}"><span class="t">${timeStr(e.t)}</span><span class="dotmark"></span><div><b>${esc(e.title)}</b><div class="muted">${esc(e.detail || '')}</div></div></div>`).join('') : '<div class="muted">暂无事件</div>'}
</div>`;
$('#openAllApps').onclick = () => go('apps-all');
}
$$('#view .chip').forEach(b => b.onclick = () => { state.filter = b.dataset.filter; render(); });
$$('#view .top-row').forEach(r => r.onclick = () => openApp(r.dataset.top));