|
|
|
@ -1,11 +1,13 @@ |
|
|
|
@using Volo.Abp |
|
|
|
@implements IDisposable |
|
|
|
@inject IComponentBundleManager BundleManager |
|
|
|
@inject PersistentComponentState PersistentComponentState |
|
|
|
|
|
|
|
@if (StyleFiles != null) |
|
|
|
{ |
|
|
|
foreach (var file in StyleFiles) |
|
|
|
{ |
|
|
|
<link rel="stylesheet" href="@file"/> |
|
|
|
<link rel="stylesheet" href="@file" /> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -18,16 +20,37 @@ |
|
|
|
|
|
|
|
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!"); |
|
|
|
} |
|
|
|
StyleFiles = (await BundleManager.GetStyleBundleFilesAsync(BundleName!)).ToList(); |
|
|
|
|
|
|
|
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); |
|
|
|
StyleFiles!.AddRange(WebAssemblyStyleFiles); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Task PersistStyleFiles() |
|
|
|
{ |
|
|
|
PersistentComponentState.PersistAsJson(nameof(StyleFiles), StyleFiles); |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() => persistingSubscription.Dispose(); |
|
|
|
} |
|
|
|
|