diff --git a/public/js/app.js b/public/js/app.js index e39c720..5aeee41 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -85,18 +85,29 @@ const App = { document.getElementById('main-layout').classList.add('hidden'); const pub = document.getElementById('public-page'); pub.classList.remove('hidden'); - const topAuth = document.getElementById('top-auth'); - if (Auth.logged()) { topAuth.classList.add('hidden'); } else { topAuth.classList.remove('hidden'); } + this.updateTopAuth(); const comp = page === 'login' ? LoginPage : page === 'register' ? RegisterPage : page === 'install' ? InstallPage : HomePage; comp.render(param).then(html => { pub.innerHTML = html; if (comp.mount) comp.mount(param); }).catch(() => { pub.innerHTML = '
'; }); }, + updateTopAuth() { + const el = document.getElementById('top-auth'); + if (Auth.logged()) { + const u = Auth.user(); + el.innerHTML = `${U.esc(u.game_name||u.username)}`; + el.style.display = 'flex'; + } else { + el.innerHTML = ` 登录 注册`; + el.style.display = 'flex'; + } + }, + showLayout() { - document.getElementById('top-bar').classList.add('hidden'); document.getElementById('public-page').classList.add('hidden'); document.getElementById('main-layout').classList.remove('hidden'); + this.updateTopAuth(); const u = Auth.user(); document.getElementById('user-info').innerHTML = `
${U.esc(u.game_name||u.username).charAt(0).toUpperCase()}
${U.esc(u.game_name||u.username)}
${U.ROLE[u.role]}
`; this.loadFooter();