Show relative VM creation age in detail view

main
admin 2 months ago
parent 9ee328f428
commit 4474610ea9

@ -984,6 +984,23 @@ function vmCreatedAt(vm) {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
function vmCreatedAgo(vm, now = Date.now()) {
const value = typeof vm.created_at === "string" ? vm.created_at.trim() : "";
if (!value) return "未记录";
const created = Date.parse(value);
if (!Number.isFinite(created)) return "未记录";
const elapsed = Math.max(0, now - created);
const minute = 60 * 1000;
const hour = 60 * minute;
const day = 24 * hour;
const month = 30 * day;
if (elapsed < minute) return "创建于刚刚";
if (elapsed < hour) return `创建于 ${Math.floor(elapsed / minute)} 分钟前`;
if (elapsed < day) return `创建于 ${Math.floor(elapsed / hour)} 小时前`;
if (elapsed < month) return `创建于 ${Math.floor(elapsed / day)} 天前`;
return `创建于 ${Math.floor(elapsed / month)} 个月前`;
}
function makeCell(row, className = "") {
const cell = document.createElement("td");
if (className) cell.className = className;
@ -1207,7 +1224,7 @@ function renderVmDetail(vm) {
byId("vm-detail-state").className = `state-pill ${category}`;
const region = vmRegion(vm);
text("vm-detail-header-region", region);
text("vm-detail-header-created-at", vmCreatedAt(vm));
text("vm-detail-header-created-at", vmCreatedAgo(vm));
text("vm-detail-region", region);
text("vm-detail-os-label", system.label);
text("vm-detail-os", system.value);

@ -5,8 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#101d2c" />
<title>VirtPilot · 虚拟机管理</title>
<link rel="stylesheet" href="/static/styles.css?v=email-login-1" />
<script type="module" src="/static/app.js?v=email-login-1"></script>
<link rel="stylesheet" href="/static/styles.css?v=vm-age-1" />
<script type="module" src="/static/app.js?v=vm-age-1"></script>
</head>
<body>
<div id="boot-screen" class="boot-screen" role="status" aria-live="polite">
@ -255,7 +255,7 @@
</div>
<section id="vm-detail-view" class="vm-detail-view" aria-labelledby="vm-detail-name" hidden>
<button id="vm-detail-back-button" class="button button-ghost vm-detail-back" type="button">← 返回虚拟机列表</button>
<div class="page-heading vm-detail-heading"><div><span class="eyebrow">VIRTUAL MACHINE DETAILS</span><h1 id="vm-detail-name" tabindex="-1">虚拟机</h1><p class="vm-detail-summary"><span><span class="sr-only">服务器 IP:</span><strong id="vm-detail-header-ip">未获取</strong></span><span><span class="sr-only">区域:</span><strong id="vm-detail-header-region">未设置</strong></span><span><span class="sr-only">创建时间:</span><strong id="vm-detail-header-created-at">未记录</strong></span></p></div><div class="heading-actions"><span id="vm-detail-state" class="state-pill other">未知</span><button id="vm-detail-refresh-button" class="button button-outline" type="button"><span aria-hidden="true">↻</span> 刷新</button></div></div>
<div class="page-heading vm-detail-heading"><div><span class="eyebrow">VIRTUAL MACHINE DETAILS</span><h1 id="vm-detail-name" tabindex="-1">虚拟机</h1><p class="vm-detail-summary"><span><span class="sr-only">服务器 IP:</span><strong id="vm-detail-header-ip">未获取</strong></span><span><span class="sr-only">区域:</span><strong id="vm-detail-header-region">未设置</strong></span><span><strong id="vm-detail-header-created-at">未记录</strong></span></p></div><div class="heading-actions"><span id="vm-detail-state" class="state-pill other">未知</span><button id="vm-detail-refresh-button" class="button button-outline" type="button"><span aria-hidden="true">↻</span> 刷新</button></div></div>
<div class="vm-detail-grid">
<section class="inventory-panel vm-detail-panel" aria-labelledby="vm-detail-info-title"><div class="panel-heading"><div><h2 id="vm-detail-info-title">虚拟机信息</h2><p>状态和配置每 15 秒自动更新;IP 是面板记录的配置,不代表系统已联网。</p></div></div><dl class="vm-detail-facts">
<div><dt>地区</dt><dd id="vm-detail-region">未设置</dd></div><div><dt id="vm-detail-os-label">系统</dt><dd id="vm-detail-os">未识别</dd></div>

Loading…
Cancel
Save