You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Options;
|
|
using Volo.Abp.Ui.LayoutHooks;
|
|
|
|
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Components;
|
|
|
|
public partial class LayoutHook : ComponentBase
|
|
{
|
|
[Parameter]
|
|
public string Name { get; set; } = default!;
|
|
|
|
[Parameter]
|
|
public string? Layout { get; set; }
|
|
|
|
[Inject]
|
|
protected IOptions<AbpLayoutHookOptions> LayoutHookOptions { get; set; } = default!;
|
|
|
|
protected LayoutHookViewModel LayoutHookViewModel { get; private set; } = default!;
|
|
|
|
protected override Task OnInitializedAsync()
|
|
{
|
|
if (LayoutHookOptions.Value.Hooks.TryGetValue(Name, out var layoutHooks))
|
|
{
|
|
layoutHooks = layoutHooks
|
|
.Where(x => IsComponentBase(x) && (string.IsNullOrWhiteSpace(x.Layout) || x.Layout == Layout))
|
|
.ToList();
|
|
}
|
|
|
|
layoutHooks ??= new List<LayoutHookInfo>();
|
|
|
|
LayoutHookViewModel = new LayoutHookViewModel(layoutHooks.ToArray(), Layout);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
protected virtual bool IsComponentBase(LayoutHookInfo layoutHook)
|
|
{
|
|
return typeof(ComponentBase).IsAssignableFrom(layoutHook.ComponentType);
|
|
}
|
|
}
|