diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor b/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor index 1493c7e7..c9f8029f 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor @@ -1 +1,3 @@ - +@inherits AssignmentBase + + diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor.cs index 5d527bbf..68e32e61 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/Assignment.razor.cs @@ -2,21 +2,6 @@ public partial class Assignment { - [Parameter] - [EditorRequired] - [NotNull] - public List? Items { get; set; } - - [Parameter] - [EditorRequired] - [NotNull] - public List? Value { get; set; } - - [Parameter] - [EditorRequired] - [NotNull] - public Action>? OnValueChanged { get; set; } - private List InternalValue { get { return Value; } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/AssignmentBase.cs b/src/blazor/admin/BootstrapAdmin.Web/Components/AssignmentBase.cs new file mode 100644 index 00000000..fc920834 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/AssignmentBase.cs @@ -0,0 +1,19 @@ +namespace BootstrapAdmin.Web.Components; + +public abstract class AssignmentBase : ComponentBase +{ + [Parameter] + [EditorRequired] + [NotNull] + public List? Items { get; set; } + + [Parameter] + [EditorRequired] + [NotNull] + public List? Value { get; set; } + + [Parameter] + [EditorRequired] + [NotNull] + public Action>? OnValueChanged { get; set; } +} diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor new file mode 100644 index 00000000..7fd899c3 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor @@ -0,0 +1,8 @@ +@inherits AssignmentBase + + + +@code { + RenderFragment RenderTreeItem => item => + @
@item.Name@item.Order@GetApp(item.Application)
; +} \ No newline at end of file diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.cs new file mode 100644 index 00000000..7fcf7728 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.cs @@ -0,0 +1,33 @@ +using BootstrapAdmin.Web.Core; +using BootstrapAdmin.Web.Extensions; + +namespace BootstrapAdmin.Web.Components; + +public partial class NavigationTree +{ + [NotNull] + private List? InternalItems { get; set; } + + [Inject] + [NotNull] + private IDict? DictService { get; set; } + + /// + /// + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + InternalItems = Items.ToTreeItemList(Value, RenderTreeItem); + } + + private Task OnTreeItemChecked(List 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 ?? "未设置"; +}