进一步补充后端API
This commit is contained in:
@@ -28,7 +28,8 @@
|
||||
currentTicket: null,
|
||||
dashboard: null,
|
||||
busy: false,
|
||||
modal: null // { type, data }
|
||||
modal: null, // { type, data }
|
||||
configTab: "site"
|
||||
};
|
||||
|
||||
boot();
|
||||
@@ -112,6 +113,8 @@
|
||||
} else if (state.route === "dashboard-node") {
|
||||
state.dashboard = unwrap(await request(api.dashboardSummary));
|
||||
state.nodes = toArray(unwrap(await request(api.serverNodes)));
|
||||
} else if (state.route === "system-config") {
|
||||
state.config = unwrap(await request(api.adminConfig));
|
||||
} else if (state.route === "overview") {
|
||||
state.dashboard = unwrap(await request(api.dashboardSummary));
|
||||
}
|
||||
@@ -133,6 +136,7 @@
|
||||
if (action === "nav") { window.location.hash = actionEl.getAttribute("data-route") || "overview"; return; }
|
||||
if (action === "refresh") { refreshAll(); return; }
|
||||
if (action === "modal-close") { state.modal = null; render(); return; }
|
||||
if (action === "config-tab") { state.configTab = actionEl.getAttribute("data-tab"); render(); return; }
|
||||
|
||||
// Handlers
|
||||
if (action === "plan-add") { state.modal = { type: "plan", data: {} }; render(); return; }
|
||||
@@ -179,6 +183,43 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "node-add") { state.modal = { type: "node", data: {} }; render(); return; }
|
||||
if (action === "node-edit") {
|
||||
var node = state.nodes.find(n => n.id == actionEl.getAttribute("data-id"));
|
||||
state.modal = { type: "node", data: node }; render(); return;
|
||||
}
|
||||
if (action === "node-copy") {
|
||||
adminPost(api.adminBase + "/server/manage/copy", { id: parseInt(actionEl.getAttribute("data-id")) }).then(hydrateRoute);
|
||||
return;
|
||||
}
|
||||
if (action === "node-delete") {
|
||||
if (!confirm("Are you sure?")) return;
|
||||
adminPost(api.adminBase + "/server/manage/drop", { id: parseInt(actionEl.getAttribute("data-id")) }).then(hydrateRoute);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "group-add") { state.modal = { type: "group", data: {} }; render(); return; }
|
||||
if (action === "group-edit") {
|
||||
var group = state.groups.find(g => g.id == actionEl.getAttribute("data-id"));
|
||||
state.modal = { type: "group", data: group }; render(); return;
|
||||
}
|
||||
if (action === "group-delete") {
|
||||
if (!confirm("Are you sure?")) return;
|
||||
adminPost(api.adminBase + "/server/group/drop", { id: parseInt(actionEl.getAttribute("data-id")) }).then(hydrateRoute);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "route-add") { state.modal = { type: "route", data: {} }; render(); return; }
|
||||
if (action === "route-edit") {
|
||||
var route = state.routes.find(r => r.id == actionEl.getAttribute("data-id"));
|
||||
state.modal = { type: "route", data: route }; render(); return;
|
||||
}
|
||||
if (action === "route-delete") {
|
||||
if (!confirm("Are you sure?")) return;
|
||||
adminPost(api.adminBase + "/server/route/drop", { id: parseInt(actionEl.getAttribute("data-id")) }).then(hydrateRoute);
|
||||
return;
|
||||
}
|
||||
|
||||
// Previous handlers
|
||||
if (action === "approve-all") { adminPost(api.realnameBase + "/approve-all", {}).then(hydrateRoute); return; }
|
||||
if (action === "sync-all") { adminPost(api.realnameBase + "/sync-all", {}).then(hydrateRoute); return; }
|
||||
@@ -218,6 +259,22 @@
|
||||
adminPost(api.adminBase + "/user/update", serializeForm(form)).then(() => { state.modal = null; hydrateRoute(); });
|
||||
return;
|
||||
}
|
||||
if (action === "config-save") {
|
||||
adminPost(api.adminBase + "/config/save", serializeForm(form)).then(() => { hydrateRoute(); });
|
||||
return;
|
||||
}
|
||||
if (action === "node-save") {
|
||||
adminPost(api.adminBase + "/server/manage/save", serializeForm(form)).then(() => { state.modal = null; hydrateRoute(); });
|
||||
return;
|
||||
}
|
||||
if (action === "group-save") {
|
||||
adminPost(api.adminBase + "/server/group/save", serializeForm(form)).then(() => { state.modal = null; hydrateRoute(); });
|
||||
return;
|
||||
}
|
||||
if (action === "route-save") {
|
||||
adminPost(api.adminBase + "/server/route/save", serializeForm(form)).then(() => { state.modal = null; hydrateRoute(); });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
@@ -241,6 +298,9 @@
|
||||
if (m.type === "plan") html += renderPlanForm(m.data);
|
||||
if (m.type === "user") html += renderUserForm(m.data);
|
||||
if (m.type === "coupon") html += renderCouponForm(m.data);
|
||||
if (m.type === "node") html += renderNodeForm(m.data);
|
||||
if (m.type === "group") html += renderGroupForm(m.data);
|
||||
if (m.type === "route") html += renderRouteForm(m.data);
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
@@ -405,6 +465,7 @@
|
||||
if (route === "coupon-manage") return renderCouponManage();
|
||||
if (route === "user-manage") return renderUserManage();
|
||||
if (route === "ticket-manage") return renderTicketManage();
|
||||
if (route === "system-config") return renderSystemConfig();
|
||||
if (route === "realname") return renderRealName();
|
||||
if (route === "user-online-devices") return renderOnlineDevices();
|
||||
return renderOverview();
|
||||
@@ -536,7 +597,7 @@
|
||||
function renderNodeManage() {
|
||||
var rows = state.nodes || [];
|
||||
return [
|
||||
'<div class="toolbar" style="margin-bottom:24px;"><button class="btn btn-primary">Add New Node</button></div>',
|
||||
'<div class="toolbar" style="margin-bottom:24px;"><button class="btn btn-primary" data-action="node-add">Add New Node</button></div>',
|
||||
'<div class="table-wrap glass-card">',
|
||||
renderTable(["ID", "Name/Host", "Type", "Rate", "Visibility", "Actions"], rows.map(function(row) {
|
||||
return [
|
||||
@@ -545,7 +606,7 @@
|
||||
escapeHtml(row.type),
|
||||
'<strong>' + row.rate + 'x</strong>',
|
||||
renderStatus(row.show ? "visible" : "hidden"),
|
||||
'<div class="row-actions"><button class="btn btn-ghost" data-action="node-edit" data-id="' + row.id + '">Edit</button><button class="btn btn-ghost" data-action="node-copy" data-id="' + row.id + '">Copy</button></div>'
|
||||
'<div class="row-actions"><button class="btn btn-ghost" data-action="node-edit" data-id="' + row.id + '">Edit</button><button class="btn btn-ghost" data-action="node-copy" data-id="' + row.id + '">Copy</button><button class="btn btn-ghost" data-action="node-delete" data-id="' + row.id + '">Delete</button></div>'
|
||||
];
|
||||
})),
|
||||
'</div>'
|
||||
@@ -587,6 +648,72 @@
|
||||
].join("");
|
||||
}
|
||||
|
||||
function renderNodeGroup() {
|
||||
var rows = state.groups || [];
|
||||
return [
|
||||
'<div class="toolbar" style="margin-bottom:24px;"><button class="btn btn-primary" data-action="group-add">Add Group</button></div>',
|
||||
'<div class="table-wrap glass-card">',
|
||||
renderTable(["ID", "Group Name", "Node Count", "User Count", "Actions"], rows.map(function(row) {
|
||||
return [
|
||||
'<code>' + row.id + '</code>',
|
||||
'<strong>' + escapeHtml(row.name) + '</strong>',
|
||||
'<code>' + (row.server_count || 0) + '</code>',
|
||||
'<code>' + (row.user_count || 0) + '</code>',
|
||||
'<div class="row-actions"><button class="btn btn-ghost" data-action="group-edit" data-id="' + row.id + '">Edit</button><button class="btn btn-ghost" data-action="group-delete" data-id="' + row.id + '">Delete</button></div>'
|
||||
];
|
||||
})),
|
||||
'</div>'
|
||||
].join("");
|
||||
}
|
||||
|
||||
function renderNodeRoute() {
|
||||
var rows = state.routes || [];
|
||||
return [
|
||||
'<div class="toolbar" style="margin-bottom:24px;"><button class="btn btn-primary" data-action="route-add">Add Route</button></div>',
|
||||
'<div class="table-wrap glass-card">',
|
||||
renderTable(["ID", "Remarks", "Match", "Action", "Actions"], rows.map(function(row) {
|
||||
return [
|
||||
'<code>' + row.id + '</code>',
|
||||
'<strong>' + escapeHtml(row.remarks) + '</strong>',
|
||||
'<div style="font-size:12px;">' + (row.match || []).join(", ") + '</div>',
|
||||
'<code>' + row.action + '</code>',
|
||||
'<div class="row-actions"><button class="btn btn-ghost" data-action="route-edit" data-id="' + row.id + '">Edit</button><button class="btn btn-ghost" data-action="route-delete" data-id="' + row.id + '">Delete</button></div>'
|
||||
];
|
||||
})),
|
||||
'</div>'
|
||||
].join("");
|
||||
}
|
||||
|
||||
function renderSystemConfig() {
|
||||
var cfg = state.config || {};
|
||||
var tab = state.configTab || "site";
|
||||
var sections = ["site", "subscribe", "server", "email", "telegram", "safe"];
|
||||
|
||||
var tabData = cfg[tab] || {};
|
||||
|
||||
return [
|
||||
'<div class="tabs-nav glass-card" style="margin-bottom:24px; padding:8px; display:flex; gap:8px; overflow-x:auto;">',
|
||||
sections.map(s => '<button class="btn ' + (tab === s ? "btn-primary" : "btn-ghost") + '" data-action="config-tab" data-tab="' + s + '">' + s.toUpperCase() + '</button>').join(""),
|
||||
'</div>',
|
||||
'<form data-form="config-save" class="glass-card card fade-in" style="padding:40px;">',
|
||||
'<div class="grid grid-2">',
|
||||
Object.keys(tabData).map(key => {
|
||||
var val = tabData[key];
|
||||
var label = key.replace(/_/g, " ").replace(/\b\w/g, c => c.toUpperCase());
|
||||
var input = '<input name="' + key + '" value="' + (val === null ? "" : val) + '" />';
|
||||
if (typeof val === "boolean") {
|
||||
input = '<select name="' + key + '"><option value="1" ' + (val ? "selected" : "") + '>Enabled</option><option value="0" ' + (val ? "" : "selected") + '>Disabled</option></select>';
|
||||
}
|
||||
return '<div class="field"><label>' + label + '</label>' + input + '</div>';
|
||||
}).join(""),
|
||||
'</div>',
|
||||
'<div style="margin-top:32px; border-top:1px solid var(--border); padding-top:32px;">',
|
||||
'<button class="btn btn-primary" type="submit">Apply System Settings</button>',
|
||||
'</div>',
|
||||
'</form>'
|
||||
].join("");
|
||||
}
|
||||
|
||||
// Helpers
|
||||
function statCard(title, value, hint) {
|
||||
return [
|
||||
@@ -693,6 +820,48 @@
|
||||
});
|
||||
return r;
|
||||
}
|
||||
function renderNodeForm(d) {
|
||||
return [
|
||||
'<h2>' + (d.id ? "Edit Node" : "Create Node") + '</h2>',
|
||||
'<form data-form="node-save" style="max-height:70vh; overflow-y:auto; padding-right:12px;">',
|
||||
'<input type="hidden" name="id" value="' + (d.id || "") + '" />',
|
||||
'<div class="grid grid-2">',
|
||||
'<div class="field"><label>Node Name</label><input name="name" value="' + (d.name || "") + '" required /></div>',
|
||||
'<div class="field"><label>Node Type</label><input name="type" value="' + (d.type || "shadowsocks") + '" required /></div>',
|
||||
'<div class="field"><label>Server Domain/IP</label><input name="host" value="' + (d.host || "") + '" required /></div>',
|
||||
'<div class="field"><label>Public Port</label><input name="port" value="' + (d.port || "") + '" required /></div>',
|
||||
'<div class="field"><label>Internal Port</label><input type="number" name="server_port" value="' + (d.server_port || 443) + '" required /></div>',
|
||||
'<div class="field"><label>Rate multiplier</label><input type="number" step="0.1" name="rate" value="' + (d.rate || 1.0) + '" /></div>',
|
||||
'</div>',
|
||||
'<div class="field"><label>Visibility</label><select name="show"><option value="1">Visible</option><option value="0" ' + (d.show ? "" : "selected") + '>Hidden</option></select></div>',
|
||||
'<button class="btn btn-primary" type="submit">Save Node</button>',
|
||||
'</form>'
|
||||
].join("");
|
||||
}
|
||||
|
||||
function renderGroupForm(d) {
|
||||
return [
|
||||
'<h2>' + (d.id ? "Edit Group" : "Create Group") + '</h2>',
|
||||
'<form data-form="group-save">',
|
||||
'<input type="hidden" name="id" value="' + (d.id || "") + '" />',
|
||||
'<div class="field"><label>Group Name</label><input name="name" value="' + (d.name || "") + '" required /></div>',
|
||||
'<button class="btn btn-primary" type="submit">Save Group</button>',
|
||||
'</form>'
|
||||
].join("");
|
||||
}
|
||||
|
||||
function renderRouteForm(d) {
|
||||
return [
|
||||
'<h2>' + (d.id ? "Edit Route" : "Create Route") + '</h2>',
|
||||
'<form data-form="route-save">',
|
||||
'<input type="hidden" name="id" value="' + (d.id || "") + '" />',
|
||||
'<div class="field"><label>Remarks</label><input name="remarks" value="' + (d.remarks || "") + '" required /></div>',
|
||||
'<div class="field"><label>Action</label><select name="action"><option value="direct">Direct</option><option value="proxy">Proxy</option><option value="block">Block</option></select></div>',
|
||||
'<button class="btn btn-primary" type="submit">Save Route</button>',
|
||||
'</form>'
|
||||
].join("");
|
||||
}
|
||||
|
||||
function getRouteTitle(r) { return r.replace(/-/g, " ").replace(/\b\w/g, c => c.toUpperCase()); }
|
||||
function getRouteDescription(r) { return "SingBox Gopanel integrated module management."; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user