feat: 增加获取后台地址方法
This commit is contained in:
parent
331f034d9b
commit
8c102946d7
|
@ -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();
|
||||
|
|
|
@ -24,6 +24,17 @@ namespace BootstrapClient.Web.Shared.Services
|
|||
[NotNull]
|
||||
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>
|
||||
|
|
|
@ -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<BootstrapAdminAuthenticationOptions>? 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('/'));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnInitialized 方法
|
||||
/// </summary>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,12 @@ public interface IDict
|
|||
/// <returns></returns>
|
||||
string? GetSettingsUrl(string appId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string? GetAdminUrl();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue