/** * 数字人直播系统 - Toast 消息提示组件 */ (function() { 'use strict'; const Toast = { _animStyleAdded: false, _ensureAnimStyle() { if (this._animStyleAdded) return; const style = document.createElement('style'); style.textContent = ` @keyframes dhSlideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } } @keyframes dhSlideOutRight { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } } `; document.head.appendChild(style); this._animStyleAdded = true; }, show(message, type = 'info', duration = 3000) { this._ensureAnimStyle(); const colors = { success: '#4caf50', error: '#f44336', warning: '#ff9800', info: '#2196f3' }; const toast = document.createElement('div'); toast.style.cssText = ` position: fixed; top: 20px; right: 20px; padding: 14px 24px; background: ${colors[type] || colors.info}; color: white; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.2); z-index: 99999; font-size: 14px; max-width: 400px; word-break: break-word; animation: dhSlideInRight 0.3s ease-out; pointer-events: auto; `; toast.textContent = message; document.body.appendChild(toast); setTimeout(() => { toast.style.animation = 'dhSlideOutRight 0.3s ease-out'; setTimeout(() => toast.remove(), 300); }, duration); }, success(msg, duration) { this.show(msg, 'success', duration); }, error(msg, duration) { this.show(msg, 'error', duration); }, warning(msg, duration) { this.show(msg, 'warning', duration); }, info(msg, duration) { this.show(msg, 'info', duration); } }; window.DigitalHumanToast = Toast; console.log('[数字人直播] Toast组件已加载'); })();