(message, type = 'info', duration = 4000)
| 20 | } |
| 21 | |
| 22 | show(message, type = 'info', duration = 4000) { |
| 23 | const toast = document.createElement('div'); |
| 24 | toast.className = `toast ${type}`; |
| 25 | |
| 26 | const icon = this.getIcon(type); |
| 27 | toast.innerHTML = ` |
| 28 | <span class="toast-icon">${icon}</span> |
| 29 | <span class="toast-message">${this.escapeHtml(message)}</span> |
| 30 | <button class="toast-close" onclick="this.parentElement.remove()">×</button> |
| 31 | `; |
| 32 | |
| 33 | this.container.appendChild(toast); |
| 34 | |
| 35 | // 自动移除 |
| 36 | setTimeout(() => { |
| 37 | toast.style.animation = 'slideOut 0.3s ease forwards'; |
| 38 | setTimeout(() => toast.remove(), 300); |
| 39 | }, duration); |
| 40 | |
| 41 | return toast; |
| 42 | } |
| 43 | |
| 44 | getIcon(type) { |
| 45 | const icons = { |
no test coverage detected