feat: Client 增加登出弹框功能

This commit is contained in:
Argo-Lenovo 2022-01-02 12:06:26 +08:00
parent 580055c688
commit 76a6628865
5 changed files with 74 additions and 3 deletions

View File

@ -152,4 +152,22 @@ class DictService : BaseDatabase, IDict
public bool SaveWebFooter(string footer) => SaveDict(new Dict { Category = "网站设置", Name = "网站页脚", Code = footer });
public bool SaveCookieExpiresPeriod(int expiresPeriod) => SaveDict(new Dict { Category = "网站设置", Name = "Cookie保留时长", Code = expiresPeriod.ToString() });
public string? GetProfileUrl(string appId) => GetUrlByName(appId, "个人中心地址");
public string? GetSettingsUrl(string appId) => GetUrlByName(appId, "系统设置地址");
public string? GetNotificationUrl(string appId) => GetUrlByName(appId, "系统通知地址");
private string? GetUrlByName(string appId, string dictName)
{
string? url = null;
var dicts = GetAll();
var appName = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == appId && d.Define == EnumDictDefine.System)?.Name;
if (!string.IsNullOrEmpty(appName))
{
url = dicts.FirstOrDefault(d => d.Category == appName && d.Name == dictName && d.Define == EnumDictDefine.Customer)?.Code;
}
return url;
}
}

View File

@ -111,5 +111,11 @@ namespace BootstrapAdmin.Web.Core
/// <param name="expiresPeriod"></param>
/// <returns></returns>
bool SaveCookieExpiresPeriod(int expiresPeriod);
string? GetProfileUrl(string appId);
string? GetSettingsUrl(string appId);
string? GetNotificationUrl(string appId);
}
}

View File

@ -8,8 +8,14 @@
<Header>
<span class="ml-3 flex-sm-fill d-none d-sm-block">Bootstrap of Blazor</span>
<Widget></Widget>
<img src="_content/BootstrapClient.Web.Shared/images/Argo.png" class="layout-avatar-right" />
<span class="mx-3 d-none d-sm-block">@DisplayName</span>
<Logout ImageUrl="_content/BootstrapClient.Web.Shared/images/Argo.png" DisplayName="@DisplayName" UserName="@UserName">
<LinkTemplate>
<a href="@ProfileUrl"><i class="fa fa-suitcase"></i>个人中心</a>
<a href="@SettingsUrl"><i class="fa fa-cog"></i>设置</a>
<a href="@NotificationUrl"><i class="fa fa-bell"></i>通知<span id="logoutNoti" class="badge badge-pill badge-success"></span></a>
<a href="#" @onclick="OnLogout"><i class="fa fa-key"></i>注销</a>
</LinkTemplate>
</Logout>
<div class="layout-drawer" @onclick="@(e => IsOpen = !IsOpen)"><i class="fa fa-gears"></i></div>
</Header>
<Side>

View File

@ -5,6 +5,7 @@ using BootstrapClient.Web.Shared.Extensions;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace BootstrapClient.Web.Shared.Shared
@ -30,6 +31,12 @@ namespace BootstrapClient.Web.Shared.Shared
private IEnumerable<MenuItem>? MenuItems { get; set; }
private string? ProfileUrl { get; set; }
private string? SettingsUrl { get; set; }
private string? NotificationUrl { get; set; }
/// <summary>
/// 获得 当前用户登录显示名称
/// </summary>
@ -74,6 +81,31 @@ namespace BootstrapClient.Web.Shared.Shared
[NotNull]
private NavigationManager? NavigationManager { get; set; }
[Inject]
[NotNull]
private IConfiguration? Configuration { get; set; }
/// <summary>
/// OnInitialized 方法
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();
// TODO: 后期重构 AppId 到统一的地方
var appId = Configuration.GetValue("AppId", "Blazor");
ProfileUrl = CombinePath(DictsService.GetProfileUrl(appId));
SettingsUrl = CombinePath(DictsService.GetSettingsUrl(appId));
NotificationUrl = CombinePath(DictsService.GetNotificationUrl(appId));
}
private string CombinePath(string? url)
{
url ??= "";
var hostUrl = AuthorizationOption.Value.AuthHost.TrimEnd('/');
return string.Join('/', hostUrl, url.TrimStart('/'));
}
/// <summary>
/// OnInitialized 方法
/// </summary>
@ -96,6 +128,8 @@ namespace BootstrapClient.Web.Shared.Shared
private Task<bool> OnAuthorizing(string url) => SecurityService.AuhorizingNavigation(UserName, url);
private string GetAuthorUrl() => $"{AuthorizationOption.Value.AuthHost}/Account/Login?ReturnUrl={NavigationManager.Uri}";
private string GetAuthorUrl() => CombinePath($"/Account/Login?ReturnUrl={NavigationManager.Uri}");
private void OnLogout() => NavigationManager.NavigateTo(CombinePath("/Account/Logout"), true);
}
}

View File

@ -0,0 +1,7 @@
namespace BootstrapClient.Web.Shared.Utils;
class AppContext
{
[NotNull]
public string? AppId { get; set; }
}