using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.Options; using Volo.Abp.UI.Navigation; namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesign; public partial class MainMenu : IDisposable { [Inject] protected IMenuManager MenuManager { get; set; } [Inject] protected IOptions Options { get; set; } [Inject] protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } protected ApplicationMenu Menu { get; set; } protected override async Task OnInitializedAsync() { await GetMenuAsync(); AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged; } private async Task GetMenuAsync() { Menu = await MenuManager.GetMainMenuAsync(); } private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task task) { await GetMenuAsync(); await InvokeAsync(StateHasChanged); } public void Dispose() { AuthenticationStateProvider.AuthenticationStateChanged -= AuthenticationStateProviderOnAuthenticationStateChanged; } }