From 4f4df7e47983be7092bf895f46fe213f1691f482 Mon Sep 17 00:00:00 2001 From: canglan Date: Mon, 13 Jul 2026 04:07:18 +0800 Subject: [PATCH] fix: backend+frontend full audit - 15 bugs fixed across all files --- public/js/auth.js | 2 +- public/js/pages/home.js | 2 +- public/js/pages/notifications.js | 4 ++-- public/js/pages/ticket-create.js | 2 +- public/js/pages/ticket-detail.js | 4 ++-- public/js/utils.js | 10 ++++++---- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/public/js/auth.js b/public/js/auth.js index 0d3142e..d3a4d7d 100644 --- a/public/js/auth.js +++ b/public/js/auth.js @@ -4,7 +4,7 @@ const Auth = { token() { return localStorage.getItem(this.TK); }, user() { try { return JSON.parse(localStorage.getItem(this.US)); } catch { return null; } }, - logged() { return !!this.token(); }, + logged() { return !!(this.token() && this.user()); }, async login(username, password) { const d = await API.post('/auth/login', { username, password }); diff --git a/public/js/pages/home.js b/public/js/pages/home.js index 5649096..ddb62fc 100644 --- a/public/js/pages/home.js +++ b/public/js/pages/home.js @@ -50,7 +50,7 @@ const HomePage = { ${tickets.map(tick => ` ${tick.id}${U.badge(tick.type,'type')}${U.esc(tick.title)} ${U.badge(tick.status,'status')}${U.date(tick.created_at)} - + `).join('')}` : '

未找到工单

'; } catch (ex) { ct.innerHTML = `
${ex.message}
`; } }; diff --git a/public/js/pages/notifications.js b/public/js/pages/notifications.js index 5a803a2..720adb6 100644 --- a/public/js/pages/notifications.js +++ b/public/js/pages/notifications.js @@ -17,7 +17,7 @@ const NotificationsPage = { ${c.webhook_url?`
地址${U.esc(c.webhook_url)}
`:''}
事件${EventsLabel(c.events)}
- +
@@ -61,7 +61,7 @@ const NotificationsPage = { }, async test(id) { try { alert((await API.post(`/notifications/${id}/test`)).message); } catch(ex){alert(ex.message);} }, - async del(id) { if(await U.confirm('确认删除此通知配置?')){ await API.req('DELETE',`/notifications/${id}`); this.load(); } } + async del(id) { if(await U.confirm('确认删除此通知配置?')){ try { await API.req('DELETE',`/notifications/${id}`); this.load(); } catch(ex){alert(ex.message);} } } }; function EventOptions(current) { return ['all','ticket_created','ticket_claimed','ticket_transferred','ticket_updated'].map(e=>``).join(''); } diff --git a/public/js/pages/ticket-create.js b/public/js/pages/ticket-create.js index 5118ecb..c1c300d 100644 --- a/public/js/pages/ticket-create.js +++ b/public/js/pages/ticket-create.js @@ -65,7 +65,7 @@ const TicketCreate = {

点击选择文件或拖拽到此处

-

支持: JPG/PNG/GIF/WebP/MP4/WebM

+

支持: JPG/PNG/GIF/WebP/MP4/WebM   每个最大50MB

diff --git a/public/js/pages/ticket-detail.js b/public/js/pages/ticket-detail.js index 5e4ff91..3f1866f 100644 --- a/public/js/pages/ticket-detail.js +++ b/public/js/pages/ticket-detail.js @@ -7,10 +7,10 @@ const TicketDetail = { const id = this.id; document.getElementById('page-title').textContent = `工单 #${id}`; document.getElementById('page-actions').innerHTML = ``; - try { this.render(document.getElementById('page-content'), await API.get(`/tickets/${id}`)); } catch (e) { document.getElementById('page-content').innerHTML = `
${e.message}
`; } + try { this.renderDetail(document.getElementById('page-content'), await API.get(`/tickets/${id}`)); } catch (e) { document.getElementById('page-content').innerHTML = `
${e.message}
`; } }, - render(ct, t) { + renderDetail(ct, t) { const isStaff = Auth.isAdmin(); const isOwner = Auth.isOwner(); const isRep = t.type === 'report'; diff --git a/public/js/utils.js b/public/js/utils.js index 7f80b3f..0aa95c6 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -27,11 +27,12 @@ const U = { escJs(s) { if (!s) return ''; - return String(s).replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/\n/g,'\\n'); + return String(s).replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/"/g,'"').replace(/\n/g,'\\n'); }, showAlert(containerId, type, msg) { const ct = document.getElementById(containerId || 'page-content'); + if (!ct) return; const el = document.createElement('div'); el.className = `alert alert-${type === 'success' ? 's' : type === 'error' ? 'e' : 'i'}`; el.textContent = msg; @@ -39,20 +40,21 @@ const U = { setTimeout(() => el.remove(), 6000); }, - loading(ct) { ct.innerHTML = '

加载中...

'; }, + loading(ct) { if (!ct) return; ct.innerHTML = '

加载中...

'; }, modal(title, html, w) { const o = document.getElementById('modal-overlay'); + if (!o) return; document.getElementById('modal-title').textContent = title; document.getElementById('modal-body').innerHTML = html; - if (w) o.querySelector('.modal-box').style.width = w; + o.querySelector('.modal-box').style.width = w || ''; o.classList.remove('hidden'); }, confirm(msg) { return new Promise(resolve => { this.modal('确认', ` -

${msg}

+

${this.esc(msg)}

`); document.querySelector('.btn-confirm-cancel').onclick = () => { App.closeModal(); resolve(false); };