!53 增加功能:个人中心用户显示名称使用双向绑定

Merge pull request !53 from Argo/dev-blazor-wip
This commit is contained in:
Argo 2020-01-12 12:03:09 +08:00 committed by Gitee
commit ca1f843606
8 changed files with 32 additions and 23 deletions

View File

@ -93,7 +93,8 @@ namespace Bootstrap.Admin.Components
var cacheKey = (ModelType: fieldIdentifier.Model.GetType(), fieldIdentifier.FieldName);
if (!_propertyInfoCache.TryGetValue(cacheKey, out propertyInfo))
{
propertyInfo = cacheKey.ModelType.GetProperty(cacheKey.FieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
// Validator.TryValidateProperty 只能对 Public 属性生效
propertyInfo = cacheKey.ModelType.GetProperty(cacheKey.FieldName);
_propertyInfoCache[cacheKey] = propertyInfo;
}

View File

@ -108,8 +108,8 @@ namespace Bootstrap.Admin.Components
public void OnDisplayNameChanged(string displayName)
{
DisplayName = displayName;
Header?.UpdateState();
SideBar?.UpdateState();
Header?.DisplayNameChanged.InvokeAsync(DisplayName);
SideBar?.DisplayNameChanged.InvokeAsync(DisplayName);
}
/// <summary>

View File

@ -9,29 +9,33 @@ namespace Bootstrap.Admin.Components
public class HeaderBase : ComponentBase
{
/// <summary>
///
/// 获得 网站标题
/// </summary>
[Parameter]
public string Title { get; set; } = "";
/// <summary>
///
/// 获得 根模板页实例
/// </summary>
[CascadingParameter(Name = "Default")]
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
/// <summary>
///
/// 获得/设置 用户图标
/// </summary>
[Parameter]
public string Icon { get; set; } = "";
/// <summary>
///
/// 获得/设置 用户显示名称
/// </summary>
public void UpdateState()
{
StateHasChanged();
}
[Parameter]
public string DisplayName { get; set; } = "";
/// <summary>
/// 获得/设置 用户显示名称改变事件回调方法
/// </summary>
[Parameter]
public EventCallback<string> DisplayNameChanged { get; set; }
}
}

View File

@ -16,17 +16,21 @@ namespace Bootstrap.Admin.Components
public NavigatorBarModel Model { get; set; } = new NavigatorBarModel("");
/// <summary>
///
/// 获得 根模板页实例
/// </summary>
[CascadingParameter(Name = "Default")]
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
/// <summary>
///
/// 获得/设置 用户显示名称
/// </summary>
public void UpdateState()
{
StateHasChanged();
}
[Parameter]
public string DisplayName { get; set; } = "";
/// <summary>
/// 获得/设置 用户显示名称改变事件回调方法
/// </summary>
[Parameter]
public EventCallback<string> DisplayNameChanged { get; set; }
}
}

View File

@ -42,7 +42,7 @@ namespace Bootstrap.Pages.Admin.Components
/// 获得/设置 当前用户显示名称
/// </summary>
[DisplayName("显示名称")]
protected string DisplayName { get; set; } = "";
public string DisplayName { get; set; } = "";
/// <summary>
/// 组件初始化方法

View File

@ -1,8 +1,8 @@
@inherits DefaultLayoutComponentBase
<CascadingValue Value=this Name="Default">
<Header @ref="Header" Icon="@Model.Icon" Title="@Model.Title" />
<SideBar @ref="SideBar" Model=@Model />
<Header @ref="Header" Icon="@Model.Icon" Title="@Model.Title" @bind-DisplayName="DisplayName" />
<SideBar @ref="SideBar" Model=@Model @bind-DisplayName="DisplayName" />
@Body
<Footer Text="@Model.Footer" IsDemo=@Model.IsDemo></Footer>
</CascadingValue>

View File

@ -95,14 +95,14 @@
<div class="dropdown userinfo">
<div data-toggle="dropdown" class="dropdown-toggle shadow-default">
<img alt="" src="@Icon.ToBlazorLink()" />
<span class="username text-truncate d-inline-block">@RootLayout.DisplayName</span>
<span class="username text-truncate d-inline-block">@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">@RootLayout.DisplayName</div>
<div class="username text-truncate">@DisplayName</div>
<div>登录名:@RootLayout.UserName</div>
</div>
</div>

View File

@ -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">@RootLayout.DisplayName</span>
<span class="username d-inline-block text-truncate flex-fill">@DisplayName</span>
</a>
</div>
<div class="sidebar">