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

@@ -11,7 +11,8 @@ const App = {
{ 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();
window.addEventListener('hashchange', () => this.route());
this.route();
@@ -32,19 +33,12 @@ const App = {
closeModal() { document.getElementById('modal-overlay').classList.add('hidden'); },
navigate(page, param) { location.hash = `#/${page}` + (param ? `/${param}` : ''); },
async route() {
route() {
const hash = location.hash || '#/home';
const parts = hash.replace('#/', '').split('/');
const page = parts[0];
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') {
const params = new URLSearchParams((location.hash.split('?')[1] || ''));
const token = params.get('token');
@@ -85,6 +79,7 @@ const App = {
},
showPublic(page, param) {
document.getElementById('top-bar').classList.remove('hidden');
document.getElementById('top-auth').classList.remove('hidden');
document.getElementById('main-layout').classList.add('hidden');
const pub = document.getElementById('public-page');
@@ -94,10 +89,9 @@ const App = {
},
showLayout() {
document.getElementById('top-auth').classList.add('hidden');
document.getElementById('top-bar').classList.add('hidden');
document.getElementById('public-page').classList.add('hidden');
document.getElementById('main-layout').classList.remove('hidden');
document.getElementById('main-layout').classList.remove('hidden');
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>`;
},