!2856 feat(#I5AOA7): add ShowUserName parameter on Logout component

* chore: bump version 6.7.3
* test: 增加 ShowUserName 单元测试
* doc: 更新参数说明文档
* doc: 更新示例
* feat: 增加 ShowUserName 参数
This commit is contained in:
Argo 2022-06-04 04:11:03 +00:00
parent 0d83709570
commit 8b5760a0aa
7 changed files with 36 additions and 3 deletions

View File

@ -9,6 +9,11 @@
<div style="height: 80px;"></div>
</DemoBlock>
<DemoBlock Title="仅显示头像" Introduction="设置 <code>ShowUserName</code> 值为 <code>false</code>" Name="ShowUserName">
<Logout ImageUrl="_content/BootstrapBlazor.Shared/images/Argo.png" DisplayName="Administrators" UserName="Admin" ShowUserName="false" class="bg-secondary" />
<div style="height: 80px;"></div>
</DemoBlock>
<DemoBlock Title="自定义登录信息模板" Introduction="设置 <code>HeaderTemplate</code>" Name="HeaderTemplate">
<Logout ImageUrl="_content/BootstrapBlazor.Shared/images/Argo.png" DisplayName="Administrators" UserName="Admin" class="bg-warning">
<HeaderTemplate>

View File

@ -42,6 +42,13 @@ public partial class Logouts
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = nameof(Logout.ShowUserName),
Description = "是否显示用户名",
Type = "bool",
ValueList = "true|false",
DefaultValue = "true"
},
new AttributeItem() {
Name = nameof(Logout.PrefixUserNameText),
Description = "登出组件当前用户登录账号前置文字",

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<Version>6.7.2</Version>
<Version>6.7.3</Version>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

View File

@ -4,7 +4,10 @@
<div @attributes="AdditionalAttributes" class="@LogoutClassString">
<a class="dropdown-toggle" data-bs-toggle="dropdown" href="#" id="@Id" aria-expanded="false">
<img class="logout-avatar" alt="avatar" src="@ImageUrl" />
<span class="logout-text">@DisplayName</span>
@if (ShowUserName)
{
<span class="logout-text">@DisplayName</span>
}
</a>
<div class="dropdown-menu dropdown-menu-right shadow" aria-labelledby="@Id">
<div class="dropdown-item dropdown-user">

View File

@ -40,6 +40,12 @@ public partial class Logout
[Parameter]
public string? UserName { get; set; }
/// <summary>
/// 获得/设置 是否显示用户名 默认 true 显示
/// </summary>
[Parameter]
public bool ShowUserName { get; set; } = true;
/// <summary>
/// 获得/设置 组件当前用户登录账号前置文本 默认 当前账号
/// </summary>

File diff suppressed because one or more lines are too long

View File

@ -34,6 +34,18 @@ public class LogoutTest : BootstrapBlazorTestBase
Assert.Contains("prefix_username", cut.Markup);
}
[Fact]
public void ShowUserName_Ok()
{
// 未设置 Items
var cut = Context.RenderComponent<Logout>(pb =>
{
pb.Add(a => a.UserName, "admin");
pb.Add(a => a.ShowUserName, false);
});
Assert.DoesNotContain("logout-text", cut.Markup);
}
[Fact]
public void DisplayName_Ok()
{