|
|
|
@ -1,8 +1,11 @@ |
|
|
|
using System; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using JetBrains.Annotations; |
|
|
|
using Microsoft.AspNetCore.Components; |
|
|
|
using Microsoft.AspNetCore.Components.Authorization; |
|
|
|
using Microsoft.AspNetCore.Components.Routing; |
|
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Authentication; |
|
|
|
using Microsoft.JSInterop; |
|
|
|
using Volo.Abp.UI.Navigation; |
|
|
|
|
|
|
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic |
|
|
|
@ -11,23 +14,32 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic |
|
|
|
{ |
|
|
|
[Inject] |
|
|
|
protected IMenuManager MenuManager { get; set; } |
|
|
|
|
|
|
|
[Inject] |
|
|
|
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } |
|
|
|
|
|
|
|
protected ApplicationMenu Menu { get; set; } |
|
|
|
[CanBeNull] |
|
|
|
protected AuthenticationStateProvider AuthenticationStateProvider; |
|
|
|
|
|
|
|
[CanBeNull] |
|
|
|
protected SignOutSessionStateManager SignOutManager; |
|
|
|
|
|
|
|
protected ApplicationMenu Menu { get; set; } |
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync() |
|
|
|
{ |
|
|
|
Menu = await MenuManager.GetAsync(StandardMenus.User); |
|
|
|
|
|
|
|
Navigation.LocationChanged += OnLocationChanged; |
|
|
|
|
|
|
|
AuthenticationStateProvider.AuthenticationStateChanged += async (task) => |
|
|
|
LazyGetService(ref AuthenticationStateProvider); |
|
|
|
LazyGetService(ref SignOutManager); |
|
|
|
|
|
|
|
if (AuthenticationStateProvider != null) |
|
|
|
{ |
|
|
|
Menu = await MenuManager.GetAsync(StandardMenus.User); |
|
|
|
await InvokeAsync(StateHasChanged); |
|
|
|
}; |
|
|
|
AuthenticationStateProvider.AuthenticationStateChanged += async (task) => |
|
|
|
{ |
|
|
|
Menu = await MenuManager.GetAsync(StandardMenus.User); |
|
|
|
await InvokeAsync(StateHasChanged); |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e) |
|
|
|
@ -39,5 +51,26 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic |
|
|
|
{ |
|
|
|
Navigation.LocationChanged -= OnLocationChanged; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task NavigateToAsync(string uri, string target = null) |
|
|
|
{ |
|
|
|
if (target == "_blank") |
|
|
|
{ |
|
|
|
await JsRuntime.InvokeVoidAsync("open", uri, target); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Navigation.NavigateTo(uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task BeginSignOut() |
|
|
|
{ |
|
|
|
if (SignOutManager != null) |
|
|
|
{ |
|
|
|
await SignOutManager.SetSignOutState(); |
|
|
|
await NavigateToAsync("authentication/logout"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|