WorkpieceModelPage.razor
1.74 KB
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
@page "/Basic/WorkpieceModel"
@using System.Text.Json;
@using AntDesign.TableModels
@using System.ComponentModel
@using DataAcquisitionServer.DataAccess
@using DataAcquisitionServer.Models
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DataContext> dbContextFactory;
<Spin Spinning="loading">
<Table @ref="table"
TItem="WorkpieceModel"
DataSource="@dataItems"
Total="_total"
@bind-PageIndex="_pageIndex"
@bind-PageSize="_pageSize"
OnChange="OnChange"
Size="TableSize.Small"
RowKey="x=>x.Id">
<PropertyColumn Property="c=>c.Id" />
<PropertyColumn Title="编号" Property="c=>c.Code" />
<PropertyColumn Title="名称" Property="c=>c.Name" />
<PropertyColumn Title="标识" Property="c=>c.Flag" />
<PropertyColumn Title="备注" Property="c=>c.Remark" />
</Table>
</Spin>
@code {
bool loading = true;
List<WorkpieceModel> dataItems = new List<WorkpieceModel>();
IEnumerable<WorkpieceModel> selectedRows = null!;
ITable table = null!;
int _pageIndex = 1;
int _pageSize = 10;
int _total = 0;
public async Task OnChange(QueryModel<WorkpieceModel> queryModel)
{
loading = true;
using var dbContext = dbContextFactory.CreateDbContext();
var query = dbContext.WorkpieceModels;
dataItems = await query.OrderBy(x => x.Id).Skip(((queryModel.PageIndex - 1) * queryModel.PageSize)).Take(queryModel.PageSize).AsNoTracking().ToListAsync();
_total = await query.CountAsync();
loading = false;
}
public void RemoveSelection(int id)
{
var selected = selectedRows.Where(x => x.Id != id);
selectedRows = selected;
}
}