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:
@@ -326,6 +326,10 @@ a:hover {
|
||||
transition: background 0.15s, color 0.15s, box-shadow 0.15s;
|
||||
}
|
||||
|
||||
.top-nav a.nav-hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.top-nav a:hover {
|
||||
color: var(--text);
|
||||
background: var(--panel-hover);
|
||||
@@ -2176,9 +2180,16 @@ button.btn-sm {
|
||||
}
|
||||
|
||||
.settings-display-chk {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.settings-display-chk + .settings-display-chk {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.settings-display-hint {
|
||||
margin: 8px 0 0;
|
||||
font-size: 0.78rem;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -502,12 +502,20 @@
|
||||
</details>
|
||||
<p id="settings-meta-line" class="settings-meta-line"></p>
|
||||
<div class="settings-display-panel card">
|
||||
<h3 class="settings-display-title">监控区显示</h3>
|
||||
<h3 class="settings-display-title">显示与导航</h3>
|
||||
<label class="chk-label settings-display-chk">
|
||||
<input type="checkbox" id="pref-show-account-pnl" checked />
|
||||
显示资金账户、交易账户与浮动盈亏
|
||||
监控区显示资金账户、交易账户与浮动盈亏
|
||||
</label>
|
||||
<p class="settings-display-hint">关闭后监控区不显示上述数值;保存至 hub_settings.json,换浏览器同样生效。</p>
|
||||
<label class="chk-label settings-display-chk">
|
||||
<input type="checkbox" id="pref-show-nav-funds" checked />
|
||||
顶栏显示「资金概况」
|
||||
</label>
|
||||
<label class="chk-label settings-display-chk">
|
||||
<input type="checkbox" id="pref-show-nav-dashboard" checked />
|
||||
顶栏显示「数据看板」
|
||||
</label>
|
||||
<p class="settings-display-hint">保存至 hub_settings.json,换浏览器同样生效。关闭导航后对应页面将不可从顶栏进入。</p>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<button type="button" id="btn-settings-save" class="primary">保存设置</button>
|
||||
@@ -547,6 +555,6 @@
|
||||
<script src="/assets/funds.js?v=20260609-hub-funds-fold"></script>
|
||||
<script src="/assets/dashboard.js?v=20260611-hub-dash-sse"></script>
|
||||
<script src="/assets/ai_review_render.js?v=2"></script>
|
||||
<script src="/assets/app.js?v=20260611-hub-ai-chat"></script>
|
||||
<script src="/assets/app.js?v=20260611-hub-nav-prefs"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user