Index.razor
3.25 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@page "/Basic/Communication"
@using System.Text.Json;
@using AntDesign.TableModels
@using System.ComponentModel
@using DataAcquisition.DataAccess
@using DataAcquisition.Models
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DataContext> dbContextFactory;
<Flex Justify="space-between" Align="center">
<Flex Justify="flex-start" Align="center" Gap="small">
<AntDesign.Input DefaultValue="@("mysite")">
<AddOnBefore>编号</AddOnBefore>
</AntDesign.Input>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Search">搜索</Button>
<Button Type="@ButtonType.Default" Icon="@IconType.Outline.Redo">重置</Button>
</Flex>
<Flex Justify="flex-end" Align="center" Gap="small">
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.CloudUpload">新增</Button>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete" Danger>批量删除</Button>
</Flex>
</Flex>
<Table @ref="table"
TItem="CommunicationConfig"
DataSource="@communicationConfigs"
Total="_total"
@bind-PageIndex="_pageIndex"
@bind-PageSize="_pageSize"
@bind-SelectedRows="selectedRows"
OnChange="OnChange"
Loading="loading"
Size="TableSize.Small"
RowKey="x=>x.Id">
<Selection Key="@(context.Id.ToString())" />
<PropertyColumn Property="c=>c.Id" Hidden 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" />
<ActionColumn Title="操作">
<Space>
<SpaceItem>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Edit" Size="@ButtonSize.Small">修改</Button>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete" Size="@ButtonSize.Small" Danger>删除</Button>
</SpaceItem>
</Space>
</ActionColumn>
</Table>
@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;
}
}