!64 增加功能:Blazor 模式下权限维护页面增加表头排序功能
Merge pull request !64 from Argo/dev-sort
This commit is contained in:
commit
1645f5f657
|
@ -34,7 +34,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// 查询按钮回调方法
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<int, int, string, QueryData<TItem>>? OnQuery { get; set; }
|
||||
public Func<QueryPageOptions, QueryData<TItem>>? OnQuery { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 TableHeader 实例
|
||||
|
@ -163,10 +163,8 @@ namespace Bootstrap.Admin.Components
|
|||
/// <summary>
|
||||
/// 分页查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageItems"></param>
|
||||
/// <param name="searchText"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
protected QueryData<TItem> QueryData(int pageIndex, int pageItems, string searchText) => OnQuery?.Invoke(pageIndex, pageItems, searchText) ?? new QueryData<TItem>();
|
||||
protected QueryData<TItem> QueryData(QueryPageOptions options) => OnQuery?.Invoke(options) ?? new QueryData<TItem>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// ITableHeader 接口
|
||||
/// </summary>
|
||||
public interface ITableHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取绑定字段显示名称方法
|
||||
/// </summary>
|
||||
string GetDisplayName();
|
||||
|
||||
/// <summary>
|
||||
/// 获取绑定字段信息方法
|
||||
/// </summary>
|
||||
string GetFieldName();
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否允许排序 默认为 false
|
||||
/// </summary>
|
||||
bool Sort { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,45 +1,69 @@
|
|||
using Bootstrap.Admin.Extensions;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// 表头组件
|
||||
/// </summary>
|
||||
public class LgbTableHeader<TItem> : ComponentBase
|
||||
public class LgbTableHeader<TItem> : ComponentBase, ITableHeader
|
||||
{
|
||||
#nullable disable
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得/设置 数据绑定 Value
|
||||
/// </summary>
|
||||
[Parameter] public TItem Value { get; set; }
|
||||
#nullable restore
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得/设置 ValueChanged 事件
|
||||
/// </summary>
|
||||
[Parameter] public EventCallback<TItem> ValueChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得/设置 ValueExpression 表达式
|
||||
/// </summary>
|
||||
[Parameter] public Expression<Func<TItem>>? ValueExpression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得/设置 是否排序 默认 false
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
[Parameter] public bool Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 Table Header 实例
|
||||
/// </summary>
|
||||
[CascadingParameter]
|
||||
protected TableHeaderBase? Header { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组件初始化方法
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var filed = FieldIdentifier.Create(ValueExpression);
|
||||
var text = filed.GetDisplayName();
|
||||
builder.OpenElement(0, "th");
|
||||
builder.AddContent(1, text);
|
||||
builder.CloseElement();
|
||||
Header?.AddHeaders(this);
|
||||
}
|
||||
|
||||
private FieldIdentifier? _fieldIdentifier;
|
||||
/// <summary>
|
||||
/// 获取绑定字段显示名称方法
|
||||
/// </summary>
|
||||
public string GetDisplayName()
|
||||
{
|
||||
if (_fieldIdentifier == null) _fieldIdentifier = FieldIdentifier.Create(ValueExpression);
|
||||
return _fieldIdentifier?.GetDisplayName() ?? "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取绑定字段信息方法
|
||||
/// </summary>
|
||||
public string GetFieldName()
|
||||
{
|
||||
if (_fieldIdentifier == null) _fieldIdentifier = FieldIdentifier.Create(ValueExpression);
|
||||
return _fieldIdentifier?.FieldName ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询条件实体类
|
||||
/// </summary>
|
||||
public class QueryPageOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 查询关键字
|
||||
/// </summary>
|
||||
public string SearchText { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 排序字段名称
|
||||
/// </summary>
|
||||
public string SortName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 排序方式
|
||||
/// </summary>
|
||||
public SortOrder SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 当前页码 首页为 第一页
|
||||
/// </summary>
|
||||
public int PageIndex { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 每页条目数量
|
||||
/// </summary>
|
||||
public int PageItems { get; set; } = 20;
|
||||
}
|
||||
}
|
|
@ -159,7 +159,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// 点击翻页回调方法
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<int, int, string, QueryData<TItem>>? OnQuery { get; set; }
|
||||
public Func<QueryPageOptions, QueryData<TItem>>? OnQuery { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 点击翻页回调方法
|
||||
|
@ -194,6 +194,12 @@ namespace Bootstrap.Admin.Components
|
|||
[Parameter]
|
||||
public Func<TItem, bool>? OnSave { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表头排序时回调方法
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Action<string, SortOrder> OnSort { get; set; } = new Action<string, SortOrder>((name, order) => { });
|
||||
|
||||
/// <summary>
|
||||
/// 删除按钮回调方法
|
||||
/// </summary>
|
||||
|
@ -253,11 +259,26 @@ namespace Bootstrap.Admin.Components
|
|||
[Parameter]
|
||||
public string SubmitModalTitle { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 当前排序字段名称
|
||||
/// </summary>
|
||||
protected string SortName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 当前排序规则
|
||||
/// </summary>
|
||||
protected SortOrder SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OnInitialized 方法
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
OnSort = new Action<string, SortOrder>((sortName, sortOrder) =>
|
||||
{
|
||||
(SortName, SortOrder) = (sortName, sortOrder);
|
||||
Query();
|
||||
});
|
||||
if (EditModel == null && OnAdd != null) EditModel = OnAdd.Invoke();
|
||||
if (OnDataSourceQuery != null)
|
||||
{
|
||||
|
@ -265,7 +286,7 @@ namespace Bootstrap.Admin.Components
|
|||
}
|
||||
if (OnQuery != null)
|
||||
{
|
||||
var queryData = OnQuery(1, DefaultPageItems, SearchText);
|
||||
var queryData = OnQuery(new QueryPageOptions() { PageItems = DefaultPageItems, SearchText = SearchText, SortName = SortName, SortOrder = SortOrder });
|
||||
Items = queryData.Items;
|
||||
TotalCount = queryData.TotalCount;
|
||||
}
|
||||
|
@ -399,7 +420,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// </summary>
|
||||
protected void Query()
|
||||
{
|
||||
if (OnQuery != null) Query(OnQuery(PageIndex, PageItems, SearchText));
|
||||
if (OnQuery != null) Query(OnQuery(new QueryPageOptions() { PageIndex = PageIndex, PageItems = PageItems, SearchText = SearchText, SortOrder = SortOrder, SortName = SortName }));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Table Header 组件
|
||||
/// </summary>
|
||||
public class TableHeaderBase : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the content to be rendered inside this
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 添加表头组件到集合方法
|
||||
/// </summary>
|
||||
public void AddHeaders(ITableHeader header) => Headers.Add(header);
|
||||
|
||||
/// <summary>
|
||||
/// 获得 表头集合
|
||||
/// </summary>
|
||||
public ICollection<ITableHeader> Headers { get; } = new HashSet<ITableHeader>();
|
||||
|
||||
/// <summary>
|
||||
/// 点击表头排序是触发此回调函数
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Action<string, SortOrder>? OnSort { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
using System;
|
||||
using Bootstrap.Admin.Extensions;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Table Header 表头组件
|
||||
/// </summary>
|
||||
public class TableHeaderContent : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 Table Header 实例
|
||||
/// </summary>
|
||||
[CascadingParameter]
|
||||
protected TableHeaderBase? Header { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 升序图标
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string SortIconAsc { get; set; } = "fa fa-sort-asc";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 降序图标
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string SortIconDesc { get; set; } = "fa fa-sort-desc";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 默认图标
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string SortDefault { get; set; } = "fa fa-sort";
|
||||
|
||||
private string sortName = "";
|
||||
private SortOrder sortOrder;
|
||||
|
||||
/// <summary>
|
||||
/// 渲染组件方法
|
||||
/// </summary>
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
// 渲染正常按钮
|
||||
if (Header != null)
|
||||
{
|
||||
var index = 0;
|
||||
foreach (var header in Header.Headers)
|
||||
{
|
||||
var fieldName = header.GetFieldName();
|
||||
var displayName = header.GetDisplayName();
|
||||
builder.OpenElement(index++, "th");
|
||||
|
||||
// 如果允许排序
|
||||
if (header.Sort)
|
||||
{
|
||||
builder.AddAttribute(index++, "onclick", new Action(() =>
|
||||
{
|
||||
if (sortName != fieldName) sortOrder = SortOrder.Asc;
|
||||
else sortOrder = sortOrder == SortOrder.Asc ? SortOrder.Desc : SortOrder.Asc;
|
||||
sortName = fieldName;
|
||||
|
||||
// 通知 Table 组件刷新数据
|
||||
Header.OnSort?.Invoke(sortName, sortOrder);
|
||||
StateHasChanged();
|
||||
}));
|
||||
builder.AddAttribute(index++, "class", "sortable");
|
||||
}
|
||||
builder.OpenElement(index++, "span");
|
||||
builder.AddContent(index++, displayName);
|
||||
builder.CloseElement();
|
||||
if (header.Sort)
|
||||
{
|
||||
builder.OpenElement(index++, "i");
|
||||
var order = sortName == fieldName ? sortOrder : SortOrder.Unset;
|
||||
var icon = order switch
|
||||
{
|
||||
SortOrder.Asc => SortIconAsc,
|
||||
SortOrder.Desc => SortIconDesc,
|
||||
_ => SortDefault
|
||||
};
|
||||
builder.AddAttribute(index++, "class", icon);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 排序顺序枚举类型
|
||||
/// </summary>
|
||||
public enum SortOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// 未设置
|
||||
/// </summary>
|
||||
Unset,
|
||||
/// <summary>
|
||||
/// 升序 0-9 A-Z
|
||||
/// </summary>
|
||||
Asc,
|
||||
/// <summary>
|
||||
/// 降序 9-0 Z-A
|
||||
/// </summary>
|
||||
Desc,
|
||||
}
|
||||
}
|
|
@ -14,10 +14,10 @@
|
|||
</ConditionComponent>
|
||||
</TableInfoTemplate>
|
||||
<TableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Category"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Name"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Code"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="int" @bind-Value="@context.Define"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Category" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Name" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Code" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="int" @bind-Value="@context.Define" Sort="true"></LgbTableHeader>
|
||||
</TableHeader>
|
||||
<RowTemplate>
|
||||
<td>@context.Category</td>
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
<TableToolbarButton class="btn btn-warning" Icon="fa fa-sitemap" Title="分配角色" OnClick="AssignRoles" />
|
||||
</TableToolbarTemplate>
|
||||
<TableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.GroupCode"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.GroupName"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Description"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.GroupCode" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.GroupName" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Description" Sort="true"></LgbTableHeader>
|
||||
</TableHeader>
|
||||
<RowTemplate>
|
||||
<td>@context.GroupCode</td>
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
</div>
|
||||
</TableInfoTemplate>
|
||||
<TableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.RoleName"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Description"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.RoleName" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Description" Sort="true"></LgbTableHeader>
|
||||
</TableHeader>
|
||||
<RowTemplate>
|
||||
<td>@context.RoleName</td>
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
<TableToolbarButton class="btn btn-warning" Icon="fa fa-sitemap" Title="分配角色" OnClick="AssignRoles" />
|
||||
</TableToolbarTemplate>
|
||||
<TableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.UserName"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.DisplayName"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="DateTime" @bind-Value="@context.RegisterTime"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="DateTime?" @bind-Value="@context.ApprovedTime"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.ApprovedBy"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Description"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.UserName" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.DisplayName" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="DateTime" @bind-Value="@context.RegisterTime" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="DateTime?" @bind-Value="@context.ApprovedTime" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.ApprovedBy" Sort="true"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Description" Sort="true"></LgbTableHeader>
|
||||
</TableHeader>
|
||||
<RowTemplate>
|
||||
<td>@context.UserName</td>
|
||||
|
|
|
@ -32,19 +32,28 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex">页码</param>
|
||||
/// <param name="pageItems">每页显示数据条目数量</param>
|
||||
/// <param name="searchText"></param>
|
||||
protected override QueryData<BootstrapDict> Query(int pageIndex, int pageItems, string searchText)
|
||||
/// <param name="options"></param>
|
||||
protected override QueryData<BootstrapDict> Query(QueryPageOptions options)
|
||||
{
|
||||
var data = DataAccess.DictHelper.RetrieveDicts();
|
||||
// filter
|
||||
if (QueryModel.Define != -1) data = data.Where(d => d.Define == QueryModel.Define);
|
||||
if (!string.IsNullOrEmpty(QueryModel.Name)) data = data.Where(d => d.Name.Contains(QueryModel.Name, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(QueryModel.Category)) data = data.Where(d => d.Category.Contains(QueryModel.Category, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(searchText)) data = data.Where(d => d.Category.Contains(searchText, StringComparison.OrdinalIgnoreCase) || d.Name.Contains(searchText, StringComparison.OrdinalIgnoreCase) || d.Code.Contains(searchText, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(options.SearchText)) data = data.Where(d => d.Category.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.Name.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.Code.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// sort
|
||||
data = options.SortName switch
|
||||
{
|
||||
nameof(BootstrapDict.Category) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.Category) : data.OrderByDescending(d => d.Category),
|
||||
nameof(BootstrapDict.Name) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.Name) : data.OrderByDescending(d => d.Name),
|
||||
nameof(BootstrapDict.Code) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.Code) : data.OrderByDescending(d => d.Code),
|
||||
nameof(BootstrapDict.Define) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.Define) : data.OrderByDescending(d => d.Define),
|
||||
_ => data
|
||||
};
|
||||
var totalCount = data.Count();
|
||||
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);
|
||||
return new QueryData<BootstrapDict>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };
|
||||
var items = data.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems);
|
||||
return new QueryData<BootstrapDict>() { Items = items, TotalCount = totalCount, PageIndex = options.PageIndex, PageItems = options.PageItems };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -14,18 +14,26 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex">页码</param>
|
||||
/// <param name="pageItems">每页显示数据条目数量</param>
|
||||
/// <param name="searchText"></param>
|
||||
protected override QueryData<Group> Query(int pageIndex, int pageItems, string searchText)
|
||||
/// <param name="options"></param>
|
||||
protected override QueryData<Group> Query(QueryPageOptions options)
|
||||
{
|
||||
var data = GroupHelper.Retrieves();
|
||||
if (!string.IsNullOrEmpty(QueryModel.GroupName)) data = data.Where(d => d.GroupName.Contains(QueryModel.GroupName, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(QueryModel.Description)) data = data.Where(d => d.Description != null && d.Description.Contains(QueryModel.Description, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(searchText)) data = data.Where(d => d.GroupName.Contains(searchText, StringComparison.OrdinalIgnoreCase) || (d.Description ?? "").Contains(searchText, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(options.SearchText)) data = data.Where(d => d.GroupName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || (d.Description ?? "").Contains(options.SearchText, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// sort
|
||||
data = options.SortName switch
|
||||
{
|
||||
nameof(Group.GroupName) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.GroupName) : data.OrderByDescending(d => d.GroupName),
|
||||
nameof(Group.GroupCode) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.GroupCode) : data.OrderByDescending(d => d.GroupCode),
|
||||
nameof(Group.Description) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.Description) : data.OrderByDescending(d => d.Description),
|
||||
_ => data
|
||||
};
|
||||
|
||||
var totalCount = data.Count();
|
||||
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);
|
||||
return new QueryData<Group>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };
|
||||
var items = data.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems);
|
||||
return new QueryData<Group>() { Items = items, TotalCount = totalCount, PageIndex = options.PageIndex, PageItems = options.PageItems };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -113,10 +113,8 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex">页码</param>
|
||||
/// <param name="pageItems">每页显示数据条目数量</param>
|
||||
/// <param name="searchText"></param>
|
||||
protected override QueryData<BootstrapMenu> Query(int pageIndex, int pageItems, string searchText)
|
||||
/// <param name="options"></param>
|
||||
protected override QueryData<BootstrapMenu> Query(QueryPageOptions options)
|
||||
{
|
||||
var data = MenuHelper.RetrieveMenusByUserName(UserName);
|
||||
if (!string.IsNullOrEmpty(QueryModel.Name)) data = data.Where(d => d.Name.Contains(QueryModel.Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
@ -124,10 +122,10 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
if (!string.IsNullOrEmpty(QueryModel.Category)) data = data.Where(d => d.Category == QueryModel.Category);
|
||||
if (QueryModel.IsResource != -1) data = data.Where(d => d.IsResource == QueryModel.IsResource);
|
||||
if (!string.IsNullOrEmpty(QueryModel.Application)) data = data.Where(d => d.Application.Equals(QueryModel.Application, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(searchText)) data = data.Where(d => d.Name.Contains(searchText, StringComparison.OrdinalIgnoreCase) || d.ParentName.Contains(searchText, StringComparison.OrdinalIgnoreCase) || d.Category.Contains(searchText, StringComparison.OrdinalIgnoreCase) || d.Application.Contains(searchText, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(options.SearchText)) data = data.Where(d => d.Name.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.ParentName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.Category.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.Application.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase));
|
||||
var totalCount = data.Count();
|
||||
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);
|
||||
return new QueryData<BootstrapMenu>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };
|
||||
var items = data.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems);
|
||||
return new QueryData<BootstrapMenu>() { Items = items, TotalCount = totalCount, PageIndex = options.PageIndex, PageItems = options.PageItems };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -155,7 +153,7 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// 删除方法
|
||||
/// </summary>
|
||||
protected override bool Delete(IEnumerable<BootstrapMenu> items) => MenuHelper.Delete(items.Select(item => item.Id ?? ""));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置搜索方法
|
||||
/// </summary>
|
||||
|
|
|
@ -24,10 +24,8 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex">页码</param>
|
||||
/// <param name="pageItems">每页显示数据条目数量</param>
|
||||
/// <param name="searchText"></param>
|
||||
protected abstract QueryData<TItem> Query(int pageIndex, int pageItems, string searchText);
|
||||
/// <param name="options"></param>
|
||||
protected abstract QueryData<TItem> Query(QueryPageOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// OnParametersSet 方法
|
||||
|
@ -46,11 +44,13 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// <summary>
|
||||
/// 保存方法
|
||||
/// </summary>
|
||||
protected abstract bool Save(TItem dict);
|
||||
/// <param name="item"></param>
|
||||
protected abstract bool Save(TItem item);
|
||||
|
||||
/// <summary>
|
||||
/// 删除方法
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
protected abstract bool Delete(IEnumerable<TItem> items);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,18 +14,25 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex">页码</param>
|
||||
/// <param name="pageItems">每页显示数据条目数量</param>
|
||||
/// <param name="searchText"></param>
|
||||
protected override QueryData<Role> Query(int pageIndex, int pageItems, string searchText)
|
||||
/// <param name="options"></param>
|
||||
protected override QueryData<Role> Query(QueryPageOptions options)
|
||||
{
|
||||
var data = RoleHelper.Retrieves();
|
||||
if (!string.IsNullOrEmpty(QueryModel.RoleName)) data = data.Where(d => d.RoleName.Contains(QueryModel.RoleName, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(QueryModel.Description)) data = data.Where(d => d.Description != null && d.Description.Contains(QueryModel.Description, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(searchText)) data = data.Where(d => d.RoleName.Contains(searchText, StringComparison.OrdinalIgnoreCase) || d.Description.Contains(searchText, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(options.SearchText)) data = data.Where(d => d.RoleName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.Description.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// sort
|
||||
data = options.SortName switch
|
||||
{
|
||||
nameof(Role.RoleName) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.RoleName) : data.OrderByDescending(d => d.RoleName),
|
||||
nameof(Role.Description) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.Description) : data.OrderByDescending(d => d.Description),
|
||||
_ => data
|
||||
};
|
||||
|
||||
var totalCount = data.Count();
|
||||
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);
|
||||
return new QueryData<Role>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };
|
||||
var items = data.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems);
|
||||
return new QueryData<Role>() { Items = items, TotalCount = totalCount, PageIndex = options.PageIndex, PageItems = options.PageItems };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -37,7 +44,7 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// 删除方法
|
||||
/// </summary>
|
||||
protected override bool Delete(IEnumerable<Role> items) => RoleHelper.Delete(items.Select(item => item.Id ?? ""));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置搜索方法
|
||||
/// </summary>
|
||||
|
@ -78,6 +85,5 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,18 +14,29 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex">页码</param>
|
||||
/// <param name="pageItems">每页显示数据条目数量</param>
|
||||
/// <param name="searchText"></param>
|
||||
protected override QueryData<User> Query(int pageIndex, int pageItems, string searchText)
|
||||
/// <param name="options"></param>
|
||||
protected override QueryData<User> Query(QueryPageOptions options)
|
||||
{
|
||||
var data = UserHelper.Retrieves();
|
||||
if (!string.IsNullOrEmpty(QueryModel.UserName)) data = data.Where(d => d.UserName.Contains(QueryModel.UserName, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(QueryModel.DisplayName)) data = data.Where(d => d.DisplayName.Contains(QueryModel.DisplayName, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(searchText)) data = data.Where(d => d.UserName.Contains(searchText, StringComparison.OrdinalIgnoreCase) || d.DisplayName.Contains(searchText, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(options.SearchText)) data = data.Where(d => d.UserName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.DisplayName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// sort
|
||||
data = options.SortName switch
|
||||
{
|
||||
nameof(User.UserName) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.UserName) : data.OrderByDescending(d => d.UserName),
|
||||
nameof(User.DisplayName) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.DisplayName) : data.OrderByDescending(d => d.DisplayName),
|
||||
nameof(User.Description) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.Description) : data.OrderByDescending(d => d.Description),
|
||||
nameof(User.ApprovedBy) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.ApprovedBy) : data.OrderByDescending(d => d.ApprovedBy),
|
||||
nameof(User.ApprovedTime) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.ApprovedTime) : data.OrderByDescending(d => d.ApprovedTime),
|
||||
nameof(User.RegisterTime) => options.SortOrder == SortOrder.Asc ? data.OrderBy(d => d.RegisterTime) : data.OrderByDescending(d => d.RegisterTime),
|
||||
_ => data
|
||||
};
|
||||
|
||||
var totalCount = data.Count();
|
||||
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);
|
||||
return new QueryData<User>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };
|
||||
var items = data.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems);
|
||||
return new QueryData<User>() { Items = items, TotalCount = totalCount, PageIndex = options.PageIndex, PageItems = options.PageItems };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -37,7 +48,7 @@ namespace Bootstrap.Pages.Admin.Components
|
|||
/// 删除方法
|
||||
/// </summary>
|
||||
protected override bool Delete(IEnumerable<User> users) => UserHelper.Delete(users.Select(item => item.Id ?? ""));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置搜索方法
|
||||
/// </summary>
|
||||
|
|
|
@ -61,7 +61,10 @@
|
|||
{
|
||||
<th class="table-col-lineno">行号</th>
|
||||
}
|
||||
@TableHeader?.Invoke(EditModel)
|
||||
<TableHeader OnSort="OnSort">
|
||||
<TableHeaderContent />
|
||||
@TableHeader?.Invoke(EditModel)
|
||||
</TableHeader>
|
||||
@if (ShowExtendButtons)
|
||||
{
|
||||
<th>@ButtonTemplateHeaderText</th>
|
||||
|
@ -82,7 +85,10 @@
|
|||
{
|
||||
<th class="table-col-lineno">行号</th>
|
||||
}
|
||||
@TableHeader?.Invoke(EditModel)
|
||||
<TableHeader OnSort="OnSort">
|
||||
<TableHeaderContent />
|
||||
@TableHeader?.Invoke(EditModel)
|
||||
</TableHeader>
|
||||
@if (ShowExtendButtons)
|
||||
{
|
||||
<th>@ButtonTemplateHeaderText</th>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
@inherits TableHeaderBase
|
||||
|
||||
<CascadingValue Value="this" IsFixed="true">
|
||||
@ChildContent
|
||||
</CascadingValue>
|
|
@ -163,6 +163,24 @@ nav .dropdown .nav-link-close.dropdown-toggle:after {
|
|||
border-bottom: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.bootstrap-table .sortable {
|
||||
padding-right: 30px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.bootstrap-table .sortable span {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.bootstrap-table .sortable i {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.bootstrap-table .sortable .fa-sort {
|
||||
color: #dee2e6;
|
||||
}
|
||||
|
||||
.table-wrapper {
|
||||
border-radius: 4px;
|
||||
margin-bottom: 1rem;
|
||||
|
|
Loading…
Reference in New Issue