feat: 完善重置查询按钮

This commit is contained in:
Argo Zhang 2020-01-23 14:55:17 +08:00
parent af80525198
commit 09a3523432
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
7 changed files with 59 additions and 36 deletions

View File

@ -119,6 +119,12 @@ namespace Bootstrap.Admin.Components
[Parameter]
public Func<TItem, bool> OnSave { get; set; } = item => false;
/// <summary>
/// 重置搜索条件回调方法
/// </summary>
[Parameter]
public Action OnResetSearch { get; set; } = () => { };
/// <summary>
/// 删除按钮回调方法
/// </summary>
@ -160,18 +166,6 @@ namespace Bootstrap.Admin.Components
}
}
/// <summary>
/// 查询方法
/// </summary>
protected void Query()
{
// 查询控件按钮触发此事件
if (OnQuery != null && Table != null)
{
Table.Query(OnQuery.Invoke(1, Table.PageItems));
}
}
/// <summary>
/// 分页查询方法
/// </summary>

View File

@ -222,12 +222,6 @@ namespace Bootstrap.Admin.Components
[Parameter]
public string SubmitModalTitle { get; set; } = "";
/// <summary>
/// 查询组件模板
/// </summary>
[Parameter]
public RenderFragment<TItem>? SearchContent { get; set; }
/// <summary>
/// OnInitialized 方法
/// </summary>
@ -368,7 +362,10 @@ namespace Bootstrap.Admin.Components
StateHasChanged();
}
private void Query()
/// <summary>
/// 查询按钮调用此方法
/// </summary>
protected void Query()
{
if (OnQuery != null) Query(OnQuery.Invoke(PageIndex, PageItems));
}
@ -422,14 +419,29 @@ namespace Bootstrap.Admin.Components
/// </summary>
public string RetrieveId() => $"{Id}_table";
protected void OnSearch()
{
}
/// <summary>
/// 重置搜索按钮回调方法
/// </summary>
[Parameter]
public Action? OnResetSearch { get; set; }
/// <summary>
/// 重置查询方法
/// </summary>
protected void ResetSearchClick()
{
OnResetSearch?.Invoke();
SearchClick();
}
/// <summary>
/// 查询方法
/// </summary>
protected void SearchClick()
{
// 查询控件按钮触发此事件
PageIndex = 1;
Query();
}
}
}

View File

@ -1,10 +1,10 @@
@inherits DictsBase
<EditPage Id="dict" FixedHeader="@FixedHeader" ShowSearch="true" TItem="Bootstrap.Security.BootstrapDict" SubmitModalTitle="字典编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save">
<EditPage Id="dict" FixedHeader="@FixedHeader" ShowSearch="true" TItem="Bootstrap.Security.BootstrapDict" SubmitModalTitle="字典编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
<QueryBody>
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.Category" maxlength="50" />
<Select ColumnClass="col-sm-auto" Items="QueryDefine" TItem="int" @bind-Value="@context.Define" />
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.Name" maxlength="50" />
<LgbInputText ColumnClass="col-12" @bind-Value="@context.Category" maxlength="50" />
<Select ColumnClass="col-12" Items="QueryDefine" TItem="int" @bind-Value="@context.Define" />
<LgbInputText ColumnClass="col-12" @bind-Value="@context.Name" maxlength="50" />
</QueryBody>
<TableInfoTemplate>
<ConditionComponent>

View File

@ -54,5 +54,15 @@ namespace Bootstrap.Pages.Admin.Components
/// 删除方法
/// </summary>
protected override bool Delete(IEnumerable<BootstrapDict> items) => DataAccess.DictHelper.Delete(items.Select(item => item.Id ?? ""));
/// <summary>
/// 重置搜索方法
/// </summary>
protected void ResetSearch()
{
QueryModel.Define = -1;
QueryModel.Category = "";
QueryModel.Name = "";
}
}
}

View File

@ -1,15 +1,12 @@
@typeparam TItem
@inherits EditPageBase<TItem>
<Query Id="@($"{Id}_query")" OnQuery="Query" TItem="TItem" QueryModel="QueryModel">
@QueryBody?.Invoke(context)
</Query>
<div class="card">
<div class="card-header">
查询结果
</div>
<div class="card-body">
<Table @ref="Table" Id="@Id" FixedHeader="@FixedHeader" ShowSearch="@ShowSearch" QueryModel="QueryModel" TItem="TItem" SubmitModalTitle="@SubmitModalTitle" OnQuery="QueryData" OnAdd="OnAdd" OnDelete="OnDelete" OnSave="OnSave">
<Table @ref="Table" Id="@Id" FixedHeader="@FixedHeader" ShowSearch="@ShowSearch" QueryModel="QueryModel" TItem="TItem" SubmitModalTitle="@SubmitModalTitle" OnQuery="QueryData" OnAdd="OnAdd" OnDelete="OnDelete" OnSave="OnSave" OnResetSearch="OnResetSearch">
<TableToolbarTemplate>
@TableToolbarTemplate
</TableToolbarTemplate>
@ -30,7 +27,7 @@
@EditTemplate?.Invoke(context)
</EditTemplate>
<SearchTemplate>
@SearchTemplate?.Invoke(context)
@QueryBody?.Invoke(context)
</SearchTemplate>
</Table>
</div>

View File

@ -12,6 +12,11 @@
@TableToolbarTemplate
</TableToolbar>
</div>
<div class="float-right columns columns-right">
<button class="btn btn-secondary" type="button" title="刷新" @onclick="Query">
<i class="fa fa-refresh"></i><span>刷新</span>
</button>
</div>
<div class="float-right @(ShowSearch ? "search btn-group" : "search btn-group d-none")">
<div class="input-group">
<input class="form-control search-input" type="text" placeholder="搜索" />
@ -21,7 +26,8 @@
</button>
<button class="btn btn-secondary" type="button" title="清空过滤">
<i class="fa fa-trash"></i> <span>清空过滤</span>
</button><button class="btn btn-secondary" type="button" title="高级搜索" @onclick="AdvancedSearchClick">
</button>
<button class="btn btn-secondary" type="button" title="高级搜索" @onclick="AdvancedSearchClick">
<i class="fa fa-search-plus"></i><span>高级搜索</span>
</button>
</div>
@ -173,16 +179,16 @@
<ModalBody>
<LgbEditForm class="form-inline" Id="@Id" Model="QueryModel">
<div class="row">
@SearchContent?.Invoke(QueryModel)
@SearchTemplate?.Invoke(QueryModel)
</div>
</LgbEditForm>
</ModalBody>
<ModalFooter>
<button type="button" class="btn btn-info" @onclick="ResetSearchClick">
<button type="button" class="btn btn-info" data-dismiss="modal" @onclick="ResetSearchClick">
<i class="fa fa-trash-o"></i>
<span>重置</span>
</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">
<button type="button" class="btn btn-primary" data-dismiss="modal" @onclick="SearchClick">
<i class="fa fa-search"></i>
<span>查询</span>
</button>

View File

@ -138,6 +138,10 @@ nav .dropdown .nav-link-close.dropdown-toggle:after {
margin-top: 10px;
}
.bootstrap-table .fixed-table-toolbar .columns-right {
margin-left: 5px;
}
.bootstrap-table .fixed-table-header {
overflow: hidden;
}