feat: 增加获取后台地址方法

This commit is contained in:
Argo-Tianyi 2022-01-25 00:40:15 +08:00
parent 331f034d9b
commit 8c102946d7
4 changed files with 45 additions and 13 deletions

View File

@ -64,6 +64,12 @@ class DictService : IDict
return dicts.FirstOrDefault(d => d.Category == appId && d.Name == dictName && d.Define == EnumDictDefine.Customer)?.Code; 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() public string RetrieveIconFolderPath()
{ {
var dicts = GetAll(); var dicts = GetAll();

View File

@ -24,6 +24,17 @@ namespace BootstrapClient.Web.Shared.Services
[NotNull] [NotNull]
public string? DisplayName { get; internal set; } public string? DisplayName { get; internal set; }
/// <summary>
/// 获得/设置 应用程序基础地址 如 http://localhost:49185
/// </summary>
[NotNull]
public Uri? BaseUri { get; set; }
/// <summary>
/// 获得/设置 后台程序基础地址 如 http://localhost:5210
/// </summary>
public string? AdminUrl { get; set; }
/// <summary> /// <summary>
/// 构造函数 /// 构造函数
/// </summary> /// </summary>

View File

@ -3,10 +3,8 @@ using BootstrapBlazor.Components;
using BootstrapClient.Web.Core; using BootstrapClient.Web.Core;
using BootstrapClient.Web.Shared.Extensions; using BootstrapClient.Web.Shared.Extensions;
using BootstrapClient.Web.Shared.Services; using BootstrapClient.Web.Shared.Services;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Options;
namespace BootstrapClient.Web.Shared.Shared; namespace BootstrapClient.Web.Shared.Shared;
@ -61,10 +59,6 @@ public sealed partial class MainLayout
[NotNull] [NotNull]
private INavigation? NavigationsService { get; set; } private INavigation? NavigationsService { get; set; }
[Inject]
[NotNull]
private IOptions<BootstrapAdminAuthenticationOptions>? AuthorizationOption { get; set; }
[Inject] [Inject]
[NotNull] [NotNull]
private NavigationManager? NavigationManager { get; set; } private NavigationManager? NavigationManager { get; set; }
@ -80,18 +74,19 @@ public sealed partial class MainLayout
{ {
base.OnInitialized(); 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)); ProfileUrl = CombinePath(DictsService.GetProfileUrl(Context.AppId));
SettingsUrl = CombinePath(DictsService.GetSettingsUrl(Context.AppId)); SettingsUrl = CombinePath(DictsService.GetSettingsUrl(Context.AppId));
NotificationUrl = CombinePath(DictsService.GetNotificationUrl(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('/'));
}
/// <summary> /// <summary>
/// OnInitialized 方法 /// OnInitialized 方法
/// </summary> /// </summary>
@ -121,4 +116,18 @@ public sealed partial class MainLayout
private string LogoutUrl => CombinePath($"/Account/Logout?AppId={Context.AppId}"); private string LogoutUrl => CombinePath($"/Account/Logout?AppId={Context.AppId}");
private string AuthorUrl => CombinePath($"/Account/Login?ReturnUrl={NavigationManager.Uri}&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;
}
} }

View File

@ -37,6 +37,12 @@ public interface IDict
/// <returns></returns> /// <returns></returns>
string? GetSettingsUrl(string appId); string? GetSettingsUrl(string appId);
/// <summary>
///
/// </summary>
/// <returns></returns>
string? GetAdminUrl();
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>