feat: 菜单维护增加自定义高级搜索功能
This commit is contained in:
parent
808dc444b1
commit
c28ef26e8e
|
@ -12,6 +12,7 @@ namespace BootstrapAdmin.DataAccess.Models
|
|||
/// <summary>
|
||||
/// 获得/设置 菜单主键ID
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
public string? Id { set; get; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<div class="row g-3 form-inline">
|
||||
<div class="col-sm-6 col-md-6">
|
||||
<BootstrapInput @bind-Value="Value.Name" ShowLabel="true" />
|
||||
</div>
|
||||
<div class="col-sm-6 col-md-6">
|
||||
<BootstrapInput @bind-Value="Value.Url" ShowLabel="true" />
|
||||
</div>
|
||||
<div class="col-sm-6 col-md-6">
|
||||
<Select Items="@CategoryItems" @bind-Value="Value.Category" ShowLabel="true"></Select>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<Select Items="@TargetItems" @bind-Value="Value.Target" ShowLabel="true"></Select>
|
||||
</div>
|
||||
<div class="col-sm-6 col-md-6">
|
||||
<Select Items="@ResourceItems" @bind-Value="Value.IsResource" ShowLabel="true"></Select>
|
||||
</div>
|
||||
<div class="col-sm-6 col-md-6">
|
||||
<Select Items="@AppItems" @bind-Value="Value.Application" ShowLabel="true"></Select>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,50 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
using BootstrapAdmin.Web.Models;
|
||||
using BootstrapAdmin.Web.Utils;
|
||||
|
||||
namespace BootstrapAdmin.Web.Components;
|
||||
|
||||
public partial class MenusSearch
|
||||
{
|
||||
[NotNull]
|
||||
[Inject]
|
||||
private IDict? DictService { get; set; }
|
||||
|
||||
private IEnumerable<SelectedItem>? CategoryItems { get; set; }
|
||||
|
||||
private IEnumerable<SelectedItem>? ResourceItems { get; set; }
|
||||
|
||||
private List<SelectedItem>? AppItems { get; set; }
|
||||
|
||||
private List<SelectedItem>? TargetItems { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[NotNull]
|
||||
public MenusSearchModel? Value { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<MenusSearchModel> ValueChanged { get; set; }
|
||||
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
TargetItems = new List<SelectedItem>()
|
||||
{
|
||||
new SelectedItem("", "全部")
|
||||
};
|
||||
TargetItems.AddRange(LookupHelper.GetTargets());
|
||||
|
||||
AppItems = new List<SelectedItem>()
|
||||
{
|
||||
new SelectedItem("", "全部")
|
||||
};
|
||||
AppItems.AddRange(DictService.GetApps().ToSelectedItemList());
|
||||
|
||||
ResourceItems = typeof(EnumResource).ToSelectList(new SelectedItem("", "全部"));
|
||||
CategoryItems = typeof(EnumNavigationCategory).ToSelectList(new SelectedItem("", "全部"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BootstrapAdmin.Web.Models;
|
||||
|
||||
public class MenusSearchModel : ITableSearchModel
|
||||
{
|
||||
[Display(Name = "名称")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[Display(Name = "地址")]
|
||||
public string? Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单
|
||||
/// </summary>
|
||||
[Display(Name = "类别")]
|
||||
public EnumNavigationCategory? Category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 链接目标
|
||||
/// </summary>
|
||||
[Display(Name = "目标")]
|
||||
public string? Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮
|
||||
/// </summary>
|
||||
[Display(Name = "类型")]
|
||||
public EnumResource? IsResource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 所属应用程序,此属性由BA后台字典表分配
|
||||
/// </summary>
|
||||
[Display(Name = "所属应用")]
|
||||
public string? Application { get; set; }
|
||||
|
||||
public IEnumerable<IFilterAction> GetSearchs()
|
||||
{
|
||||
var ret = new List<IFilterAction>();
|
||||
if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
ret.Add(new SearchFilterAction(nameof(Navigation.Name), Name));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Url))
|
||||
{
|
||||
ret.Add(new SearchFilterAction(nameof(Navigation.Url), Url));
|
||||
}
|
||||
|
||||
if (Category.HasValue)
|
||||
{
|
||||
ret.Add(new SearchFilterAction(nameof(Navigation.Category), Category.Value));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Application))
|
||||
{
|
||||
ret.Add(new SearchFilterAction(nameof(Navigation.Application), Application));
|
||||
}
|
||||
|
||||
if (IsResource.HasValue)
|
||||
{
|
||||
ret.Add(new SearchFilterAction(nameof(Navigation.IsResource), IsResource.Value));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Target))
|
||||
{
|
||||
ret.Add(new SearchFilterAction(nameof(Navigation.Target), Target));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Name = null;
|
||||
Url = null;
|
||||
Category = null;
|
||||
IsResource = null;
|
||||
Target = null;
|
||||
Application = null;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
@page "/Admin/Menus"
|
||||
|
||||
<AdminTable TItem="DataAccess.Models.Navigation"
|
||||
IsTree="true" OnTreeExpand="OnTreeExpand" ExtendButtonColumnWidth="200"
|
||||
OnQueryAsync="OnQueryAsync">
|
||||
<Table TItem="DataAccess.Models.Navigation" IsBordered="true" IsStriped="true" IsMultipleSelect="true"
|
||||
IsFixedHeader="true" IsTree="true" OnTreeExpand="OnTreeExpand" ExtendButtonColumnWidth="200"
|
||||
ShowToolbar="true" ShowExtendButtons="true" ShowSearch="true" CustomerSearchModel="SearchModel"
|
||||
UseInjectDataService="true" OnQueryAsync="OnQueryAsync">
|
||||
<TableToolbarTemplate>
|
||||
<TableToolbarButton TItem="DataAccess.Models.Navigation" IsEnableWhenSelectedOneRow="true" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="menus => OnAssignmentRoles(menus.First())" />
|
||||
</TableToolbarTemplate>
|
||||
<ColumnsTemplete>
|
||||
<TableColumn @bind-Field="@context.Name" Filterable="true" Searchable="true" Width="200"></TableColumn>
|
||||
<TableColumns>
|
||||
<TableColumn @bind-Field="@context.Name" Filterable="true" Width="200"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.Order" Width="50"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.Icon" Width="50" Align="Alignment.Center">
|
||||
<Template Context="v">
|
||||
|
@ -19,8 +20,45 @@
|
|||
<TableColumn @bind-Field="@context.Target" Filterable="true" Lookup="Targets"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.IsResource" Filterable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.Application" Filterable="true" Lookup="Apps"></TableColumn>
|
||||
</ColumnsTemplete>
|
||||
</TableColumns>
|
||||
<EditTemplate Context="v">
|
||||
<div class="row g-3 form-inline">
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<BootstrapInput @bind-Value="v.Name" DisplayText="菜单名称" ShowLabel="true"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<Select @bind-Value="v.ParentId" Items="@ParementMenus" IsDisabled="@(v.ParentId == "0")" DisplayText="父级菜单" ShowLabel="true"></Select>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<BootstrapInput @bind-Value="v.Order"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<BootstrapInput @bind-Value="v.Icon"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<BootstrapInput @bind-Value="v.Url"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<Select @bind-Value="v.Category"></Select>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<Select Items="@Targets" @bind-Value="v.Target"></Select>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<Select @bind-Value="v.IsResource"></Select>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-6">
|
||||
<Select Items="@Apps" @bind-Value="v.Application"></Select>
|
||||
</div>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
<RowButtonTemplate>
|
||||
<TableCellButton Size="Size.ExtraSmall" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClick="() => OnAssignmentRoles(context)" />
|
||||
</RowButtonTemplate>
|
||||
</AdminTable>
|
||||
<CustomerSearchTemplate>
|
||||
@if (context is MenusSearchModel searchModel)
|
||||
{
|
||||
<MenusSearch @bind-Value="searchModel"></MenusSearch>
|
||||
}
|
||||
</CustomerSearchTemplate>
|
||||
</Table>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
using BootstrapAdmin.Web.Models;
|
||||
using BootstrapAdmin.Web.Services;
|
||||
using BootstrapAdmin.Web.Utils;
|
||||
|
||||
|
@ -38,6 +39,11 @@ public partial class Menus
|
|||
[NotNull]
|
||||
private List<SelectedItem>? Apps { get; set; }
|
||||
|
||||
[NotNull]
|
||||
private List<SelectedItem>? ParementMenus { get; set; }
|
||||
|
||||
private ITableSearchModel? SearchModel { get; set; } = new MenusSearchModel();
|
||||
|
||||
/// <summary>
|
||||
/// OnInitialized 方法
|
||||
/// </summary>
|
||||
|
@ -47,6 +53,9 @@ public partial class Menus
|
|||
|
||||
Targets = LookupHelper.GetTargets();
|
||||
Apps = DictService.GetApps().ToSelectedItemList();
|
||||
|
||||
ParementMenus = NavigationService.GetAllMenus(AppContext.UserName).Where(s => s.ParentId == "0").Select(s => new SelectedItem(s.Id, s.Name)).ToList();
|
||||
ParementMenus.Insert(0, new SelectedItem("0", "请选择"));
|
||||
}
|
||||
|
||||
private async Task OnAssignmentRoles(DataAccess.Models.Navigation menu)
|
||||
|
|
Loading…
Reference in New Issue