From 093dcdebd86fb4094f49e18f697bdb6dc20b9c78 Mon Sep 17 00:00:00 2001 From: tianhao Date: Tue, 16 Jun 2026 12:52:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(#19,#22,#23):=20=E5=8A=A8=E7=94=BB=E5=8F=96?= =?UTF-8?q?=E6=B6=88reject=E6=9B=BF=E4=BB=A3resolve;=20config.style?= =?UTF-8?q?=E6=B7=B1=E6=8B=B7=E8=B4=9D;=20queue=E6=B6=88=E6=81=AF=E7=BA=A7?= =?UTF-8?q?duration/onClose=E4=BC=98=E5=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/animations.js | 10 +++------- src/core.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/animations.js b/src/animations.js index 9a0196f..9eae7fc 100644 --- a/src/animations.js +++ b/src/animations.js @@ -80,7 +80,7 @@ class AnimationManager { * @returns {Promise} 动画完成Promise */ apply(element, animationName, options = {}) { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { const animation = this.get(animationName); if (!animation) { resolve(); @@ -123,19 +123,15 @@ class AnimationManager { // 动画完成处理 anim.onfinish = () => { - // 应用最终状态 Object.assign(element.style, config.leave); - - // 清理 this.activeAnimations.delete(animId); - resolve(); }; - // 动画取消处理 + // 动画取消处理 — reject 让调用者感知取消 anim.oncancel = () => { this.activeAnimations.delete(animId); - resolve(); + reject(new Error(`Animation "${animationName}" was cancelled`)); }; }); } diff --git a/src/core.js b/src/core.js index 6d0220d..c1eda5d 100644 --- a/src/core.js +++ b/src/core.js @@ -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 (_) {} }