dtable-ui-component 6.0.93 → 6.0.95-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/toaster/index.js +1 -0
- package/lib/toaster/toaster.js +23 -3
- package/package.json +1 -1
package/lib/toaster/index.js
CHANGED
package/lib/toaster/toaster.js
CHANGED
|
@@ -63,8 +63,14 @@ class Toaster {
|
|
|
63
63
|
});
|
|
64
64
|
};
|
|
65
65
|
if (!isBrowser) return;
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
|
|
67
|
+
// 单例模式:如果已经存在实例,直接返回
|
|
68
|
+
if (Toaster.instance) {
|
|
69
|
+
return Toaster.instance;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 清理可能存在的旧容器
|
|
73
|
+
this._cleanupOldContainers();
|
|
68
74
|
const container = document.createElement('div');
|
|
69
75
|
container.setAttribute('data-evergreen-toaster-container', '');
|
|
70
76
|
document.body.appendChild(container);
|
|
@@ -74,6 +80,20 @@ class Toaster {
|
|
|
74
80
|
bindGetToasts: this._bindGetToasts,
|
|
75
81
|
bindCloseAll: this._bindCloseAll
|
|
76
82
|
}));
|
|
83
|
+
|
|
84
|
+
// 保存实例引用
|
|
85
|
+
Toaster.instance = this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 清理旧的 toaster 容器
|
|
89
|
+
_cleanupOldContainers() {
|
|
90
|
+
const oldContainers = document.querySelectorAll('[data-evergreen-toaster-container]');
|
|
91
|
+
oldContainers.forEach(container => {
|
|
92
|
+
if (container.parentNode) {
|
|
93
|
+
container.parentNode.removeChild(container);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
77
96
|
}
|
|
78
97
|
}
|
|
79
|
-
exports.default = Toaster;
|
|
98
|
+
exports.default = Toaster;
|
|
99
|
+
Toaster.instance = null;
|