Skip to content

Commit f6723c0

Browse files
committed
fix: 防止多次添加相同 Id
1 parent 7e7d6f2 commit f6723c0

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/BootstrapBlazor/Components/Message/Message.razor.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ export function show(id, msgId) {
1515
}
1616

1717
const msgItem = { el, animationId: null }
18-
msg.items.push(msgItem)
19-
const autoHide = el.getAttribute('data-bb-autohide') === 'true';
18+
if (msg.items.find(i => i.el.id === msgId) === void 0) {
19+
msg.items.push(msgItem)
20+
}
2021

22+
const autoHide = el.getAttribute('data-bb-autohide') === 'true';
2123
if (autoHide) {
22-
// auto close
2324
const delay = parseInt(el.getAttribute('data-bb-delay'));
2425
let start = void 0
2526
const autoCloseAnimation = ts => {
@@ -45,10 +46,8 @@ export function show(id, msgId) {
4546
const hideHandler = setTimeout(function () {
4647
clearTimeout(hideHandler);
4748

48-
// remove Id
4949
msg.items.pop();
5050
if (msg.items.length === 0) {
51-
// call server method prepare remove dom
5251
msg.invoke.invokeMethodAsync(msg.callback);
5352
}
5453
}, 500);
@@ -58,9 +57,8 @@ export function show(id, msgId) {
5857
e.preventDefault();
5958
e.stopPropagation();
6059

61-
// trigger on-dismiss event callback
6260
const alert = e.delegateTarget.closest('.alert');
63-
if(alert) {
61+
if (alert) {
6462
const alertId = alert.getAttribute('id');
6563
msg.invoke.invokeMethodAsync('Dismiss', alertId);
6664
}

0 commit comments

Comments
 (0)