修改了历史记录页面
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using AutoMapper;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -38,7 +39,7 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
/// 建议的变量列表
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private List<VariableHistoryDto> _suggestedVariables;
|
||||
private ObservableCollection<VariableHistoryDto> _suggestedVariables;
|
||||
|
||||
/// <summary>
|
||||
/// 历史记录条数限制
|
||||
@@ -58,6 +59,12 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
[ObservableProperty]
|
||||
private DateTime? _endTime;
|
||||
|
||||
/// <summary>
|
||||
/// 选中的变量历史记录
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private VariableHistoryDto _selectedVariable;
|
||||
|
||||
/// <summary>
|
||||
/// 变量历史记录列表
|
||||
/// </summary>
|
||||
@@ -85,12 +92,13 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
_variableHistorySynchronizedView = _variableHistoryList.CreateView(v => v);
|
||||
VariableHistories = _variableHistorySynchronizedView.ToNotifyCollectionChanged();
|
||||
_allVariableHistories = new List<VariableHistoryDto>();
|
||||
_suggestedVariables = new List<VariableHistoryDto>();
|
||||
_suggestedVariables = new ObservableCollection<VariableHistoryDto>();
|
||||
|
||||
// 初始化默认值
|
||||
_historyLimit = 1000; // 默认限制1000条记录
|
||||
_startTime = null;
|
||||
_endTime = null;
|
||||
_selectedVariable = new VariableHistoryDto();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,19 +131,27 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
/// </summary>
|
||||
private void UpdateSuggestedVariables()
|
||||
{
|
||||
// 清空现有建议列表
|
||||
_suggestedVariables.Clear();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(SearchText))
|
||||
{
|
||||
// 如果搜索文本为空,显示所有唯一的变量名
|
||||
_suggestedVariables = _allVariableHistories
|
||||
var uniqueVariables = _allVariableHistories
|
||||
.GroupBy(h => h.VariableName)
|
||||
.Select(g => g.First())
|
||||
.Take(10)
|
||||
.ToList();
|
||||
|
||||
foreach (var variable in uniqueVariables)
|
||||
{
|
||||
_suggestedVariables.Add(variable);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 根据搜索文本过滤建议列表
|
||||
_suggestedVariables = _allVariableHistories
|
||||
var filteredVariables = _allVariableHistories
|
||||
.Where(h =>
|
||||
h.VariableName?.Contains(SearchText, StringComparison.OrdinalIgnoreCase) ==
|
||||
true)
|
||||
@@ -143,12 +159,40 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
.Select(g => g.First())
|
||||
.Take(10)
|
||||
.ToList();
|
||||
|
||||
foreach (var variable in filteredVariables)
|
||||
{
|
||||
_suggestedVariables.Add(variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnNavigatedToAsync(MenuItemViewModel menu)
|
||||
{
|
||||
// 加载所有变量的历史记录
|
||||
LoadAllVariableHistories(HistoryLimit, StartTime, EndTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索变量历史记录
|
||||
/// 重新加载历史记录命令
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void Reload()
|
||||
{
|
||||
LoadAllVariableHistories(HistoryLimit, StartTime, EndTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新建议列表命令
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void UpdateSuggestions()
|
||||
{
|
||||
UpdateSuggestedVariables();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当搜索文本改变时触发
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
partial void OnSearchTextChanged(string value)
|
||||
@@ -156,7 +200,7 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
// 更新建议列表
|
||||
UpdateSuggestedVariables();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(SearchText))
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
// 如果搜索文本为空,显示所有历史记录
|
||||
_variableHistoryList.Clear();
|
||||
@@ -168,7 +212,7 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
var filteredHistories = _allVariableHistories
|
||||
.Where(h =>
|
||||
h.VariableName?.Contains(
|
||||
SearchText, StringComparison.OrdinalIgnoreCase) == true)
|
||||
value, StringComparison.OrdinalIgnoreCase) == true)
|
||||
.ToList();
|
||||
|
||||
_variableHistoryList.Clear();
|
||||
@@ -176,10 +220,30 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnNavigatedToAsync(MenuItemViewModel menu)
|
||||
/// <summary>
|
||||
/// 根据搜索文本过滤历史记录
|
||||
/// </summary>
|
||||
/// <param name="searchText"></param>
|
||||
private void FilterHistoriesBySearchText(string searchText)
|
||||
{
|
||||
// 加载所有变量的历史记录
|
||||
LoadAllVariableHistories(HistoryLimit, StartTime, EndTime);
|
||||
if (string.IsNullOrWhiteSpace(searchText))
|
||||
{
|
||||
// 如果搜索文本为空,显示所有历史记录
|
||||
_variableHistoryList.Clear();
|
||||
_variableHistoryList.AddRange(_allVariableHistories);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 根据搜索文本过滤历史记录
|
||||
var filteredHistories = _allVariableHistories
|
||||
.Where(h =>
|
||||
h.VariableName?.Contains(
|
||||
searchText, StringComparison.OrdinalIgnoreCase) == true)
|
||||
.ToList();
|
||||
|
||||
_variableHistoryList.Clear();
|
||||
_variableHistoryList.AddRange(filteredHistories);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:enums="clr-namespace:DMS.Core.Enums;assembly=DMS.Core"
|
||||
xmlns:ex="clr-namespace:DMS.Extensions"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:helper="clr-namespace:DMS.WPF.Helper"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
@@ -48,6 +49,7 @@
|
||||
Spacing="10">
|
||||
<TextBlock Style="{StaticResource VarHistoryLabelStyle}" Text="搜索变量:" />
|
||||
<ui:AutoSuggestBox
|
||||
x:Name="SearchAutoSuggestBox"
|
||||
Width="200"
|
||||
ui:ControlHelper.PlaceholderText="搜索变量..."
|
||||
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
|
||||
@@ -58,6 +60,48 @@
|
||||
</ikw:SimpleStackPanel>
|
||||
</ikw:SimpleStackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 时间范围和详细信息区域 -->
|
||||
<GroupBox Header="详细信息">
|
||||
<ikw:SimpleStackPanel Margin="5" Spacing="10">
|
||||
<!-- 变量详细信息 -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Style="{StaticResource VarHistoryLabelStyle}" Text="变量ID:" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Style="{StaticResource VarHistoryValueStyle}" Text="{Binding SelectedVariable.Id}" />
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" Style="{StaticResource VarHistoryLabelStyle}" Text="变量名:" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="3" Style="{StaticResource VarHistoryValueStyle}" Text="{Binding SelectedVariable.VariableName}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Style="{StaticResource VarHistoryLabelStyle}" Text="当前值:" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Style="{StaticResource VarHistoryValueStyle}" Text="{Binding SelectedVariable.Value}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="2" Style="{StaticResource VarHistoryLabelStyle}" Text="更新时间:" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="3" Style="{StaticResource VarHistoryValueStyle}" Text="{Binding SelectedVariable.Timestamp, StringFormat='{}{0:yyyy-MM-dd HH:mm:ss.fff}'}" />
|
||||
</Grid>
|
||||
|
||||
<!-- 时间范围选择 -->
|
||||
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
||||
<TextBlock Style="{StaticResource VarHistoryLabelStyle}" Text="开始时间:" />
|
||||
<hc:DateTimePicker Width="200" SelectedDateTime="{Binding StartTime}" />
|
||||
|
||||
<TextBlock Style="{StaticResource VarHistoryLabelStyle}" Text="结束时间:" />
|
||||
<hc:DateTimePicker Width="200" SelectedDateTime="{Binding EndTime}" />
|
||||
|
||||
<Button Content="重新加载" Command="{Binding ReloadCommand}" />
|
||||
</ikw:SimpleStackPanel>
|
||||
</ikw:SimpleStackPanel>
|
||||
</GroupBox>
|
||||
</ikw:SimpleStackPanel>
|
||||
|
||||
<DataGrid
|
||||
@@ -67,6 +111,7 @@
|
||||
CanUserSortColumns="False"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding VariableHistories}"
|
||||
SelectedItem="{Binding SelectedVariable}"
|
||||
SelectionMode="Single"
|
||||
Style="{StaticResource DataGridBaseStyle}">
|
||||
<DataGrid.Columns>
|
||||
|
||||
Reference in New Issue
Block a user