diff --git a/src/core.js b/src/core.js index d679700..67747b2 100644 --- a/src/core.js +++ b/src/core.js @@ -246,6 +246,13 @@ class Toast { } _buildContent(el, c) { + // 自定义渲染函数 — 完全接管 DOM 构建 + if (typeof this.config.render === 'function') { + el.innerHTML = this.config.render(this); + this.barEl = el.querySelector('.met-bar, .met-bar-v'); + return; + } + const showIcon = this.config.icon !== false && (this.iconHTML || ICONS[this.type]); const showClose = this.config.closeButton !== false; const showProgress = this.config.showProgress !== false && this.config.duration > 0; diff --git a/src/index.js b/src/index.js index 9fe789d..71b4824 100644 --- a/src/index.js +++ b/src/index.js @@ -257,6 +257,18 @@ if (typeof window !== 'undefined') { window.MeToast = enhancedMeToast; window.Met = enhancedMeToast; window.metonaToast = enhancedMeToast; + + // Notification API — 页面不可见时自动发送系统通知 + enhancedMeToast._notify = (toast) => { + if (typeof Notification === 'undefined' || Notification.permission !== 'granted') return; + if (!document.hidden) return; + try { + new Notification(toast.title || toast.type, { body: toast.message, icon: '/favicon.ico' }); + } catch (_) {} + }; + Toast.on('afterShow', (toast) => { + if (toast.config.notifyWhenHidden) enhancedMeToast._notify(toast); + }); } // 导出