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
+3 -7
View File
@@ -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`));
};
});
}
+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 (_) {}
}