feat: 增加显示名称功能

This commit is contained in:
Argo-Tianyi 2021-12-15 10:31:35 +08:00
parent b8f2851dab
commit 2232cd2eb9
7 changed files with 35 additions and 6 deletions

View File

@ -4,5 +4,14 @@ namespace BootstrapAdmin.DataAccess.EFCore.Services
{
class DictsService : IDicts
{
public string GetWebFooter()
{
throw new NotImplementedException();
}
public string GetWebTitle()
{
throw new NotImplementedException();
}
}
}

View File

@ -33,7 +33,8 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
if (!string.IsNullOrEmpty(name))
{
title = dicts.First(d => d.Category == name && d.Name == "网站标题")?.Code ?? "网站标题";
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站标题") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站标题");
title = dict?.Code ?? "网站标题";
}
return title;
}
@ -49,7 +50,8 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
if (!string.IsNullOrEmpty(name))
{
title = dicts.First(d => d.Category == name && d.Name == "网站页脚")?.Code ?? "网站页脚";
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站页脚") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站页脚");
title = dict?.Code ?? "网站标题";
}
return title;
}

View File

@ -37,7 +37,7 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public string GetDisplayName(string userName) => Database.ExecuteScalar<string>("select DisplayName from Users where UserName = @0", userName);
public string? GetDisplayName(string? userName) => string.IsNullOrEmpty(userName) ? "" : Database.ExecuteScalar<string>("select DisplayName from Users where UserName = @0", userName);
/// <summary>
///

View File

@ -10,7 +10,7 @@
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
string GetDisplayName(string userName);
string? GetDisplayName(string? userName);
/// <summary>
/// 通过用户名获取角色列表

View File

@ -61,6 +61,7 @@ namespace Bootstrap.Admin.Controllers
/// <returns>The login.</returns>
/// <param name="userService"></param>
/// <param name="loginService"></param>
/// <param name="context"></param>
/// <param name="userName">User name.</param>
/// <param name="password">Password.</param>
/// <param name="remember">Remember.</param>

View File

@ -10,6 +10,11 @@
/// </summary>
public string AppId { get; }
/// <summary>
///
/// </summary>
public string? UserName { get; set; }
/// <summary>
///
/// </summary>

View File

@ -1,5 +1,6 @@
using BootstrapAdmin.Web.Core;
using BootstrapAdmin.Web.Extensions;
using Microsoft.AspNetCore.Components.Authorization;
namespace BootstrapAdmin.Web.Shared
{
@ -20,7 +21,7 @@ namespace BootstrapAdmin.Web.Shared
[Inject]
[NotNull]
private IUsers? UsersService { get; set; }
private AuthenticationStateProvider? AuthenticationStateProvider { get; set; }
[Inject]
[NotNull]
@ -43,7 +44,18 @@ namespace BootstrapAdmin.Web.Shared
Title = DictsService.GetWebTitle();
Footer = DictsService.GetWebFooter();
DisplayName = UsersService.GetDisplayName();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override async Task OnInitializedAsync()
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var userName = state.User.Identity?.Name;
DisplayName = UsersService.GetDisplayName(userName);
}
}
}