11 changed files with 224 additions and 11 deletions
@ -0,0 +1,28 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Bundling; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorServerComponentBundleManager : IComponentBundleManager, ITransientDependency |
|||
{ |
|||
protected IBundleManager BundleManager { get; } |
|||
|
|||
public BlazorServerComponentBundleManager(IBundleManager bundleManager) |
|||
{ |
|||
BundleManager = bundleManager; |
|||
} |
|||
|
|||
public virtual async Task<IReadOnlyList<string>> GetStyleBundleFilesAsync(string bundleName) |
|||
{ |
|||
return (await BundleManager.GetStyleBundleFilesAsync(bundleName)).Select(f => f.FileName).ToList(); |
|||
} |
|||
|
|||
public virtual async Task<IReadOnlyList<string>> GetScriptBundleFilesAsync(string bundleName) |
|||
{ |
|||
return (await BundleManager.GetScriptBundleFilesAsync(bundleName)).Select(f => f.FileName).ToList(); |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
@using Volo.Abp |
|||
@implements IDisposable |
|||
@inject IComponentBundleManager BundleManager |
|||
@inject PersistentComponentState PersistentComponentState |
|||
|
|||
@if (ScriptFiles != null) |
|||
{ |
|||
foreach (var file in ScriptFiles) |
|||
{ |
|||
<script src="@file"></script> |
|||
} |
|||
} |
|||
|
|||
@code { |
|||
[Parameter] |
|||
public List<string>? WebAssemblyScriptFiles { get; set; } |
|||
|
|||
[Parameter] |
|||
public string? BundleName { get; set; } |
|||
|
|||
private List<string>? ScriptFiles { get; set; } |
|||
|
|||
private PersistingComponentStateSubscription persistingSubscription; |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
if (BundleName == null) |
|||
{ |
|||
throw new AbpException("The BundleName parameter of the AbpScripts component can not be null!"); |
|||
} |
|||
|
|||
persistingSubscription = PersistentComponentState.RegisterOnPersisting(PersistScriptFiles); |
|||
|
|||
if (PersistentComponentState.TryTakeFromJson<List<string>>(nameof(ScriptFiles), out var restoredStyleFiles)) |
|||
{ |
|||
ScriptFiles = restoredStyleFiles; |
|||
} |
|||
else |
|||
{ |
|||
ScriptFiles = (await BundleManager.GetScriptBundleFilesAsync(BundleName!)).ToList(); |
|||
} |
|||
|
|||
if (WebAssemblyScriptFiles != null) |
|||
{ |
|||
ScriptFiles?.AddRange(WebAssemblyScriptFiles); |
|||
} |
|||
} |
|||
|
|||
private Task PersistScriptFiles() |
|||
{ |
|||
PersistentComponentState.PersistAsJson(nameof(ScriptFiles), ScriptFiles); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public void Dispose() => persistingSubscription.Dispose(); |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
@using Volo.Abp |
|||
@implements IDisposable |
|||
@inject IComponentBundleManager BundleManager |
|||
@inject PersistentComponentState PersistentComponentState |
|||
|
|||
@if (StyleFiles != null) |
|||
{ |
|||
foreach (var file in StyleFiles) |
|||
{ |
|||
<link rel="stylesheet" href="@file" /> |
|||
} |
|||
} |
|||
|
|||
@code { |
|||
[Parameter] |
|||
public List<string>? WebAssemblyStyleFiles { get; set; } |
|||
|
|||
[Parameter] |
|||
public string? BundleName { get; set; } |
|||
|
|||
private List<string>? StyleFiles { get; set; } |
|||
|
|||
private PersistingComponentStateSubscription persistingSubscription; |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
if (BundleName == null) |
|||
{ |
|||
throw new AbpException("The BundleName parameter of the AbpStyles component can not be null!"); |
|||
} |
|||
|
|||
persistingSubscription = PersistentComponentState.RegisterOnPersisting(PersistStyleFiles); |
|||
|
|||
if (PersistentComponentState.TryTakeFromJson<List<string>>(nameof(StyleFiles), out var restoredStyleFiles)) |
|||
{ |
|||
StyleFiles = restoredStyleFiles; |
|||
} |
|||
else |
|||
{ |
|||
StyleFiles = (await BundleManager.GetStyleBundleFilesAsync(BundleName!)).ToList(); |
|||
} |
|||
|
|||
if (OperatingSystem.IsBrowser() && WebAssemblyStyleFiles != null) |
|||
{ |
|||
StyleFiles?.AddRange(WebAssemblyStyleFiles); |
|||
} |
|||
} |
|||
|
|||
private Task PersistStyleFiles() |
|||
{ |
|||
PersistentComponentState.PersistAsJson(nameof(StyleFiles), StyleFiles); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public void Dispose() => persistingSubscription.Dispose(); |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Bundling; |
|||
|
|||
public interface IComponentBundleManager |
|||
{ |
|||
Task<IReadOnlyList<string>> GetStyleBundleFilesAsync(string bundleName); |
|||
|
|||
Task<IReadOnlyList<string>> GetScriptBundleFilesAsync(string bundleName); |
|||
} |
|||
@ -1,16 +1,8 @@ |
|||
@inject NavigationManager Navigation |
|||
@inject IJSRuntime JSRuntime |
|||
|
|||
@code { |
|||
protected override void OnInitialized() |
|||
{ |
|||
if (JSRuntime is IJSInProcessRuntime) |
|||
{ |
|||
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); |
|||
} |
|||
else |
|||
{ |
|||
Navigation.NavigateTo($"account/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}", true); |
|||
} |
|||
Navigation.NavigateTo($"account/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}", true); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,8 @@ |
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme; |
|||
|
|||
public class AuthenticationOptions |
|||
{ |
|||
public string LoginUrl { get; set; } = "authentication/login"; |
|||
|
|||
public string LogoutUrl { get; set; } = "authentication/logout"; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Bundling; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
public class WebAssemblyComponentBundleManager : IComponentBundleManager, ITransientDependency |
|||
{ |
|||
public virtual Task<IReadOnlyList<string>> GetStyleBundleFilesAsync(string bundleName) |
|||
{ |
|||
return Task.FromResult<IReadOnlyList<string>>(new List<string>()); |
|||
} |
|||
|
|||
public virtual Task<IReadOnlyList<string>> GetScriptBundleFilesAsync(string bundleName) |
|||
{ |
|||
return Task.FromResult<IReadOnlyList<string>>(new List<string>()); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
@inject NavigationManager Navigation |
|||
@using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesignTheme |
|||
@using Microsoft.Extensions.Options |
|||
@inject IOptions<AuthenticationOptions> AuthenticationOptions |
|||
@inject IOptions<AbpAspNetCoreComponentsWebOptions> AbpAspNetCoreComponentsWebOptions |
|||
@using Volo.Abp.DependencyInjection |
|||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication |
|||
@using Volo.Abp.AspNetCore.Components.Web |
|||
@inherits RedirectToLogin |
|||
@attribute [ExposeServices(typeof(RedirectToLogin))] |
|||
@attribute [Dependency(ReplaceServices = true)] |
|||
|
|||
@code { |
|||
|
|||
protected override void OnInitialized() |
|||
{ |
|||
if (AbpAspNetCoreComponentsWebOptions.Value.IsBlazorWebApp) |
|||
{ |
|||
Navigation.NavigateTo(AuthenticationOptions.Value.LogoutUrl, forceLoad: true); |
|||
} |
|||
else |
|||
{ |
|||
Navigation.NavigateToLogin(AuthenticationOptions.Value.LoginUrl); |
|||
} |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue