Skip to content

Commit d5cbb73

Browse files
authored
feat(Message): support async update content use same option (#6040)
* doc: 更新示例 * feat: 支持保持相同消息 * doc: 更新本地化 * refactor: 优化性能 * refactor: 完善逻辑
1 parent ab6c3c1 commit d5cbb73

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

src/BootstrapBlazor.Server/Components/Samples/Messages.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ private MessageService? MessageService { get; set; }
2424
<Message @ref="Message" Placement="Placement.Bottom" />
2525
</DemoBlock>
2626

27+
<DemoBlock Title="@Localizer["MessagesAsyncTitle"]" Introduction="@Localizer["MessagesAsyncIntro"]" Name="Async">
28+
<Button IsAsync="true" OnClick="@ShowAsyncMessage" Text="@Localizer["MessagesAsyncText"]"></Button>
29+
</DemoBlock>
30+
2731
<DemoBlock Title="@Localizer["MessagesIconTitle"]" Introduction="@Localizer["MessagesIconIntro"]" Name="Icon">
2832
<button class="btn btn-primary" @onclick="@ShowIconMessage">@Localizer["MessagesMessagePrompt"]</button>
2933
</DemoBlock>

src/BootstrapBlazor.Server/Components/Samples/Messages.razor.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public sealed partial class Messages
1616
[NotNull]
1717
private Message? Message1 { get; set; }
1818

19+
private readonly MessageOption _option = new();
20+
1921
private async Task ShowMessage()
2022
{
2123
Message.SetPlacement(Placement.Top);
@@ -25,6 +27,28 @@ await MessageService.Show(new MessageOption()
2527
});
2628
}
2729

30+
private async Task ShowAsyncMessage()
31+
{
32+
_option.ForceDelay = true;
33+
_option.IsAutoHide = false;
34+
_option.Delay = 3000;
35+
_option.Content = Localizer["MessagesAsyncDemoStep1Text"];
36+
_option.Color = Color.Info;
37+
await MessageService.Show(_option);
38+
39+
await Task.Delay(3000);
40+
_option.Content = Localizer["MessagesAsyncDemoStep2Text"];
41+
_option.IsAutoHide = true;
42+
_option.Color = Color.Info;
43+
await MessageService.Show(_option);
44+
45+
await Task.Delay(2000);
46+
_option.Content = Localizer["MessagesAsyncDemoStep3Text"];
47+
_option.Color = Color.Success;
48+
49+
await MessageService.Show(_option);
50+
}
51+
2852
private async Task ShowIconMessage()
2953
{
3054
await MessageService.Show(new MessageOption()

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"ToastsPreventIntro": "By setting <code>PreventDuplicates=\"true\"</code> to repeatedly click the button below, only one pop-up window will appear",
126126
"ToastsPreventText": "Prevent Duplicates",
127127
"ToastsAsyncTitle": "Async notification",
128-
"ToastsAsyncIntro": "By setting <code>IsAsync</code>, the pop-up window is displayed, the thread is blocked, and after clicking the close button, the subsequent code continues to execute",
128+
"ToastsAsyncIntro": "By setting the button's <code>IsAsync</code> parameter, use the same <code>ToastOption</code> to update the pop-up window information for different steps",
129129
"ToastsAsyncDemoTitle": "Async notification",
130130
"ToastsAsyncDemoStep1Text": "Packing documents, please wait...",
131131
"ToastsAsyncDemoStep2Text": "Packaging completed, downloading...",
@@ -465,6 +465,12 @@
465465
"MessagesNormalTitle": "Basic usage",
466466
"MessagesNormalIntro": "Appears from the top and automatically disappears after 4 seconds",
467467
"MessagesMessagePrompt": "Open the message prompt",
468+
"MessagesAsyncTitle": "Async notification",
469+
"MessagesAsyncIntro": "By setting the button's <code>IsAsync</code> parameter, use the same <code>MessageOption</code> to update the pop-up window information for different steps",
470+
"MessagesAsyncDemoStep1Text": "Packing documents, please wait...",
471+
"MessagesAsyncDemoStep2Text": "Packaging completed, downloading...",
472+
"MessagesAsyncDemoStep3Text": "Download completed, close the window automatically",
473+
"MessagesAsyncText": "AsyncNotify",
468474
"MessagesIconTitle": "message box with icon",
469475
"MessagesIconIntro": "Change the small icon on the left side of the message box by setting the <code>Icon</code> property of <code>MessageOption</code>",
470476
"MessagesCloseButtonTitle": "message box with close button",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"ToastsPreventIntro": "通过设置 <code>PreventDuplicates=\"true\"</code> 重复点击下方按钮时,仅弹窗一次",
126126
"ToastsPreventText": "阻止重复",
127127
"ToastsAsyncTitle": "线程阻塞通知",
128-
"ToastsAsyncIntro": "通过设置 <code>IsAsync</code> 弹窗显示后,线程阻塞,点击关闭按钮后,继续执行后续代码",
128+
"ToastsAsyncIntro": "通过设置按钮 <code>IsAsync</code> 参数,使用同一个 <code>ToastOption</code> 更新弹窗信息提示不同步骤时的信息",
129129
"ToastsAsyncDemoTitle": "异步通知",
130130
"ToastsAsyncDemoStep1Text": "正在打包文档,请稍等...",
131131
"ToastsAsyncDemoStep2Text": "打包完成,正在下载...",
@@ -465,6 +465,12 @@
465465
"MessagesNormalTitle": "基础用法",
466466
"MessagesNormalIntro": "从顶部出现,4 秒后自动消失",
467467
"MessagesMessagePrompt": "打开消息提示",
468+
"MessagesAsyncTitle": "线程阻塞通知",
469+
"MessagesAsyncIntro": "通过设置按钮 <code>IsAsync</code> 参数,使用同一个 <code>MessageOption</code> 更新弹窗信息提示不同步骤时的信息",
470+
"MessagesAsyncDemoStep1Text": "正在打包文档,请稍等...",
471+
"MessagesAsyncDemoStep2Text": "打包完成,正在下载...",
472+
"MessagesAsyncDemoStep3Text": "下载完成,自动关窗",
473+
"MessagesAsyncText": "线程阻塞通知示例",
468474
"MessagesIconTitle": "带图标的消息框",
469475
"MessagesIconIntro": "通过设置 <code>MessageOption</code> 的 <code>Icon</code> 属性,更改消息框左侧小图标",
470476
"MessagesCloseButtonTitle": "带关闭按钮的消息框",

src/BootstrapBlazor/Components/Message/Message.razor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ private async Task Show(MessageOption option)
102102
_messages.Clear();
103103
}
104104

105-
_messages.Add(option);
106-
_msgId = GetItemId(option);
105+
if (!_messages.Contains(option))
106+
{
107+
_messages.Add(option);
108+
_msgId = GetItemId(option);
109+
}
107110
await InvokeAsync(StateHasChanged);
108111
}
109112

0 commit comments

Comments
 (0)