-
Notifications
You must be signed in to change notification settings - Fork 10
/
GamesTableViewTip.razor
162 lines (148 loc) · 7.82 KB
/
GamesTableViewTip.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
@inject HttpClient Http
@inject ToastService? ToastService
@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService
@if (!isReady)
{
<SkeletonParagraph />
<div class="mt-2">
</div>
<SkeletonParagraph />
<div class="mt-2">
</div>
<SkeletonParagraph />
<div class="mt-2">
</div>
<SkeletonParagraph />
}
else
{
<Table TItem="BasicInforTableModel" IsPagination="true" PageItemsSource="@PageItems" IsStriped=true
OnQueryAsync="@OnQueryBasicAsync" SearchModel="@SearchModelBasic" ShowSearch="true" ShowLoading="true"
ShowExtendButtons="true" ExtendButtonColumnWidth="70" FixedExtendButtonsColumn="true"
ShowToolbar="true" ShowDefaultButtons="false" @ref="table">
<TableToolbarTemplate>
<CnGalWebSite.Shared.MasaComponent.Shared.Buttons.ExportButton TItem="BasicInforTableModel" Columns="table.Columns" Items="ModelBasic.BasicInfors" Name="游戏汇总表" />
</TableToolbarTemplate>
<TableColumns>
<TableColumn @bind-Field="@context.RealId" Filterable="true" Sortable="true" Width="80" TextWrap="true" Fixed="true" />
<TableColumn @bind-Field="@context.IssueTime" FormatString="yyyy-MM-dd" Sortable="true" DefaultSort="true" Width="100" TextWrap="true" />
<TableColumn @bind-Field="@context.Name" Filterable="true" Sortable="true" Searchable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.ProductionGroup" Filterable="true" Sortable="true" Searchable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.Original" Filterable="true" Sortable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.GamePlatforms" Filterable="true" Sortable="true" Searchable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.Engine" Filterable="true" Sortable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.Publisher" Filterable="true" Sortable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.GameNickname" Filterable="true" Sortable="true" Searchable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.Tags" Filterable="true" Sortable="true" Searchable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.IssueMethod" Filterable="true" Sortable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.OfficialWebsite" Filterable="true" Sortable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.SteamId" Filterable="true" Sortable="true" Width="200" TextWrap="true" />
<TableColumn @bind-Field="@context.QQgroupGame" Filterable="true" Sortable="true" Width="200" TextWrap="true" />
</TableColumns>
<RowButtonTemplate>
<TableCellButton AutoSelectedRowWhenClick="false" Size="Size.ExtraSmall" Color="Color.Success" Icon="fa fa-share-square-o" Text="查看" IsAsync="true" OnClickWithoutRender="@(() => OnLook(context.RealId))" />
</RowButtonTemplate>
</Table>
}
@code {
Table<BasicInforTableModel> table;
[CascadingParameter]
public ErrorHandler ErrorHandler { get; set; }
private IEnumerable<int> PageItems => new int[] { 10, 20, 40, 80, 200, 1000 };
public BasicInforListViewModel ModelBasic { get; set; } = new BasicInforListViewModel
{
BasicInfors = new List<BasicInforTableModel>()
};
private bool isReady = false;
private static readonly ConcurrentDictionary<Type, Func<IEnumerable<BasicInforTableModel>, string, BootstrapBlazor.Components.SortOrder, IEnumerable<BasicInforTableModel>>> SortLambdaCacheBasic = new();
private BasicInforTableModel SearchModelBasic { get; set; } = new BasicInforTableModel();
protected override async Task OnInitializedAsync()
{
try
{
//因为server端在处理大量数据时会断开连接 所以一切数据从服务端加载
ModelBasic = await Http.GetFromJsonAsync<BasicInforListViewModel>(ToolHelper.WebApiPath + "api/tables/GetBasicInforList");
isReady = true;
}
catch (Exception ex)
{
ErrorHandler.ProcessError(ex, "无法获取基础信息汇总表格");
}
}
[Parameter]
public EventCallback<NavigateModel> OnClickUrl { get; set; }
public async Task OnLook(long id)
{
await _dataCacheService.OpenNewPage.InvokeAsync(ToolHelper.WebApiPath + "entries/index/" + id);
}
private Task<QueryData<BasicInforTableModel>> OnQueryBasicAsync(QueryPageOptions options)
{
IEnumerable<BasicInforTableModel> items = ModelBasic.BasicInfors;
// 处理高级搜索
if (!string.IsNullOrWhiteSpace(SearchModelBasic.Name))
{
items = items.Where(item => item.Name?.Contains(SearchModelBasic.Name, StringComparison.OrdinalIgnoreCase) ?? false);
}
if (!string.IsNullOrWhiteSpace(SearchModelBasic.ProductionGroup))
{
items = items.Where(item => item.ProductionGroup?.Contains(SearchModelBasic.ProductionGroup, StringComparison.OrdinalIgnoreCase) ?? false);
}
if (!string.IsNullOrWhiteSpace(SearchModelBasic.GameNickname))
{
items = items.Where(item => item.GameNickname?.Contains(SearchModelBasic.GameNickname, StringComparison.OrdinalIgnoreCase) ?? false);
}
if (!string.IsNullOrWhiteSpace(SearchModelBasic.GamePlatforms))
{
items = items.Where(item => item.GamePlatforms?.Contains(SearchModelBasic.GamePlatforms, StringComparison.OrdinalIgnoreCase) ?? false);
}
if (!string.IsNullOrWhiteSpace(SearchModelBasic.Tags))
{
items = items.Where(item => item.Tags?.Contains(SearchModelBasic.Tags, StringComparison.OrdinalIgnoreCase) ?? false);
}
// 处理 Searchable=true 列与 SeachText 模糊搜索
if (options.Searchs.Any())
{
items = items.Where(options.Searchs.GetFilterFunc<BasicInforTableModel>(FilterLogic.Or));
}
else
{
// 处理 SearchText 模糊搜索
if (!string.IsNullOrWhiteSpace(options.SearchText))
{
items = items.Where(item => (item.Name?.Contains(options.SearchText) ?? false)
|| (item.ProductionGroup?.Contains(options.SearchText) ?? false)
|| (item.GameNickname?.Contains(options.SearchText) ?? false)
|| (item.Tags?.Contains(options.SearchText) ?? false)
|| (item.GamePlatforms?.Contains(options.SearchText) ?? false));
}
}
// 过滤
var isFiltered = false;
if (options.Filters.Any())
{
items = items.Where(options.Filters.GetFilterFunc<BasicInforTableModel>());
isFiltered = true;
}
// 排序
var isSorted = false;
if (!string.IsNullOrWhiteSpace(options.SortName))
{
// 外部未进行排序,内部自动进行排序处理
var invoker = SortLambdaCacheBasic.GetOrAdd(typeof(BasicInforTableModel), key => LambdaExtensions.GetSortLambda<BasicInforTableModel>().Compile());
items = invoker(items, options.SortName, (BootstrapBlazor.Components.SortOrder)options.SortOrder);
isSorted = true;
}
// 设置记录总数
var total = items.Count();
// 内存分页
items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();
return Task.FromResult(new QueryData<BasicInforTableModel>()
{
Items = items,
TotalCount = total,
IsSorted = isSorted,
IsFiltered = isFiltered
});
}
}