Skip to content

Commit 7287e74

Browse files
committed
doc: 更新示例
1 parent 65d85ce commit 7287e74

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
<DemoBlock Title="@Localizer["NormalTitle"]"
99
Introduction="@Localizer["NormalIntro"]"
1010
Name="Normal">
11-
<NetworkMonitor OnNetworkStateChanged="OnNetworkStateChanged"></NetworkMonitor>
12-
<section ignore>
13-
<ConsoleLogger @ref="_logger"></ConsoleLogger>
14-
</section>
15-
</DemoBlock>
16-
17-
<DemoBlock Title="@Localizer["IndicatorTitle"]"
18-
Introduction="@Localizer["IndicatorIntro"]"
19-
Name="Indicator">
2011
<section ignore>
2112
<ul class="ul-demo">
2213
<li>@Localizer["IndicatorLi1"]</li>
@@ -26,4 +17,7 @@
2617
</ul>
2718
</section>
2819
<NetworkMonitorIndicator></NetworkMonitorIndicator>
20+
<section ignore>
21+
<ConsoleLogger @ref="_logger"></ConsoleLogger>
22+
</section>
2923
</DemoBlock>

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,43 @@ namespace BootstrapBlazor.Server.Components.Samples;
88
/// <summary>
99
/// NetworkMonitor Sample code
1010
/// </summary>
11-
public partial class NetworkMonitors
11+
public partial class NetworkMonitors : IDisposable
1212
{
13+
[Inject, NotNull]
14+
private INetworkMonitorService? NetworkMonitorService { get; set; }
15+
1316
private ConsoleLogger _logger = null!;
1417

18+
/// <summary>
19+
/// <inheritdoc/>
20+
/// </summary>
21+
protected override async Task OnInitializedAsync()
22+
{
23+
await base.OnInitializedAsync();
24+
25+
await NetworkMonitorService.RegisterStateChangedCallback(this, OnNetworkStateChanged);
26+
}
27+
1528
private Task OnNetworkStateChanged(NetworkMonitorState state)
1629
{
17-
_logger.Log($"Online: {state.IsOnline} NetworkType: {state.NetworkType} Downlink: {state.Downlink} RTT: {state.RTT}");
30+
_logger.Log($"Online: NetworkType: {state.NetworkType} Downlink: {state.Downlink} RTT: {state.RTT}");
1831
return Task.CompletedTask;
1932
}
33+
34+
private void Dispose(bool disposing)
35+
{
36+
if (disposing)
37+
{
38+
NetworkMonitorService.UnregisterStateChangedCallback(this);
39+
}
40+
}
41+
42+
/// <summary>
43+
/// <inheritdoc/>
44+
/// </summary>
45+
public void Dispose()
46+
{
47+
Dispose(true);
48+
GC.SuppressFinalize(this);
49+
}
2050
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7123,14 +7123,12 @@
71237123
},
71247124
"BootstrapBlazor.Server.Components.Samples.NetworkMonitors": {
71257125
"NetworkMonitorTitle": "NetworkMonitor",
7126-
"NetworkMonitorDescription": "链路断开后自动重连示例",
7127-
"NormalTitle": "基本用法",
7128-
"NormalIntro": "通过设置 <code>IsAutoReconnect</code> 开启自动重连机制",
7129-
"IndicatorTitle": "网络状态指示灯",
7130-
"IndicatorIntro": "使用组件 <code>NetworkMonitorIndicator</code> 当网络状态变化时,显示不同颜色的指示灯,鼠标移动到上面时显示网络状态明细",
7131-
"IndicatorLi1": "绿色:网络非常好 (4G)",
7132-
"IndicatorLi2": "黄色:网络一般 (3G)",
7133-
"IndicatorLi3": "红色:网络差 (2G)",
7134-
"IndicatorLi4": "灰色:离线状态"
7126+
"NetworkMonitorDescription": "Use the browser native API <code>navigator.connection</code> to display the current network status in real time",
7127+
"NormalTitle": "Basic usage",
7128+
"NormalIntro": "Use the component <code>NetworkMonitorIndicator</code> to display indicator lights of different colors when the network status changes, and display the network status details when the mouse moves over it",
7129+
"IndicatorLi1": "Green: Very good network (4G)",
7130+
"IndicatorLi2": "Yellow: Average network (3G)",
7131+
"IndicatorLi3": "Red: Poor network (2G)",
7132+
"IndicatorLi4": "Gray: Offline"
71357133
}
71367134
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7125,9 +7125,7 @@
71257125
"NetworkMonitorTitle": "NetworkMonitor 网络状态",
71267126
"NetworkMonitorDescription": "使用浏览器原生 api <code>navigator.connection</code> 实时显示当前网络状态",
71277127
"NormalTitle": "基本用法",
7128-
"NormalIntro": "网络变化时,通过 <code>OnNetworkStateChanged</code> 回调获得当前网络状态信息",
7129-
"IndicatorTitle": "网络状态指示灯",
7130-
"IndicatorIntro": "使用组件 <code>NetworkMonitorIndicator</code> 当网络状态变化时,显示不同颜色的指示灯,鼠标移动到上面时显示网络状态明细",
7128+
"NormalIntro": "使用组件 <code>NetworkMonitorIndicator</code> 当网络状态变化时,显示不同颜色的指示灯,鼠标移动到上面时显示网络状态明细",
71317129
"IndicatorLi1": "绿色:网络非常好 (4G)",
71327130
"IndicatorLi2": "黄色:网络一般 (3G)",
71337131
"IndicatorLi3": "红色:网络差 (2G)",

0 commit comments

Comments
 (0)