diff --git a/js/app.js b/js/app.js index 06abafd..c4c524c 100644 --- a/js/app.js +++ b/js/app.js @@ -3,6 +3,36 @@ // ============================================================ let currentUser = null; +function showToast(message, type = 'success', duration = 3000) { + // 移除已有 toast + const existing = document.querySelector('.toast'); + if (existing) existing.remove(); + + const toast = document.createElement('div'); + toast.className = 'toast ' + type; + + const icons = { + success: ``, + error: ``, + warning: `` + }; + + toast.innerHTML = ` + ${icons[type] || icons.success} + ${message} + `; + + document.body.appendChild(toast); + + requestAnimationFrame(() => { + toast.classList.add('show'); + }); + + setTimeout(() => { + toast.classList.remove('show'); + setTimeout(() => toast.remove(), 400); + }, duration); +} let currentPage = 'feed'; let currentPageNum = 1;