feat: 增加显示名称功能
This commit is contained in:
parent
b8f2851dab
commit
2232cd2eb9
|
@ -4,5 +4,14 @@ namespace BootstrapAdmin.DataAccess.EFCore.Services
|
|||
{
|
||||
class DictsService : IDicts
|
||||
{
|
||||
public string GetWebFooter()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetWebTitle()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
///
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
string GetDisplayName(string userName);
|
||||
string? GetDisplayName(string? userName);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户名获取角色列表
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
/// </summary>
|
||||
public string AppId { get; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue