mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-04 21:20:16 +08:00
!2406 doc(#I4T460): add dynamic update runtime feature on HemeLayout
* feat: 增加首页页脚计时器动态更新功能
This commit is contained in:
parent
cf3f3e25c9
commit
887b0cdb48
@ -1,4 +1,5 @@
|
||||
@inherits LayoutComponentBase
|
||||
@implements IDisposable
|
||||
@layout BaseLayout
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IJSRuntime JSRuntime
|
||||
@ -121,10 +122,10 @@
|
||||
|
||||
private string SelectedCulture { get; set; } = CultureInfo.CurrentUICulture.Name;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
private CancellationTokenSource DisposeTokenSource { get; } = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
if (OperatingSystem.IsBrowser())
|
||||
{
|
||||
BBVersion = typeof(BootstrapComponentBase).Assembly.GetName().Version?.ToString() ?? "";
|
||||
@ -151,6 +152,42 @@
|
||||
OS = "Unknown";
|
||||
}
|
||||
|
||||
UpdateRuntime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnAfterRenderAsync 方法
|
||||
/// </summary>
|
||||
/// <param name="firstRender"></param>
|
||||
/// <returns></returns>
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
while (!DisposeTokenSource.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000, DisposeTokenSource.Token);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
if (!DisposeTokenSource.IsCancellationRequested)
|
||||
{
|
||||
UpdateRuntime();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRuntime()
|
||||
{
|
||||
var ts = DateTimeOffset.Now - Cache.GetStartTime();
|
||||
Runtime = ts.ToString("dd\\.hh\\:mm\\:ss");
|
||||
}
|
||||
@ -183,4 +220,19 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
DisposeTokenSource.Cancel();
|
||||
DisposeTokenSource.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user