feat: 增加授权组件基类
This commit is contained in:
parent
fe36e7d888
commit
dee2e909a4
|
@ -1 +1,3 @@
|
|||
<CheckboxList Items="Items" @bind-Value="InternalValue" ShowBorder="false" ShowLabel="false" />
|
||||
@inherits AssignmentBase<SelectedItem>
|
||||
|
||||
<CheckboxList Items="Items" @bind-Value="InternalValue" ShowBorder="false" ShowLabel="false" />
|
||||
|
|
|
@ -2,21 +2,6 @@
|
|||
|
||||
public partial class Assignment
|
||||
{
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
[NotNull]
|
||||
public List<SelectedItem>? Items { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
[NotNull]
|
||||
public List<string>? Value { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
[NotNull]
|
||||
public Action<List<string>>? OnValueChanged { get; set; }
|
||||
|
||||
private List<string> InternalValue
|
||||
{
|
||||
get { return Value; }
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
namespace BootstrapAdmin.Web.Components;
|
||||
|
||||
public abstract class AssignmentBase<TItem> : ComponentBase
|
||||
{
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
[NotNull]
|
||||
public List<TItem>? Items { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
[NotNull]
|
||||
public List<string>? Value { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
[NotNull]
|
||||
public Action<List<string>>? OnValueChanged { get; set; }
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
@inherits AssignmentBase<Navigation>
|
||||
|
||||
<Tree Items="InternalItems" ShowCheckbox="true" ShowIcon="true" OnTreeItemChecked="@OnTreeItemChecked" />
|
||||
|
||||
@code {
|
||||
RenderFragment<Navigation> RenderTreeItem => item =>
|
||||
@<div class="d-flex flex-fill"><span class="flex-fill">@item.Name</span><span class="mx-3">@item.Order</span><span>@GetApp(item.Application)</span></div>;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
|
||||
namespace BootstrapAdmin.Web.Components;
|
||||
|
||||
public partial class NavigationTree
|
||||
{
|
||||
[NotNull]
|
||||
private List<TreeItem>? InternalItems { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IDict? DictService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
InternalItems = Items.ToTreeItemList(Value, RenderTreeItem);
|
||||
}
|
||||
|
||||
private Task OnTreeItemChecked(List<TreeItem> items)
|
||||
{
|
||||
Value = items.Select(i => i.Key!.ToString()!).ToList();
|
||||
OnValueChanged(Value);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private string GetApp(string app) => DictService.GetApps().FirstOrDefault(i => i.Value == app)?.Text ?? "未设置";
|
||||
}
|
Loading…
Reference in New Issue