feat: 增加程序异常分页逻辑
This commit is contained in:
parent
93630f99b4
commit
ebbaba0f59
|
@ -1,4 +1,5 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.DataAccess.PetaPoco.Extensions;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using PetaPoco;
|
||||
|
||||
|
@ -17,4 +18,31 @@ class ExceptionService : BaseDatabase, IException
|
|||
catch { }
|
||||
return true;
|
||||
}
|
||||
|
||||
public (IEnumerable<Error> Items, int ItemsCount) GetAll(string? searchText, int pageIndex, int pageItems, string? sortName, string sortOrder)
|
||||
{
|
||||
var sql = new Sql();
|
||||
|
||||
if (!string.IsNullOrEmpty(searchText))
|
||||
{
|
||||
sql.Append("WHERE ErrorPage Like @0 or Message Like @0 or StackTrace Like @0", $"%{searchText}%");
|
||||
}
|
||||
|
||||
if (sortOrder == "Unset")
|
||||
{
|
||||
sortOrder = "desc";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(sortName))
|
||||
{
|
||||
sql.OrderBy("Logtime desc", "ErrorPage", "UserId");
|
||||
}
|
||||
else
|
||||
{
|
||||
sql.OrderBy($"{sortName} {sortOrder}");
|
||||
}
|
||||
|
||||
var data = Database.Page<Error>(pageIndex, pageItems, sql);
|
||||
return (data.Items, data.TotalItems.ToInt32());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,4 +5,6 @@ namespace BootstrapAdmin.Web.Core;
|
|||
public interface IException
|
||||
{
|
||||
bool Log(Error exception);
|
||||
|
||||
(IEnumerable<Error> Items, int ItemsCount) GetAll(string? searchText, int pageIndex, int pageItems, string?sortName, string sortOrder);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
@page "/Admin/Exceptions"
|
||||
|
||||
<AdminTable TItem="DataAccess.Models.Error"
|
||||
IsPagination="true" PageItemsSource="PageItemsSource"
|
||||
ShowDefaultButtons="false" ShowExtendButtons="false" ShowAdvancedSearch="false"
|
||||
OnQueryAsync="OnQueryAsync">
|
||||
<ColumnsTemplete>
|
||||
<TableColumn @bind-Field="context.LogTime" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="context.ErrorPage" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="context.UserId" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="context.UserIp" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="context.ExceptionType" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="context.Message" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
|
||||
</ColumnsTemplete>
|
||||
</AdminTable>
|
|
@ -0,0 +1,29 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
|
||||
namespace BootstrapAdmin.Web.Pages.Admin;
|
||||
|
||||
public partial class Exceptions
|
||||
{
|
||||
private List<int> PageItemsSource { get; } = new List<int> { 5, 20, 40, 80, 100, 200 };
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IException? ExceptionService { get; set; }
|
||||
|
||||
private Task<QueryData<Error>> OnQueryAsync(QueryPageOptions options)
|
||||
{
|
||||
var ret = new QueryData<Error>()
|
||||
{
|
||||
IsSorted = true,
|
||||
IsFiltered = true,
|
||||
IsSearch = true
|
||||
};
|
||||
|
||||
var items = ExceptionService.GetAll(options.SearchText, options.PageIndex, options.PageItems, options.SortName, options.SortOrder.ToString());
|
||||
|
||||
ret.TotalCount = items.ItemsCount;
|
||||
ret.Items = items.Items;
|
||||
return Task.FromResult(ret);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue