fix(#19,#22,#23): 动画取消reject替代resolve; config.style深拷贝; queue消息级duration/onClose优先

This commit is contained in:
tianhao
2026-06-16 12:52:03 +08:00
parent 56bac1fa0f
commit 093dcdebd8
2 changed files with 14 additions and 9 deletions
+11 -2
View File
@@ -79,6 +79,10 @@ class Toast {
this.html = opts.html || '';
this.iconHTML = opts.iconHTML || '';
this.config = { ...DEFAULTS, ...opts };
// 防止嵌套对象被多个 toast 实例共享引用
if (opts.style && typeof opts.style === 'object') {
this.config.style = { ...opts.style };
}
this.el = null;
this.barEl = null;
this.rafId = null;
@@ -991,13 +995,18 @@ const meToast = {
index++;
const msg = typeof message === 'string' ? message : (message?.message || '');
const msgObj = (typeof message === 'object' && message !== null) ? message : {};
const msgOnClose = msgObj.onClose;
this._emit({
...opts,
...((typeof message === 'object' && message !== null) ? message : {}),
...msgObj,
message: msg,
duration: opts.duration || 3000,
duration: msgObj.duration || opts.duration || 3000,
onClose: (toast) => {
if (typeof msgOnClose === 'function') {
try { msgOnClose(toast); } catch (_) {}
}
if (typeof userOnClose === 'function') {
try { userOnClose(toast); } catch (_) {}
}