diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs index 4a1ced77..e6c0548b 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs @@ -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; + } } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs index 35cbb693..31ed886e 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs @@ -111,5 +111,11 @@ namespace BootstrapAdmin.Web.Core /// /// bool SaveCookieExpiresPeriod(int expiresPeriod); + + string? GetProfileUrl(string appId); + + string? GetSettingsUrl(string appId); + + string? GetNotificationUrl(string appId); } } diff --git a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor index 1915e5d3..1c841bb2 100644 --- a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor +++ b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor @@ -8,8 +8,14 @@
Bootstrap of Blazor - - @DisplayName + + + 个人中心 + 设置 + 通知 + 注销 + +
diff --git a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs index 2cf2f6c3..71edb1cf 100644 --- a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs +++ b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs @@ -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? MenuItems { get; set; } + private string? ProfileUrl { get; set; } + + private string? SettingsUrl { get; set; } + + private string? NotificationUrl { get; set; } + /// /// 获得 当前用户登录显示名称 /// @@ -74,6 +81,31 @@ namespace BootstrapClient.Web.Shared.Shared [NotNull] private NavigationManager? NavigationManager { get; set; } + [Inject] + [NotNull] + private IConfiguration? Configuration { get; set; } + + /// + /// OnInitialized 方法 + /// + 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('/')); + } + /// /// OnInitialized 方法 /// @@ -96,6 +128,8 @@ namespace BootstrapClient.Web.Shared.Shared private Task 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); } } diff --git a/src/blazor/client/BootstrapClient.Shared/Utils/AppContext.cs b/src/blazor/client/BootstrapClient.Shared/Utils/AppContext.cs new file mode 100644 index 00000000..24b73b8c --- /dev/null +++ b/src/blazor/client/BootstrapClient.Shared/Utils/AppContext.cs @@ -0,0 +1,7 @@ +namespace BootstrapClient.Web.Shared.Utils; + +class AppContext +{ + [NotNull] + public string? AppId { get; set; } +}