重做实例页 UI:列表卡片为主,添加收起,Token 默认隐藏,风格对齐系统设置。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
(function () {
|
||||
function fmtVer(v) {
|
||||
if (!v || !v.online) return v && v.msg ? String(v.msg) : "离线";
|
||||
const short = v.short_sha || (v.sha ? String(v.sha).slice(0, 7) : "");
|
||||
const branch = v.branch ? v.branch + " · " : "";
|
||||
if (!short) return "未知版本";
|
||||
return branch + short + (v.dirty ? " (dirty)" : "");
|
||||
}
|
||||
|
||||
async function refreshVersion(card) {
|
||||
const iid = card.getAttribute("data-id");
|
||||
const verEl = card.querySelector("[data-inst-version]");
|
||||
if (!iid || !verEl) return;
|
||||
verEl.textContent = "…";
|
||||
verEl.className = "update-version muted";
|
||||
try {
|
||||
const r = await fetch("/api/instances/" + iid + "/version", {
|
||||
credentials: "same-origin",
|
||||
headers: { Accept: "application/json" },
|
||||
});
|
||||
const v = await r.json();
|
||||
if (v && v.online) {
|
||||
verEl.textContent = fmtVer(v);
|
||||
verEl.className = "update-version online";
|
||||
} else {
|
||||
verEl.textContent = (v && v.msg) || "离线";
|
||||
verEl.className = "update-version offline";
|
||||
}
|
||||
} catch (e) {
|
||||
verEl.textContent = "探测失败";
|
||||
verEl.className = "update-version offline";
|
||||
}
|
||||
}
|
||||
|
||||
function bindTokenToggles(root) {
|
||||
(root || document).querySelectorAll(".inst-token-toggle").forEach(function (btn) {
|
||||
if (btn.dataset.bound) return;
|
||||
btn.dataset.bound = "1";
|
||||
btn.addEventListener("click", function () {
|
||||
const wrap = btn.closest(".inst-token-wrap");
|
||||
const input = wrap && wrap.querySelector(".inst-token-input");
|
||||
if (!input) return;
|
||||
const show = input.type === "password";
|
||||
input.type = show ? "text" : "password";
|
||||
btn.textContent = show ? "隐藏" : "显示";
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function boot() {
|
||||
bindTokenToggles(document);
|
||||
document.querySelectorAll(".inst-card[data-id]").forEach(function (card) {
|
||||
refreshVersion(card);
|
||||
const btn = card.querySelector("[data-inst-refresh-ver]");
|
||||
if (btn) {
|
||||
btn.addEventListener("click", function (e) {
|
||||
e.preventDefault();
|
||||
refreshVersion(card);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", boot);
|
||||
} else {
|
||||
boot();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user