fix: move install check to init once, route() sync for instant nav, hide top-bar in admin

This commit is contained in:
2026-07-12 02:40:08 +08:00
parent 7699bd0598
commit 50f3cace51
2 changed files with 6 additions and 12 deletions

View File

@@ -306,7 +306,7 @@ tbody tr:last-child td{border-bottom:none}
.footer-inner{max-width:1280px;margin:0 auto;display:flex;justify-content:center;gap:28px;flex-wrap:wrap} .footer-inner{max-width:1280px;margin:0 auto;display:flex;justify-content:center;gap:28px;flex-wrap:wrap}
.footer-inner a{color:var(--g4);text-decoration:none;transition:color .2s} .footer-inner a{color:var(--g4);text-decoration:none;transition:color .2s}
.footer-inner a:hover{color:white} .footer-inner a:hover{color:white}
#app{min-height:calc(100vh - 52px);display:flex;flex-direction:column} #app{min-height:100vh;display:flex;flex-direction:column}
#public-page,#main-layout{flex:1} #public-page,#main-layout{flex:1}
/* ===== Install Page ===== */ /* ===== Install Page ===== */

View File

@@ -11,7 +11,8 @@ const App = {
{ id: 'export', label: '数据导出', icon: 'fa-download', roles: ['owner'] }, { id: 'export', label: '数据导出', icon: 'fa-download', roles: ['owner'] },
], ],
init() { async init() {
try { const s = await API.get('/install/status'); if (!s.installed) { location.hash = '#/install'; return; } } catch { location.hash = '#/install'; return; }
this.loadFooter(); this.loadFooter();
window.addEventListener('hashchange', () => this.route()); window.addEventListener('hashchange', () => this.route());
this.route(); this.route();
@@ -32,19 +33,12 @@ const App = {
closeModal() { document.getElementById('modal-overlay').classList.add('hidden'); }, closeModal() { document.getElementById('modal-overlay').classList.add('hidden'); },
navigate(page, param) { location.hash = `#/${page}` + (param ? `/${param}` : ''); }, navigate(page, param) { location.hash = `#/${page}` + (param ? `/${param}` : ''); },
async route() { route() {
const hash = location.hash || '#/home'; const hash = location.hash || '#/home';
const parts = hash.replace('#/', '').split('/'); const parts = hash.replace('#/', '').split('/');
const page = parts[0]; const page = parts[0];
const param = parts.slice(1).join('/'); const param = parts.slice(1).join('/');
if (page !== 'install') {
try {
const s = await API.get('/install/status');
if (!s.installed) { location.hash = '#/install'; return; }
} catch { location.hash = '#/install'; return; }
}
if (page === 'verify') { if (page === 'verify') {
const params = new URLSearchParams((location.hash.split('?')[1] || '')); const params = new URLSearchParams((location.hash.split('?')[1] || ''));
const token = params.get('token'); const token = params.get('token');
@@ -85,6 +79,7 @@ const App = {
}, },
showPublic(page, param) { showPublic(page, param) {
document.getElementById('top-bar').classList.remove('hidden');
document.getElementById('top-auth').classList.remove('hidden'); document.getElementById('top-auth').classList.remove('hidden');
document.getElementById('main-layout').classList.add('hidden'); document.getElementById('main-layout').classList.add('hidden');
const pub = document.getElementById('public-page'); const pub = document.getElementById('public-page');
@@ -94,10 +89,9 @@ const App = {
}, },
showLayout() { showLayout() {
document.getElementById('top-auth').classList.add('hidden'); document.getElementById('top-bar').classList.add('hidden');
document.getElementById('public-page').classList.add('hidden'); document.getElementById('public-page').classList.add('hidden');
document.getElementById('main-layout').classList.remove('hidden'); document.getElementById('main-layout').classList.remove('hidden');
document.getElementById('main-layout').classList.remove('hidden');
const u = Auth.user(); const u = Auth.user();
document.getElementById('user-info').innerHTML = `<div class="av">${(u.game_name||u.username).charAt(0).toUpperCase()}</div><div class="dt"><div class="nm">${u.game_name||u.username}</div><div class="rl">${U.ROLE[u.role]}</div></div>`; document.getElementById('user-info').innerHTML = `<div class="av">${(u.game_name||u.username).charAt(0).toUpperCase()}</div><div class="dt"><div class="nm">${u.game_name||u.username}</div><div class="rl">${U.ROLE[u.role]}</div></div>`;
}, },