CommunicationPage.razor
2.31 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
58
59
60
61
62
63
@page "/Basic/Communication"
@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="CommunicationConfig"
DataSource="@communicationConfigs"
Total="_total"
@bind-PageIndex="_pageIndex"
@bind-PageSize="_pageSize"
@bind-SelectedRows="selectedRows"
OnChange="OnChange"
Size="TableSize.Small"
RowKey="x=>x.Id">
@* <Selection Key="@(context.Id.ToString())" /> *@
<PropertyColumn Property="c=>c.Id" Sortable />
<PropertyColumn Title="编号" Property="c=>c.Code"/>
<PropertyColumn Title="名称" Property="c=>c.Name" />
<PropertyColumn Title="通信方式" Property="c=>c.CommunicationType" />
<PropertyColumn Title="设备型号" Property="c=>c.EquipmentModel" />
<PropertyColumn Title="IP地址" Property="c=>c.IpAddress" />
<PropertyColumn Title="端口" Property="c=>c.Port" />
<PropertyColumn Title="是否启用" Property="c=>c.Enable">
<Switch @bind-Value="@context.Enable" Disabled="true"></Switch>
</PropertyColumn>
<PropertyColumn Title="备注" Property="c=>c.Remark" />
</Table>
</Spin>
@code {
bool loading = true;
List<CommunicationConfig> communicationConfigs = new List<CommunicationConfig>();
IEnumerable<CommunicationConfig> selectedRows = null!;
ITable table = null!;
int _pageIndex = 1;
int _pageSize = 10;
int _total = 0;
public async Task OnChange(QueryModel<CommunicationConfig> queryModel)
{
loading = true;
using var dbContext = dbContextFactory.CreateDbContext();
var query = dbContext.CommunicationConfigs;
communicationConfigs = 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;
}
}