feat: 增加更新 DisplayName 逻辑

This commit is contained in:
Argo-Tianyi 2022-01-27 12:53:36 +08:00 committed by zhangpeihang
parent f748b69dfe
commit ce9cc849d4
4 changed files with 25 additions and 11 deletions

View File

@ -56,6 +56,10 @@ public partial class Profiles
[NotNull] [NotNull]
private string? DefaultLogoFolder { get; set; } private string? DefaultLogoFolder { get; set; }
[CascadingParameter]
[NotNull]
private Layout? Layout { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -109,8 +113,13 @@ public partial class Profiles
private async Task OnSaveDisplayName(EditContext context) private async Task OnSaveDisplayName(EditContext context)
{ {
var ret = UserService.SaveDisplayName(CurrentUser.DisplayName, CurrentUser.UserName); var ret = UserService.SaveDisplayName(CurrentUser.UserName, CurrentUser.DisplayName);
await ShowToast(ret, "显示名称"); await ShowToast(ret, "显示名称");
if (ret)
{
AppContext.DisplayName = CurrentUser.DisplayName;
await RenderLayout("displayName");
}
} }
private async Task OnSavePassword(EditContext context) private async Task OnSavePassword(EditContext context)
@ -177,4 +186,12 @@ public partial class Profiles
await ShowToast(ret, "用户头像", "删除"); await ShowToast(ret, "用户头像", "删除");
return ret; return ret;
} }
private async Task RenderLayout(string key)
{
if (Layout.OnUpdateAsync != null)
{
await Layout.OnUpdateAsync(key);
}
}
} }

View File

@ -180,9 +180,9 @@ public partial class Settings
private async Task RenderLayout(string key) private async Task RenderLayout(string key)
{ {
if (Layout.OnUpdate != null) if (Layout.OnUpdateAsync != null)
{ {
await Layout.OnUpdate(key); await Layout.OnUpdateAsync(key);
} }
} }
} }

View File

@ -3,10 +3,10 @@
<Layout SideWidth="0" IsPage="true" IsFullSide="true" IsFixedHeader="true" <Layout SideWidth="0" IsPage="true" IsFullSide="true" IsFixedHeader="true"
ShowFooter="true" ShowGotoTop="true" ShowCollapseBar="true" Menus="@MenuItems" ShowFooter="true" ShowGotoTop="true" ShowCollapseBar="true" Menus="@MenuItems"
OnAuthorizing="@OnAuthorizing" OnErrorHandleAsync="OnErrorHandleAsync" OnAuthorizing="@OnAuthorizing" OnErrorHandleAsync="OnErrorHandleAsync"
UseTabSet="true" TabDefaultUrl="/Admin/Index" OnUpdate="OnUpdate"> UseTabSet="true" TabDefaultUrl="/Admin/Index" OnUpdateAsync="OnUpdateAsync">
<Header> <Header>
<span class="ms-3 flex-fill">Bootstrap of Blazor</span> <span class="ms-3 flex-fill">Bootstrap of Blazor</span>
<Logout ImageUrl="@Icon" DisplayName="@DisplayName" UserName="@UserName"> <Logout ImageUrl="@Icon" DisplayName="@Context.DisplayName" UserName="@UserName">
<LinkTemplate> <LinkTemplate>
<a href="/Admin/Profiles"><i class="fa fa-suitcase"></i>个人中心</a> <a href="/Admin/Profiles"><i class="fa fa-suitcase"></i>个人中心</a>
<a href="/Admin/Index"><i class="fa fa-cog"></i>设置</a> <a href="/Admin/Index"><i class="fa fa-cog"></i>设置</a>
@ -26,7 +26,7 @@
<div class="layout-user"> <div class="layout-user">
<img class="layout-avatar" src="@Icon"> <img class="layout-avatar" src="@Icon">
<div class="layout-title"> <div class="layout-title">
<span>@DisplayName</span> <span>@Context.DisplayName</span>
</div> </div>
<div class="layout-user-state"></div> <div class="layout-user-state"></div>
</div> </div>

View File

@ -74,8 +74,6 @@ namespace BootstrapAdmin.Web.Shared
private string? Footer { get; set; } private string? Footer { get; set; }
private string? DisplayName { get; set; }
private string? UserName { get; set; } private string? UserName { get; set; }
private bool Lock { get; set; } private bool Lock { get; set; }
@ -133,9 +131,8 @@ namespace BootstrapAdmin.Web.Shared
if (!string.IsNullOrEmpty(UserName)) if (!string.IsNullOrEmpty(UserName))
{ {
var user = UsersService.GetUserByUserName(UserName); var user = UsersService.GetUserByUserName(UserName);
DisplayName = user?.DisplayName ?? "未注册账户";
Context.UserName = UserName; Context.UserName = UserName;
Context.DisplayName = DisplayName; Context.DisplayName = user?.DisplayName ?? "未注册账户"; ;
Icon = string.IsNullOrEmpty(user?.Icon) ? "/images/uploader/default.jpg" : GetIcon(user.Icon); Icon = string.IsNullOrEmpty(user?.Icon) ? "/images/uploader/default.jpg" : GetIcon(user.Icon);
MenuItems = NavigationsService.GetAllMenus(UserName).ToMenus(); MenuItems = NavigationsService.GetAllMenus(UserName).ToMenus();
@ -161,7 +158,7 @@ namespace BootstrapAdmin.Web.Shared
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public Task OnUpdate(string key) public Task OnUpdateAsync(string key)
{ {
if (key == "title") if (key == "title")
{ {