dtable-ui-component 6.0.95-beta.1 → 6.0.95-beta.2
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 +0 -1
- package/lib/toaster/toaster.js +15 -0
- package/package.json +1 -1
package/lib/toaster/index.js
CHANGED
package/lib/toaster/toaster.js
CHANGED
|
@@ -20,6 +20,8 @@ class Toaster {
|
|
|
20
20
|
constructor() {
|
|
21
21
|
var _this = this;
|
|
22
22
|
this._bindNotify = handler => {
|
|
23
|
+
// 在绑定通知处理器时,确保只有一个容器
|
|
24
|
+
this._ensureSingleContainer();
|
|
23
25
|
this.notifyHandler = handler;
|
|
24
26
|
};
|
|
25
27
|
this._bindGetToasts = handler => {
|
|
@@ -94,6 +96,19 @@ class Toaster {
|
|
|
94
96
|
}
|
|
95
97
|
});
|
|
96
98
|
}
|
|
99
|
+
// 确保 DOM 中只有一个 toaster 容器
|
|
100
|
+
_ensureSingleContainer() {
|
|
101
|
+
const containers = document.querySelectorAll('[data-evergreen-toaster-container]');
|
|
102
|
+
if (containers.length > 1) {
|
|
103
|
+
// 保留第一个容器(我们的实例),删除其他的
|
|
104
|
+
for (let i = 1; i < containers.length; i++) {
|
|
105
|
+
const container = containers[i];
|
|
106
|
+
if (container.parentNode) {
|
|
107
|
+
container.parentNode.removeChild(container);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
97
112
|
}
|
|
98
113
|
exports.default = Toaster;
|
|
99
114
|
Toaster.instance = null;
|