From 23745952e5216c37e392532e7eaa8ffabc027fc7 Mon Sep 17 00:00:00 2001 From: tianhao Date: Tue, 16 Jun 2026 13:02:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Notification=20API=20+=20=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=B8=B2=E6=9F=93=E5=87=BD=E6=95=B0=20+=20st?= =?UTF-8?q?ack=E7=8B=AC=E7=AB=8B=E9=85=8D=E7=BD=AE=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.js | 7 +++++++ src/index.js | 12 ++++++++++++ 2 files changed, 19 insertions(+) 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); + }); } // 导出