EquipmentPropteryIndex.razor
4.64 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
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
@using AntDesign.TableModels
@using DataAcquisition.Common.Utils
@using DataAcquisition.DataAccess
@using DataAcquisition.Models
@using DataAcquisition.Services
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DataContext> dbContextFactory;
@inject DataCacheService dataCacheService;
@inject IMessageService _message
<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="detailTable"
TItem="EquipmentProperty"
DataSource="@equipmentProperties"
Total="_detailTotal"
@bind-PageIndex="_detailPageIndex"
@bind-PageSize="_detailPageSize"
OnChange="EquipmentPropertyOnChange"
Size="TableSize.Small"
RowKey="x=>x.Id">
<Selection Key="@(context.Id.ToString())" />
<PropertyColumn Property="c=>c.Id" Hidden />
<PropertyColumn Title="编号" Property="c=>c.Code" />
<PropertyColumn Title="名称" Property="c=>c.Name" />
<PropertyColumn Title="数据地址" Property="c=>c.DataAddress" />
<PropertyColumn Title="数据类型" Property="c=>c.DataType" />
<PropertyColumn Title="值" Property="c=>c.Value" />
<PropertyColumn Title="是否启用" Property="c=>c.Enable">
<Switch @bind-Value="@context.Enable" Disabled="true"></Switch>
</PropertyColumn>
<PropertyColumn Title="备注" Property="c=>c.Remark" />
<PropertyColumn Title="创建时间" Property="c=>c.CreateTime" />
<PropertyColumn Title="更新时间" Property="c=>c.UpdateTime" />
<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 {
[Parameter]
public int EquipmentId { get; set; } = 0;
ITable detailTable = null!;
List<EquipmentProperty> equipmentProperties = new List<EquipmentProperty>();
int _detailPageIndex = 1;
int _detailPageSize = 10;
int _detailTotal = 0;
SystemLog log = SystemLog.Instance;
bool load = false;
protected override Task OnParametersSetAsync()
{
load = false;
_detailPageIndex = 1;
LoadEquipmentPropertyData(_detailPageIndex, _detailPageSize).Wait();
_ = InvokeAsync(async () =>
{
try
{
load = true;
do
{
var equipmentPropertiesCache = dataCacheService.Equipments.Find(x => x.Id == EquipmentId)?.EquipmentProperties.ToList() ?? new List<EquipmentProperty>();
foreach (var item in equipmentProperties)
{
var newItem = equipmentPropertiesCache.Find(x => x.Id == item.Id);
if (newItem is null) continue;
item.Value = newItem.Value ?? string.Empty;
item.UpdateTime = newItem.UpdateTime;
}
StateHasChanged();
await Task.Delay(1000);
} while (load);
}
catch (Exception ex)
{
log.LogError($"设备详细页面数据刷新异常:{ex.Message}");
}
});
return base.OnParametersSetAsync();
}
public async Task EquipmentPropertyOnChange(QueryModel<EquipmentProperty> queryModel)
{
await LoadEquipmentPropertyData(queryModel.PageIndex, queryModel.PageSize, queryModel.SortModel);
}
private Task LoadEquipmentPropertyData(int index, int size, IList<ITableSortModel>? sortModels = null)
{
return Task.Run(async () =>
{
using var dbContext = dbContextFactory.CreateDbContext();
var query = dbContext.EquipmentProperties.Where(x => x.EquipmentId == EquipmentId);
equipmentProperties = await query.OrderBy(x => x.Id).Skip(((index - 1) * size)).Take(size).AsNoTracking().ToListAsync();
_detailTotal = await query.CountAsync();
});
}
}