From 989a3ae4cf462f50fce4e898e3e056216cec6d3d Mon Sep 17 00:00:00 2001 From: canglan Date: Sun, 12 Jul 2026 01:53:59 +0800 Subject: [PATCH] feat: home page hash-based tab routing for shareable links --- public/js/app.js | 7 ++++--- public/js/pages/home.js | 35 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 4d12603..f8c9b9b 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -55,7 +55,8 @@ const App = { } if (page === 'install') { this.showPublic('install'); return; } - if (page === 'home' || page === 'login' || page === 'register') { this.showPublic(page); return; } + if (page === 'home') { this.showPublic('home', param); return; } + if (page === 'login' || page === 'register') { this.showPublic(page); return; } if (!Auth.logged()) { location.hash = '#/login'; return; } this.showLayout(); @@ -83,13 +84,13 @@ const App = { } }, - showPublic(page) { + showPublic(page, param) { document.getElementById('top-auth').classList.remove('hidden'); document.getElementById('main-layout').classList.add('hidden'); const pub = document.getElementById('public-page'); pub.classList.remove('hidden'); const comp = page === 'login' ? LoginPage : page === 'register' ? RegisterPage : page === 'install' ? InstallPage : HomePage; - Promise.resolve(comp.render()).then(html => { pub.innerHTML = html; if (comp.mount) comp.mount(); }); + Promise.resolve(comp.render(param)).then(html => { pub.innerHTML = html; if (comp.mount) comp.mount(param); }); }, showLayout() { diff --git a/public/js/pages/home.js b/public/js/pages/home.js index 552f906..5649096 100644 --- a/public/js/pages/home.js +++ b/public/js/pages/home.js @@ -1,26 +1,25 @@ const HomePage = { - async render() { + async render(tab) { + const t = tab || 'report'; return `
- - - - + + + +
`; }, - mount() { + mount(tab) { + const t = tab || 'report'; const tabBtns = document.querySelectorAll('.tab-nav button'); const tabContent = document.getElementById('home-tab'); - let currentTab = 'report'; - function switchTab(tab) { - currentTab = tab; - tabBtns.forEach(b => b.classList.toggle('active', b.dataset.tab === tab)); - if (tab === 'tracking') renderTracking(tabContent); - else TicketCreate.render(tabContent, { type: tab, prefill: {}, backLink: null }); + function switchContent(type) { + if (type === 'tracking') renderTracking(tabContent); + else TicketCreate.render(tabContent, { type, prefill: {}, backLink: null }); } function renderTracking(ct) { @@ -35,8 +34,8 @@ const HomePage = { `; } - tabBtns.forEach(b => b.onclick = () => switchTab(b.dataset.tab)); - switchTab('report'); + tabBtns.forEach(b => b.onclick = () => App.navigate('home', b.dataset.tab)); + switchContent(t); this.searchTracking = async () => { const token = document.getElementById('track-token').value.trim(); @@ -48,10 +47,10 @@ const HomePage = { ct.innerHTML = tickets.length ? `
- ${tickets.map(t => ` - - - + ${tickets.map(tick => ` + + + `).join('')}
#类型标题状态时间操作
${t.id}${U.badge(t.type,'type')}${U.esc(t.title)}${U.badge(t.status,'status')}${U.date(t.created_at)}
${tick.id}${U.badge(tick.type,'type')}${U.esc(tick.title)}${U.badge(tick.status,'status')}${U.date(tick.created_at)}
` : '

未找到工单

'; } catch (ex) { ct.innerHTML = `
${ex.message}
`; } };