From 8f1c258b54d96bda3293379fe8eaddc4f386adfc Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Sep 2026 04:01:54 +0800 Subject: [PATCH] Show VM network and creation details in header --- static/app.js | 23 ++++++++++++++++++++--- static/index.html | 6 +++--- static/styles.css | 4 ++-- tests/test_libvirt_service.py | 19 ++++++++++++++++++- virsh_panel/libvirt_service.py | 6 ++++++ 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/static/app.js b/static/app.js index 1a21d3f2..385a8e9b 100644 --- a/static/app.js +++ b/static/app.js @@ -754,6 +754,15 @@ function vmIp(vm) { return String(vm.public_ip_cidr || "").trim().split("/")[0] || "未获取"; } +function vmCreatedAt(vm) { + const value = typeof vm.created_at === "string" ? vm.created_at.trim() : ""; + if (!value) return "未记录"; + const date = new Date(value); + if (!Number.isFinite(date.getTime())) return "未记录"; + const pad = (number) => String(number).padStart(2, "0"); + return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`; +} + function makeCell(row, className = "") { const cell = document.createElement("td"); if (className) cell.className = className; @@ -855,7 +864,12 @@ function renderVMs(connectionError = false) { nameButton.setAttribute("aria-label", `管理虚拟机 ${vm.name || uuid}`); nameButton.addEventListener("click", () => openVmDetail(uuid)); identityText.append(nameButton); - identityText.append(makeElement("span", "vm-id", uuid || "UUID 未知")); + const uuidRow = makeElement("span", "vm-uuid-row"); + const uuidText = makeElement("span", "vm-id", uuid || "UUID 未知"); + if (uuid) uuidText.title = uuid; + uuidRow.append(uuidText); + if (uuid) uuidRow.append(makeCopyIconButton(uuid, "UUID")); + identityText.append(uuidRow); identity.append(identityText); const identityCell = makeCell(row); identityCell.dataset.label = "虚拟机"; @@ -968,13 +982,16 @@ function renderVmDetail(vm) { const busy = state.vmActionInFlight === uuid; const system = vmSystemInfo(vm); text("vm-detail-name", vm.name || "未命名虚拟机"); - text("vm-detail-uuid", uuid || "UUID 未知"); text("vm-detail-state", stateLabel(vm.state)); byId("vm-detail-state").className = `state-pill ${category}`; - text("vm-detail-region", vmRegion(vm)); + const region = vmRegion(vm); + text("vm-detail-header-region", region); + text("vm-detail-header-created-at", vmCreatedAt(vm)); + text("vm-detail-region", region); text("vm-detail-os-label", system.label); text("vm-detail-os", system.value); const ip = vmIp(vm); + text("vm-detail-header-ip", ip); text("vm-detail-ip", ip); byId("vm-detail-ip-copy").hidden = ip === "未获取"; text("vm-detail-spec", `${vm.vcpu ?? "—"} vCPU · ${vm.memory_mib ?? "—"} MiB`); diff --git a/static/index.html b/static/index.html index ba70e776..2c638bf0 100644 --- a/static/index.html +++ b/static/index.html @@ -5,8 +5,8 @@ VirtPilot · 虚拟机管理 - - + +
@@ -224,7 +224,7 @@