refactor: 个人中心保存用户显示名称
This commit is contained in:
parent
81948f4693
commit
0c49b3ebbf
|
@ -64,6 +64,16 @@ namespace Bootstrap.Admin.Components
|
|||
/// </summary>
|
||||
protected string RequestUrl { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Header 组件引用实例
|
||||
/// </summary>
|
||||
protected Header? Header { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SideBar 组件引用实例
|
||||
/// </summary>
|
||||
protected SideBar? SideBar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OnInitializedAsync 方法
|
||||
/// </summary>
|
||||
|
@ -77,11 +87,8 @@ namespace Bootstrap.Admin.Components
|
|||
}
|
||||
else
|
||||
{
|
||||
RequestUrl = new UriBuilder(NavigationManager?.Uri ?? "").Path;
|
||||
Model = new NavigatorBarModel(state.User.Identity.Name, RequestUrl.ToMvcMenuUrl());
|
||||
IsAdmin = state.User.IsInRole("Administrators");
|
||||
UserName = state.User.Identity.Name ?? "";
|
||||
DisplayName = Model.DisplayName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +99,17 @@ namespace Bootstrap.Admin.Components
|
|||
{
|
||||
RequestUrl = new UriBuilder(NavigationManager?.Uri ?? "").Path;
|
||||
Model = new NavigatorBarModel(UserName, RequestUrl.ToMvcMenuUrl());
|
||||
DisplayName = Model.DisplayName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void OnDisplayNameChanged(string displayName)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Header?.UpdateDisplayName();
|
||||
SideBar?.UpdateDisplayName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -8,24 +8,6 @@ namespace Bootstrap.Admin.Components
|
|||
/// </summary>
|
||||
public class HeaderBase : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string UserName { get; set; } = "未设置";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string DisplayName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<string>? DisplayNameChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -38,6 +20,12 @@ namespace Bootstrap.Admin.Components
|
|||
[Parameter]
|
||||
public string Title { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -47,14 +35,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
/// <summary>
|
||||
/// 更新登录用户显示名称方法
|
||||
/// </summary>
|
||||
/// <param name="displayName"></param>
|
||||
public void UpdateDisplayName(string displayName)
|
||||
public void UpdateDisplayName()
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
|
|
|
@ -26,5 +26,13 @@ namespace Bootstrap.Admin.Components
|
|||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void UpdateDisplayName()
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Models
|
|||
/// <param name="activeUrl"></param>
|
||||
public NavigatorBarModel(string? userName, string activeUrl = "") : base(userName)
|
||||
{
|
||||
Navigations = MenuHelper.RetrieveSystemMenus(userName, activeUrl);
|
||||
Navigations = MenuHelper.RetrieveSystemMenus(userName ?? "", activeUrl);
|
||||
var authApps = AppHelper.RetrievesByUserName(userName);
|
||||
Applications = string.IsNullOrEmpty(userName) ? new KeyValuePair<string, string>[0] : DictHelper.RetrieveApps().Where(app => app.Key.IsNullOrEmpty() || authApps.Any(key => key.Equals(app.Key, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="card" asp-auth="saveDisplayName">
|
||||
<div class="card-header">基本资料</div>
|
||||
<div class="card-body" data-toggle="LgbValidate" data-valid-button="#btnSaveDisplayName">
|
||||
@if (IsDemo)
|
||||
@if (!(Model?.IsDemo ?? false))
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<span>演示系统禁止更改管理员显示名称</span>
|
||||
|
@ -15,11 +15,11 @@
|
|||
</div>
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="DisplayName">显示名称</label>
|
||||
<input type="text" class="form-control" @bind="RootLayout.DisplayName" placeholder="不可为空,20字以内" maxlength="20" data-valid="true" />
|
||||
<input type="text" class="form-control" @bind="@DisplayName" placeholder="不可为空,20字以内" maxlength="20" data-valid="true" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@if (!IsDemo)
|
||||
@if (!(Model?.IsDemo ?? false))
|
||||
{
|
||||
<div class="modal-footer">
|
||||
<button id="btnSaveDisplayName" data-method="user" class="btn btn-secondary" type="button" @onclick="SaveDisplayName"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
|
@ -30,9 +30,12 @@
|
|||
<div class="card" asp-auth="savePassword" asp-condition="!@Model?.External">
|
||||
<div class="card-header">修改密码</div>
|
||||
<div class="card-body" data-toggle="LgbValidate" data-valid-button="#btnSavePassword">
|
||||
<div class="alert alert-danger" role="alert" asp-condition="@Model?.IsDemo">
|
||||
<span>演示系统禁止更改管理员密码</span>
|
||||
</div>
|
||||
@if (!(Model?.IsDemo ?? false))
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<span>演示系统禁止更改管理员密码</span>
|
||||
</div>
|
||||
}
|
||||
<form class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
|
@ -51,9 +54,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="modal-footer" asp-condition="!@Model?.IsDemo">
|
||||
<button id="btnSavePassword" data-method="password" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
</div>
|
||||
@if (!(Model?.IsDemo ?? false))
|
||||
{
|
||||
<div class="modal-footer">
|
||||
<button id="btnSavePassword" data-method="password" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" asp-auth="saveApp">
|
||||
|
@ -117,21 +123,24 @@
|
|||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
private ProfilesModel? Model;
|
||||
private bool IsDemo;
|
||||
protected ProfilesModel? Model { get; set; }
|
||||
|
||||
protected string DisplayName { get; set; } = "";
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
Model = new ProfilesModel(RootLayout.UserName);
|
||||
IsDemo = Model?.IsDemo ?? false;
|
||||
DisplayName = Model.DisplayName;
|
||||
}
|
||||
|
||||
private void SaveDisplayName()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Model?.UserName) && !string.IsNullOrEmpty(RootLayout.DisplayName))
|
||||
if (!string.IsNullOrEmpty(Model?.UserName) && !string.IsNullOrEmpty(DisplayName))
|
||||
{
|
||||
Bootstrap.DataAccess.UserHelper.SaveDisplayName(Model.UserName, RootLayout.DisplayName);
|
||||
if (Bootstrap.DataAccess.UserHelper.SaveDisplayName(Model.UserName, DisplayName))
|
||||
{
|
||||
RootLayout.OnDisplayNameChanged(DisplayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
@inherits DefaultLayoutComponentBase
|
||||
|
||||
<CascadingValue Value=this Name="Default">
|
||||
<Header Icon="@Model.Icon" Title="@Model.Title" IsAdmin=@IsAdmin UserName="@Model.UserName" @bind-DisplayName="@DisplayName"></Header>
|
||||
<SideBar @bind-Model=@Model />
|
||||
<Header @ref="Header" Icon="@Model.Icon" Title="@Model.Title" IsAdmin=@IsAdmin UserName="@UserName" HomeUrl="@HomeUrl" DisplayName="@DisplayName" />
|
||||
<SideBar @ref="SideBar" Model=@Model />
|
||||
@Body
|
||||
<Footer Text="@Model.Footer" IsDemo=@Model.IsDemo></Footer>
|
||||
</CascadingValue>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<header class="header">
|
||||
<div class="bg"></div>
|
||||
<div class="d-flex align-items-center">
|
||||
<a id="navbar" href="@RootLayout.HomeUrl" class="sidebar-toggle-box">
|
||||
<a id="navbar" href="@HomeUrl" class="sidebar-toggle-box">
|
||||
<i class="fa fa-bars"></i>
|
||||
<span id="websiteTitle">@Title</span>
|
||||
</a>
|
||||
|
@ -94,15 +94,15 @@
|
|||
</div>
|
||||
<div class="dropdown userinfo">
|
||||
<div data-toggle="dropdown" class="dropdown-toggle shadow-default">
|
||||
<img id="headerIcon" alt="" src="@Icon.ToBlazorLink()" />
|
||||
<span id="userDisplayName" data-userName="@UserName" class="username text-truncate d-inline-block">@DisplayName</span>
|
||||
<img alt="" src="@Icon.ToBlazorLink()" />
|
||||
<span class="username text-truncate d-inline-block">@RootLayout.DisplayName</span>
|
||||
</div>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<div class="dropdown-item">
|
||||
<div class="d-flex flex-fill align-items-center">
|
||||
<img src="@Icon.ToBlazorLink()">
|
||||
<div class="flex-fill">
|
||||
<div class="username text-truncate">@DisplayName</div>
|
||||
<div class="username text-truncate">@RootLayout.DisplayName</div>
|
||||
<div>登录名:@UserName</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<div class="nav-header flex-fill align-items-center">
|
||||
<a href="/Pages/Admin/Profiles">
|
||||
<img src="@Model.Icon.ToBlazorLink()" />
|
||||
<span class="username d-inline-block text-truncate flex-fill">@Model.DisplayName</span>
|
||||
<span class="username d-inline-block text-truncate flex-fill">@RootLayout.DisplayName</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
|
|
Loading…
Reference in New Issue