diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs index 4aa1fadc..f6a0352c 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Home/Index.cs @@ -22,6 +22,9 @@ Navigation.NavigateTo($"/Admin/Index", true); } #else + /// + /// + /// protected override void OnInitialized() { Navigation.NavigateTo($"/Admin/Index", true); diff --git a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor index 313d33b3..d5c84ae4 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor @@ -1,37 +1,40 @@ @inherits LayoutComponentBase - -
- Bootstrap of Blazor - - @DisplayName -
-
- -
- -
- @Title +
+ Bootstrap of Blazor + + @DisplayName +
+
+ +
+ +
+ @Title +
-
-
- -
- @DisplayName +
+ +
+ @DisplayName +
+
-
-
- -
- @Body -
-
-
@Footer
-
- - - - + +
+ @Body +
+
+
@Footer
+
+ + + + +} \ No newline at end of file diff --git a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs index 73956421..e00be754 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs @@ -33,10 +33,6 @@ namespace BootstrapAdmin.Web.Shared [NotNull] private BootstrapAppContext? Context { get; set; } - [Inject] - [NotNull] - private NavigationManager? Navigation { get; set; } - [Inject] [NotNull] private IBootstrapAdminService? SecurityService { get; set; } @@ -47,30 +43,30 @@ namespace BootstrapAdmin.Web.Shared private string? DisplayName { get; set; } - /// - /// - /// - protected override void OnInitialized() - { - base.OnInitialized(); - - MenuItems = NavigationsService.GetAllMenus("Admin").ToAdminMenus(); - - Title = DictsService.GetWebTitle(); - Footer = DictsService.GetWebFooter(); - } + private bool Login { get; set; } /// - /// + /// OnInitializedAsync 方法 /// /// protected override async Task OnInitializedAsync() { var state = await AuthenticationStateProvider.GetAuthenticationStateAsync(); var userName = state.User.Identity?.Name; - DisplayName = UsersService.GetDisplayName(userName); - Context.UserName = userName; - Context.DisplayName = DisplayName; + + if (!string.IsNullOrEmpty(userName)) + { + DisplayName = UsersService.GetDisplayName(userName); + Context.UserName = userName; + Context.DisplayName = DisplayName; + + MenuItems = NavigationsService.GetAllMenus("Admin").ToAdminMenus(); + } + + Title = DictsService.GetWebTitle(); + Footer = DictsService.GetWebFooter(); + + Login = true; } private Task OnAuthorizing(string url) => SecurityService.AuhorizingNavigation(Context.UserName, url);