fix: restore from regex corruption, JS-bind modal close, data-action delegation
This commit is contained in:
@@ -22,13 +22,13 @@ const App = {
|
||||
const el = document.getElementById('sidebar-nav');
|
||||
if (el) el.insertAdjacentHTML('beforeend', '<div style="color:red;font-size:10px;padding:8px">Error: ' + String(msg).substring(0,80) + '</div>');
|
||||
};
|
||||
document.getElementById('modal-close').onclick = () => this.closeModal();
|
||||
document.getElementById('modal-close-btn').onclick = () => this.closeModal();
|
||||
document.addEventListener('click', (e) => {
|
||||
const action = e.target.closest('[data-action]');
|
||||
if (!action) return;
|
||||
const [obj, method, ...args] = action.dataset.action.split(':');
|
||||
const target = window[obj];
|
||||
if (target && target[method]) target[method](...args);
|
||||
const btn = e.target.closest('[data-action]');
|
||||
if (!btn) return;
|
||||
const parts = btn.dataset.action.split(':');
|
||||
const target = window[parts[0]];
|
||||
if (target && target[parts[1]]) target[parts[1]](...parts.slice(2));
|
||||
});
|
||||
this.route();
|
||||
},
|
||||
@@ -68,7 +68,6 @@ const App = {
|
||||
if (page === 'install') { this.showPublic('install'); return; }
|
||||
if (page === 'home') { this.showPublic('home', param); return; }
|
||||
if (page === 'login' || page === 'register') { this.showPublic(page); return; }
|
||||
if (page === 'forgot' || page === 'reset') { this.showPublic(page); return; }
|
||||
if (!Auth.logged()) { location.hash = '#/login'; return; }
|
||||
|
||||
this.showLayout();
|
||||
@@ -104,7 +103,7 @@ const App = {
|
||||
const pub = document.getElementById('public-page');
|
||||
pub.classList.remove('hidden');
|
||||
this.updateTopAuth();
|
||||
const comp = page === 'login' ? LoginPage : page === 'register' ? RegisterPage : page === 'install' ? InstallPage : page === 'forgot' ? ForgotPage : page === 'reset' ? ResetPage : HomePage;
|
||||
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 = '<div class="pub-card"><div class="logo"><i class="fas fa-exclamation-triangle" style="color:var(--d)"></i><h2>加载失败</h2><p>请刷新页面重试</p></div></div>';
|
||||
});
|
||||
@@ -173,8 +172,6 @@ window.PollsPage = PollsPage;
|
||||
window.FeaturesPage = FeaturesPage;
|
||||
window.LoginPage = LoginPage;
|
||||
window.RegisterPage = RegisterPage;
|
||||
window.ForgotPage = ForgotPage;
|
||||
window.ResetPage = ResetPage;
|
||||
window.HomePage = HomePage;
|
||||
window.InstallPage = InstallPage;
|
||||
window.U = U;
|
||||
|
||||
Reference in New Issue
Block a user