Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit de0f264

Browse files
authored
【新增】使用 INotificationService 动态调用 TNotification 组件显示消息通知 (#155)
2 parents 0373342 + 4fe1c08 commit de0f264

26 files changed

Lines changed: 519 additions & 209 deletions

doc/TDesign.Docs.Shared/Pages/Components/MessagePage.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<Example Title="通过服务调用">
6262
<Description>注入 <code>IMessageService</code> 接口动态调用消息</Description>
6363
<RunContent>
64-
<TButton OnClick="@(e=>MessageService.Show(new MessageConfiguration{ Content="这是全局提示"}))">自定义提示</TButton>
64+
<TButton OnClick="@(e=>MessageService.Show(new (){ Content="这是全局提示"}))">自定义提示</TButton>
6565
<TButton Theme="Theme.Primary" OnClick="@(e=>MessageService.Info("普通的提示"))">普通</TButton>
6666
<TButton Theme="Theme.Success" OnClick="@(e=>MessageService.Success("成功的提示"))">成功</TButton>
6767
<TButton Theme="Theme.Warning" OnClick="@(e=>MessageService.Warning("警告的提示"))">警告</TButton>

doc/TDesign.Docs.Shared/Pages/Components/NotificationPage.razor

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,13 @@
8484
</OperationContent>
8585
</TNotification>
8686
<br/>
87-
<TNotification Theme="Theme.Warning">
88-
<TitleContent>
89-
消息通知 <small>这里是副标题</small>
90-
</TitleContent>
87+
<TNotification Theme="Theme.Warning" Title="消息通知" SubTitle="这里是副标题">
9188
<ChildContent>
9289
1. 使用插槽自定义标题 2. 使用插槽自定义底部内容
9390
</ChildContent>
9491
<OperationContent>
95-
<TButton Type="ButtonVarient.Text">取消</TButton>
96-
<TButton Theme="Theme.Primary" Type="ButtonVarient.Text">稍后提醒我(10s)</TButton>
92+
<TButton Varient="ButtonVarient.Text">取消</TButton>
93+
<TButton Theme="Theme.Primary" Varient="ButtonVarient.Text">稍后提醒我(10s)</TButton>
9794
</OperationContent>
9895
</TNotification>
9996
</RunContent>
@@ -111,22 +108,41 @@
111108
</OperationContent>
112109
</TNotification>
113110

114-
<TNotification Theme=""Theme.Warning"">
115-
<TitleContent>
116-
消息通知 <small>这里是副标题</small>
117-
</TitleContent>
111+
<TNotification Theme=""Theme.Warning"" Title=""消息通知"" SubTitle=""这里是副标题"">
118112
<ChildContent>
119113
1. 使用插槽自定义标题 2. 使用插槽自定义底部内容
120114
</ChildContent>
121115
<OperationContent>
122-
<TButton Type=""ButtonType.Text"">取消</TButton>
123-
<TButton Theme=""Theme.Primary"" Type=""ButtonType.Text"">稍后提醒我(10s)</TButton>
116+
<TButton Varient=""ButtonType.Text"">取消</TButton>
117+
<TButton Theme=""Theme.Primary"" Varient=""ButtonType.Text"">稍后提醒我(10s)</TButton>
124118
</OperationContent>
125119
</TNotification>
126120
```
127121
")
128122
</CodeContent>
129123
</Example>
130124

131-
<h2>通过服务调用</h2>
132-
代码建设中...
125+
126+
<Example Title="通过服务调用">
127+
<Description>注入 <code>INotificationService</code> 接口动态调用消息</Description>
128+
<RunContent>
129+
<TButton OnClick="@(e=>NotificationService.Show(new (){ Content="这是全局提示"}))">自定义提示</TButton>
130+
<TButton Theme="Theme.Primary" OnClick="@(e=>NotificationService.Info("普通的提示","消息通知"))">普通</TButton>
131+
<TButton Theme="Theme.Success" OnClick="@(e=>NotificationService.Success("成功的提示","消息通知"))">成功</TButton>
132+
<TButton Theme="Theme.Warning" OnClick="@(e=>NotificationService.Warning("警告的提示","消息通知"))">警告</TButton>
133+
<TButton Theme="Theme.Danger" OnClick="@(e=>NotificationService.Danger("失败的提示","消息通知"))">失败</TButton>
134+
</RunContent>
135+
<CodeContent>
136+
@Code.Create(@"
137+
```cs
138+
@inject INotificationService NotificationService
139+
140+
NotificationService.Info(...)
141+
NotificationService.Success(...)
142+
NotificationService.Danger(...)
143+
NotificationService.Warning(...)
144+
```
145+
")
146+
</CodeContent>
147+
</Example>
148+
@inject INotificationService NotificationService
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace TDesign.Abstractions;
2+
/// <summary>
3+
/// 表示实现该接口的组件会被自动作为容器加入。该接口用于动态服务调用时组件所需要的容器组件。
4+
/// </summary>
5+
public interface IContainerComonent : IComponent
6+
{
7+
}

src/TDesign/Components/Messages/IMessageService.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/TDesign/Components/Messages/MessageService.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/TDesign/Components/Messages/TMessageContainer.cs

Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace TDesign.Notification;
2+
/// <summary>
3+
/// 提供可以弹出通知提示的服务。
4+
/// </summary>
5+
/// <typeparam name="TConfiguration">配置的类型。</typeparam>
6+
public interface INotifyService<TConfiguration> where TConfiguration : NotifyConfigurationBase
7+
{
8+
/// <summary>
9+
/// 显示指定消息配置的全局提示。
10+
/// </summary>
11+
/// <param name="configuration">消息服务的配置。</param>
12+
Task? Show(TConfiguration configuration);
13+
/// <summary>
14+
/// 当消息被关闭后时触发的事件。
15+
/// </summary>
16+
event Action? OnClosed;
17+
/// <summary>
18+
/// 当消息正在显示时触发的事件。
19+
/// </summary>
20+
21+
event Func<TConfiguration, Task>? OnShowing;
22+
}

src/TDesign/Abstractions/MessageComponentBase.cs renamed to src/TDesign/Components/Notify/Abstractions/NotifyComponentBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
namespace TDesign;
1+
namespace TDesign.Notification;
22
/// <summary>
33
/// 消息组件的基类。
44
/// </summary>
5-
public abstract class MessageComponentBase : BlazorComponentBase, IHasChildContent
5+
public abstract class NotifyComponentBase : BlazorComponentBase, IHasChildContent
66
{
77
/// <summary>
88
/// <inheritdoc/>

src/TDesign/Components/Messages/MessageConfiguration.cs renamed to src/TDesign/Components/Notify/Abstractions/NotifyConfigurationBase.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
1-
namespace TDesign;
2-
3-
/// <summary>
4-
/// 表示全局消息的配置。
5-
/// </summary>
6-
/// <remarks>该对象用于 <see cref="IMessageService"/> 调用时传值给 <see cref="TMessage"/> 组件。</remarks>
7-
public class MessageConfiguration
1+
namespace TDesign.Notification;
2+
public abstract class NotifyConfigurationBase
83
{
9-
internal Guid Key => Guid.NewGuid();
104
/// <summary>
11-
/// 获取或设置消息提示的内容文本字符串。
5+
/// Gets the key.
126
/// </summary>
13-
public string? Content { get; set; }
7+
internal Guid Key => Guid.NewGuid();
148
/// <summary>
15-
/// 获取或设置消息提示的图标
9+
/// 获取或设置内容文本字符串
1610
/// </summary>
17-
public object? Icon { get; set; }
11+
public string? Content { get; set; }
1812
/// <summary>
19-
/// 获取或设置消息提示的主题风格
13+
/// 获取或设置主题风格
2014
/// </summary>
2115
public Theme Theme { get; set; } = Theme.Primary;
22-
2316
/// <summary>
24-
/// 获取或设置消息提示具备加载中的状态
17+
/// 获取或设置消息持续多久自动关闭,单位是毫秒,默认 5 秒,即 5000 毫秒
2518
/// </summary>
26-
public bool Loading { get; set; }
27-
/// <summary>
28-
/// 获取或设置消息提示可以被用户关闭。
29-
/// </summary>
30-
public bool Closable { get; set; }
31-
19+
public int? Delay { get; set; } = 3000;
3220
/// <summary>
33-
/// 获取或设置消息提示持续多久自动关闭,单位是毫秒,默认 5 秒,即 5000 毫秒
21+
/// 获取或设置消息提示的图标
3422
/// </summary>
35-
public int? Delay { get; set; } = 3000;
23+
public object? Icon { get; set; }
3624

3725
/// <summary>
3826
/// 获取或设置显示的位置。

0 commit comments

Comments
 (0)