From 8c102946d79a9d8cfe948beb412c344c12aef126 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 25 Jan 2022 00:40:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=9C=B0=E5=9D=80=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/DictService.cs | 6 ++++ .../Services/BootstrapAppContext.cs | 11 ++++++ .../Shared/MainLayout.razor.cs | 35 ++++++++++++------- .../client/BootstrapClient.Web.Core/IDict.cs | 6 ++++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/blazor/client/BootstrapClient.DataAccess/Services/DictService.cs b/src/blazor/client/BootstrapClient.DataAccess/Services/DictService.cs index 384c4ef8..13307a78 100644 --- a/src/blazor/client/BootstrapClient.DataAccess/Services/DictService.cs +++ b/src/blazor/client/BootstrapClient.DataAccess/Services/DictService.cs @@ -64,6 +64,12 @@ class DictService : IDict return dicts.FirstOrDefault(d => d.Category == appId && d.Name == dictName && d.Define == EnumDictDefine.Customer)?.Code; } + public string? GetAdminUrl() + { + var dicts = GetAll(); + return dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name == "BA")?.Code; + } + public string RetrieveIconFolderPath() { var dicts = GetAll(); diff --git a/src/blazor/client/BootstrapClient.Shared/Services/BootstrapAppContext.cs b/src/blazor/client/BootstrapClient.Shared/Services/BootstrapAppContext.cs index d01eb2cc..0671feda 100644 --- a/src/blazor/client/BootstrapClient.Shared/Services/BootstrapAppContext.cs +++ b/src/blazor/client/BootstrapClient.Shared/Services/BootstrapAppContext.cs @@ -24,6 +24,17 @@ namespace BootstrapClient.Web.Shared.Services [NotNull] public string? DisplayName { get; internal set; } + /// + /// 获得/设置 应用程序基础地址 如 http://localhost:49185 + /// + [NotNull] + public Uri? BaseUri { get; set; } + + /// + /// 获得/设置 后台程序基础地址 如 http://localhost:5210 + /// + public string? AdminUrl { get; set; } + /// /// 构造函数 /// diff --git a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs index 6fc186df..9e40c9c6 100644 --- a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs +++ b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs @@ -3,10 +3,8 @@ using BootstrapBlazor.Components; using BootstrapClient.Web.Core; using BootstrapClient.Web.Shared.Extensions; using BootstrapClient.Web.Shared.Services; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.Extensions.Options; namespace BootstrapClient.Web.Shared.Shared; @@ -61,10 +59,6 @@ public sealed partial class MainLayout [NotNull] private INavigation? NavigationsService { get; set; } - [Inject] - [NotNull] - private IOptions? AuthorizationOption { get; set; } - [Inject] [NotNull] private NavigationManager? NavigationManager { get; set; } @@ -80,18 +74,19 @@ public sealed partial class MainLayout { base.OnInitialized(); + Context.BaseUri = NavigationManager.ToAbsoluteUri(NavigationManager.BaseUri); + + var adminUrl = DictsService.GetAdminUrl(); + if (!string.IsNullOrEmpty(adminUrl)) + { + Context.AdminUrl = string.Format(adminUrl, Context.BaseUri.Scheme, Context.BaseUri.Host).TrimEnd('/'); + } + ProfileUrl = CombinePath(DictsService.GetProfileUrl(Context.AppId)); SettingsUrl = CombinePath(DictsService.GetSettingsUrl(Context.AppId)); NotificationUrl = CombinePath(DictsService.GetNotificationUrl(Context.AppId)); } - private string CombinePath(string? url) - { - url ??= ""; - var hostUrl = AuthorizationOption.Value.AuthHost.TrimEnd('/'); - return string.Join('/', hostUrl, url.TrimStart('/')); - } - /// /// OnInitialized 方法 /// @@ -121,4 +116,18 @@ public sealed partial class MainLayout private string LogoutUrl => CombinePath($"/Account/Logout?AppId={Context.AppId}"); private string AuthorUrl => CombinePath($"/Account/Login?ReturnUrl={NavigationManager.Uri}&AppId={Context.AppId}"); + + private string CombinePath(string? url) + { + url ??= ""; + if (!string.IsNullOrEmpty(Context.AdminUrl)) + { + url = string.Join('/', Context.AdminUrl, url.TrimStart('/')); + } + else + { + url = "#"; + } + return url; + } } diff --git a/src/blazor/client/BootstrapClient.Web.Core/IDict.cs b/src/blazor/client/BootstrapClient.Web.Core/IDict.cs index 5a5728bb..e1cfc5f8 100644 --- a/src/blazor/client/BootstrapClient.Web.Core/IDict.cs +++ b/src/blazor/client/BootstrapClient.Web.Core/IDict.cs @@ -37,6 +37,12 @@ public interface IDict /// string? GetSettingsUrl(string appId); + /// + /// + /// + /// + string? GetAdminUrl(); + /// /// ///