feat(hub): settings toggles for funds and dashboard nav

Add show_nav_funds and show_nav_dashboard in hub_settings display prefs to hide top nav entries and redirect direct URL access.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-11 11:00:19 +08:00
parent 07e8604ea6
commit 007e089121
6 changed files with 89 additions and 14 deletions
+51 -8
View File
@@ -3,17 +3,47 @@
let settingsCache = null;
let authState = { required: false, logged_in: true };
function showAccountPnlPref() {
function displayPref(key, defaultOn) {
const d = settingsCache && settingsCache.display;
if (!d || d.show_account_pnl === undefined) return true;
return !!d.show_account_pnl;
if (!d || d[key] === undefined) return defaultOn !== false;
return !!d[key];
}
function showAccountPnlPref() {
return displayPref("show_account_pnl", true);
}
function showNavFundsPref() {
return displayPref("show_nav_funds", true);
}
function showNavDashboardPref() {
return displayPref("show_nav_dashboard", true);
}
function syncNavVisibility(data) {
const d = (data && data.display) || {};
const navFunds = document.getElementById("nav-funds");
const navDash = document.getElementById("nav-dashboard");
if (navFunds) navFunds.classList.toggle("nav-hidden", d.show_nav_funds === false);
if (navDash) navDash.classList.toggle("nav-hidden", d.show_nav_dashboard === false);
}
function pageNavAllowed(page) {
if (page === "funds") return showNavFundsPref();
if (page === "dashboard") return showNavDashboardPref();
return true;
}
function syncDisplayPrefsUI(data) {
const cb = document.getElementById("pref-show-account-pnl");
if (!cb) return;
const show = data && data.display ? data.display.show_account_pnl : true;
cb.checked = show !== false;
const d = (data && data.display) || {};
const pnlCb = document.getElementById("pref-show-account-pnl");
const fundsCb = document.getElementById("pref-show-nav-funds");
const dashCb = document.getElementById("pref-show-nav-dashboard");
if (pnlCb) pnlCb.checked = d.show_account_pnl !== false;
if (fundsCb) fundsCb.checked = d.show_nav_funds !== false;
if (dashCb) dashCb.checked = d.show_nav_dashboard !== false;
syncNavVisibility(data);
}
function positionTableHeadHtml(compact) {
@@ -662,7 +692,11 @@
}
function setActiveNav() {
const page = currentPage();
let page = currentPage();
if (!pageNavAllowed(page)) {
history.replaceState({}, "", "/monitor");
page = "monitor";
}
const pageId = pageElementId(page);
document.querySelectorAll(".top-nav a").forEach((a) => {
const href = (a.getAttribute("href") || "").split("?")[0];
@@ -857,6 +891,7 @@
async function loadSettings() {
const r = await apiFetch("/api/settings");
settingsCache = await r.json();
syncNavVisibility(settingsCache);
return settingsCache;
}
@@ -3055,10 +3090,14 @@
function collectSettingsFromUI() {
const rows = [...document.querySelectorAll("#settings-list .settings-card")];
const pnlCb = document.getElementById("pref-show-account-pnl");
const fundsCb = document.getElementById("pref-show-nav-funds");
const dashCb = document.getElementById("pref-show-nav-dashboard");
return {
version: 1,
display: {
show_account_pnl: pnlCb ? !!pnlCb.checked : true,
show_nav_funds: fundsCb ? !!fundsCb.checked : true,
show_nav_dashboard: dashCb ? !!dashCb.checked : true,
},
exchanges: rows.map((card) => {
const caps = [];
@@ -3100,6 +3139,10 @@
await loadSettingsUI();
}
if (lastMonitorRows.length) renderMonitorGrid(lastMonitorRows);
if (!pageNavAllowed(currentPage())) {
history.replaceState({}, "", "/monitor");
setActiveNav();
}
} else showToast("保存失败", true);
} catch (e) {
showToast(String(e), true);