修复无法单击的错误
Some checks failed
build / build (api, amd64, linux) (push) Failing after -49s
build / build (api, arm64, linux) (push) Failing after -51s
build / build (api.exe, amd64, windows) (push) Failing after -51s

This commit is contained in:
CN-JS-HuiBai
2026-04-18 12:17:24 +08:00
parent def8352bbb
commit 9c28e65775
4 changed files with 97 additions and 37 deletions

View File

@@ -39,7 +39,9 @@
realname: { list: [], pagination: null },
devices: { list: [], pagination: null },
ipv6: { list: [], pagination: null },
expandedNodes: new Set()
expandedNodes: new Set(),
prevUser: null,
prevRoute: null
};
const ROUTE_META = {
@@ -73,6 +75,9 @@
root.addEventListener("click", onClick);
root.addEventListener("submit", onSubmit);
// Initialize shell and modal containers
root.innerHTML = '<div id="admin-shell-container"></div><div id="admin-modal-container"></div><div id="admin-busy-container"></div>';
if (state.token) {
await loadBootstrap();
} else {
@@ -266,6 +271,8 @@
}
if (action === "plan-delete") {
event.preventDefault();
event.stopPropagation();
if (confirm("确认删除该套餐吗?")) {
await adminPost(`${cfg.api.adminBase}/plan/drop`, { id: Number(actionEl.getAttribute("data-id")) });
await hydrateRoute();
@@ -280,6 +287,8 @@
}
if (action === "coupon-delete") {
event.preventDefault();
event.stopPropagation();
if (confirm("确认删除该优惠券吗?")) {
await adminPost(`${cfg.api.adminBase}/coupon/drop`, { id: Number(actionEl.getAttribute("data-id")) });
await hydrateRoute();
@@ -312,6 +321,8 @@
}
if (action === "order-paid") {
event.preventDefault();
event.stopPropagation();
await adminPost(`${cfg.api.adminBase}/order/paid`, {
trade_no: actionEl.getAttribute("data-trade")
});
@@ -320,6 +331,8 @@
}
if (action === "order-cancel") {
event.preventDefault();
event.stopPropagation();
await adminPost(`${cfg.api.adminBase}/order/cancel`, {
trade_no: actionEl.getAttribute("data-trade")
});
@@ -334,13 +347,18 @@
}
if (action === "node-edit") {
const item = state.nodes.find((row) => String(row.id) === actionEl.getAttribute("data-id"));
event.preventDefault();
event.stopPropagation();
const nodeId = String(actionEl.getAttribute("data-id"));
const item = state.nodes.find((row) => String(row.id) === nodeId);
state.modal = { type: "node", data: item || {} };
render();
return;
}
if (action === "node-copy") {
event.preventDefault();
event.stopPropagation();
const nodeId = Number(actionEl.getAttribute("data-id"));
try {
await adminPost(`${cfg.api.adminBase}/server/manage/copy`, { id: nodeId });
@@ -350,6 +368,8 @@
}
if (action === "node-delete") {
event.preventDefault();
event.stopPropagation();
if (confirm("确认删除该节点吗?")) {
const nodeId = Number(actionEl.getAttribute("data-id"));
try {
@@ -544,19 +564,32 @@
await hydrateRoute();
}
function render() {
root.innerHTML = state.user ? renderDashboard() : renderLogin();
if (state.modal) {
const modalShell = document.createElement("div");
modalShell.className = "modal-overlay";
modalShell.innerHTML = renderModalContent();
root.appendChild(modalShell);
function render(force) {
const shellContainer = document.getElementById("admin-shell-container");
const modalContainer = document.getElementById("admin-modal-container");
const busyContainer = document.getElementById("admin-busy-container");
if (!shellContainer || !modalContainer || !busyContainer) return;
// Re-render the shell if user or route changed, or if forced (e.g., data updated)
if (force || state.user !== state.prevUser || state.route !== state.prevRoute) {
shellContainer.innerHTML = state.user ? renderDashboard() : renderLogin();
state.prevUser = state.user;
state.prevRoute = state.route;
}
// Handle Modal independently
if (state.modal) {
modalContainer.innerHTML = `<div class="modal-overlay">${renderModalContent()}</div>`;
} else {
modalContainer.innerHTML = "";
}
// Handle Busy overlay independently
if (state.busy) {
const overlay = document.createElement("div");
overlay.className = "busy-overlay";
overlay.innerHTML = '<div class="busy-spinner">正在处理...</div>';
root.appendChild(overlay);
busyContainer.innerHTML = '<div class="busy-overlay"><div class="busy-spinner">正在处理...</div></div>';
} else {
busyContainer.innerHTML = "";
}
}
@@ -741,7 +774,8 @@
}
function renderNodeManage() {
const roots = state.nodes.filter((node) => !node.parent_id);
const isRoot = (node) => !node.parent_id || String(node.parent_id) === "0";
const roots = state.nodes.filter(isRoot);
const childrenByParent = {};
state.nodes.forEach((node) => {
if (node.parent_id) {
@@ -1332,17 +1366,17 @@
function setBusy(value) {
state.busy = value;
render();
render(true);
}
function show(message, type) {
state.message = message;
state.messageType = type || "info";
render();
render(true);
window.clearTimeout(show._timer);
show._timer = window.setTimeout(function () {
state.message = "";
render();
render(true);
}, 3000);
}