|
|
|
|
@ -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);
|
|
|
|
|
|