From c31379c8b0abd1b4c15905f6200e189066096f52 Mon Sep 17 00:00:00 2001 From: jinghui <181050043@qq.com> Date: Mon, 26 Oct 2026 18:32:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=90=E8=A1=8C=E7=9A=84=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E6=98=BE=E7=A4=BA=E5=B7=B2=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ public/app.js | 16 +++++++++++++++- public/style.css | 2 +- server/index.js | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29a6b6..d347486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 更新日志 +## 2026-10-26 → ✨ 运行的容器显示已运行时长 + +- ✨ 容器列表每行副标题改为「项目: xxx · 已运行 1天4小时」(原来是 Docker 的英文状态 `Up 29 hours`) +- ✨ 超过 1 分钟才显示时长,刚启动显示「刚刚启动」,停止的显示「已停止」 +- 🔧 时长用紧凑格式(`1天4小时` / `38分钟`)并加宽名称列,61 行里仅 1 行仍因项目名过长省略(有 title 提示) +- 🔧 镜像名是 sha256 摘要时只显示前 12 位,避免撑爆布局 + ## 2026-10-26 → ✨ 概览新增实时流量图表(今天/昨天/30 天/12 个月/查某天) - ✨ 按小时记账:每 3 秒采样把各容器网络计数器差量累加到当天小时桶,15 秒落盘 `data/traffic/YYYY-MM-DD.json`,重启不丢 diff --git a/public/app.js b/public/app.js index 838ad9f..7f3de72 100644 --- a/public/app.js +++ b/public/app.js @@ -47,6 +47,20 @@ const fmtDur = (ms) => { if (m > 0) return `${m} 分钟`; return '不到 1 分钟'; }; +const shortImg = (img) => { + const s = String(img || ''); + if (/^sha256:/.test(s)) return s.slice(7, 19); + const last = s.split('/').pop(); + return last.length > 22 ? last.slice(0, 22) + '…' : last; +}; +const fmtDurCompact = (ms) => { + if (ms === null || ms === undefined || !isFinite(ms) || ms < 0) return '—'; + const s = Math.floor(ms / 1000), d = Math.floor(s / 86400), h = Math.floor((s % 86400) / 3600), m = Math.floor((s % 3600) / 60); + if (d > 0) return `${d}天${h ? h + '小时' : ''}`; + if (h > 0) return `${h}小时${m ? m + '分' : ''}`; + if (m > 0) return `${m}分钟`; + return '1分钟内'; +}; const ago = (iso) => { if (!iso) return '-'; const d = (Date.now() - new Date(iso).getTime()) / 1000; @@ -508,7 +522,7 @@ async function renderContainers(silent, mode = 'running') { return `
${icon('box')}
${esc(c.name)}
-
${c.project ? '项目: ' + esc(c.project) : esc(c.image.split('/').pop())} · ${esc(c.status)}${c.restarts ? ` · 重启${c.restarts}` : ''}
+
${c.project ? '项目: ' + esc(c.project) : esc(shortImg(c.image))} · ${c.state === 'running' ? (c.runMs === null || c.runMs === undefined ? '运行中' : c.runMs < 60000 ? '刚刚启动' : '已运行 ' + fmtDurCompact(c.runMs)) : '已停止'}${c.restarts ? ` · 重启${c.restarts}` : ''}
CPU
${fmtPct(s.cpu)}
diff --git a/public/style.css b/public/style.css index b329d55..305e753 100644 --- a/public/style.css +++ b/public/style.css @@ -68,7 +68,7 @@ a{color:var(--blue);text-decoration:none;cursor:pointer} .dot{position:absolute;right:-2px;bottom:-2px;width:9px;height:9px;border-radius:50%;border:2px solid #fff;background:#c3cad6} .dot.up{background:var(--blue)} .dot.err{background:var(--red)} -.ident{min-width:170px;flex:0 0 200px;overflow:hidden} +.ident{min-width:190px;flex:0 0 236px;overflow:hidden} .ident .nm{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis} .ident .pj{font-size:12px;color:var(--muted);margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis} .metrics{display:flex;gap:16px;flex:1;flex-wrap:nowrap;align-items:center;overflow:hidden;min-width:0} diff --git a/server/index.js b/server/index.js index 66175af..f13a7d8 100644 --- a/server/index.js +++ b/server/index.js @@ -864,6 +864,8 @@ app.get('/api/containers', async (req, res) => { image: c.Image, state: c.State, status: c.Status, created: c.Created, project: projectOf(c.Labels), service: svcOf(c.Labels), health: m.health || '', restarts: m.restarts || 0, + startedAt: m.startedAt || '', + runMs: c.State === 'running' && m.startedAt ? Math.max(0, Date.now() - Date.parse(m.startedAt)) : null, ports: (c.Ports || []).map(p => ({ ip: p.IP, private: p.PrivatePort, public: p.PublicPort, type: p.Type })), stats: { cpu: st.cpu ?? 0, mem: st.mem ?? 0, memLimit: st.memLimit ?? 0, memPct: st.memPct ?? 0,