From c4675f7a15f24dfa4985d71f20b60caf303c215c Mon Sep 17 00:00:00 2001 From: AskaEth Date: Sun, 26 Jul 2026 21:32:01 +0800 Subject: [PATCH] feat: persistent registration toast, click to dismiss --- static/js/pages/market.js | 2 +- static/js/utils/toast.js | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/static/js/pages/market.js b/static/js/pages/market.js index ee2bd78..7be221a 100644 --- a/static/js/pages/market.js +++ b/static/js/pages/market.js @@ -141,7 +141,7 @@ const PageMarket = { if (!email || !pass) { Toast.show('请输入邮箱和密码', 'error'); return; } const res = await fetch('/api/market/register', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({email, password: pass, passwordConfirm: pass, name}) }); const data = await res.json(); - Toast.show(data.error ? '注册失败' : '注册成功,请查收验证邮件', data.error ? 'error' : 'success'); + Toast.show(data.error ? '注册失败' : '注册成功,请查收验证邮件(点击关闭)', data.error ? 'error' : 'success', data.error ? 3000 : 0); if (!data.error) overlay.remove(); }); }, diff --git a/static/js/utils/toast.js b/static/js/utils/toast.js index 4f5c03e..152c174 100644 --- a/static/js/utils/toast.js +++ b/static/js/utils/toast.js @@ -13,14 +13,25 @@ const Toast = { const toast = document.createElement('div'); toast.className = `toast ${type}`; toast.textContent = message; + toast.style.cursor = 'pointer'; + toast.addEventListener('click', () => { + toast.style.opacity = '0'; + toast.style.transform = 'translateY(20px)'; + toast.style.transition = 'all 0.2s ease'; + setTimeout(() => toast.remove(), 200); + }); this._container.appendChild(toast); - setTimeout(() => { - toast.style.opacity = '0'; - toast.style.transform = 'translateX(100%)'; - toast.style.transition = 'all 0.3s ease'; - setTimeout(() => toast.remove(), 300); - }, duration); + if (duration > 0) { + setTimeout(() => { + if (toast.parentNode) { + toast.style.opacity = '0'; + toast.style.transform = 'translateY(20px)'; + toast.style.transition = 'all 0.3s ease'; + setTimeout(() => toast.remove(), 300); + } + }, duration); + } } };