feat: Notification API + 自定义渲染函数 + stack独立配置完善
This commit is contained in:
@@ -246,6 +246,13 @@ class Toast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildContent(el, c) {
|
_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 showIcon = this.config.icon !== false && (this.iconHTML || ICONS[this.type]);
|
||||||
const showClose = this.config.closeButton !== false;
|
const showClose = this.config.closeButton !== false;
|
||||||
const showProgress = this.config.showProgress !== false && this.config.duration > 0;
|
const showProgress = this.config.showProgress !== false && this.config.duration > 0;
|
||||||
|
|||||||
@@ -257,6 +257,18 @@ if (typeof window !== 'undefined') {
|
|||||||
window.MeToast = enhancedMeToast;
|
window.MeToast = enhancedMeToast;
|
||||||
window.Met = enhancedMeToast;
|
window.Met = enhancedMeToast;
|
||||||
window.metonaToast = 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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
|
|||||||
Reference in New Issue
Block a user