feat(wpf): 添加Ploss和Qfod数据表格视图
This commit is contained in:
@@ -2,6 +2,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Windows;
|
||||
using WCTDataMiner.Core.Services;
|
||||
using WCTDataMiner.Wpf.Messages;
|
||||
|
||||
@@ -12,7 +13,9 @@ namespace WCTDataMiner.Wpf.ViewModels;
|
||||
/// </summary>
|
||||
public partial class MainViewModel : ObservableObject,
|
||||
IRecipient<NavigateToPlossChartMessage>,
|
||||
IRecipient<NavigateToQfodChartMessage>
|
||||
IRecipient<NavigateToQfodChartMessage>,
|
||||
IRecipient<NavigateToPlossTableMessage>,
|
||||
IRecipient<NavigateToQfodTableMessage>
|
||||
{
|
||||
private readonly ImportViewModel _importViewModel;
|
||||
private readonly ScenarioListViewModel _scenarioListViewModel;
|
||||
@@ -59,6 +62,8 @@ public partial class MainViewModel : ObservableObject,
|
||||
// 注册导航消息订阅
|
||||
WeakReferenceMessenger.Default.Register<NavigateToPlossChartMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<NavigateToQfodChartMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<NavigateToPlossTableMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<NavigateToQfodTableMessage>(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,9 +125,12 @@ public partial class MainViewModel : ObservableObject,
|
||||
/// </summary>
|
||||
public void Receive(NavigateToPlossChartMessage message)
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<PlossChartViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<PlossChartViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -130,8 +138,37 @@ public partial class MainViewModel : ObservableObject,
|
||||
/// </summary>
|
||||
public void Receive(NavigateToQfodChartMessage message)
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<QfodChartViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<QfodChartViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收导航到 Ploss 表格消息
|
||||
/// </summary>
|
||||
public void Receive(NavigateToPlossTableMessage message)
|
||||
{
|
||||
Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<PlossTableViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收导航到 Qfod 表格消息
|
||||
/// </summary>
|
||||
public void Receive(NavigateToQfodTableMessage message)
|
||||
{
|
||||
Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<QfodTableViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
});
|
||||
}
|
||||
}
|
||||
87
src/WCTDataMiner.Wpf/ViewModels/PlossTableViewModel.cs
Normal file
87
src/WCTDataMiner.Wpf/ViewModels/PlossTableViewModel.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using WCTDataMiner.Core.Models;
|
||||
using WCTDataMiner.Core.Services;
|
||||
using WCTDataMiner.Wpf.Messages;
|
||||
|
||||
namespace WCTDataMiner.Wpf.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Ploss 数据表格 ViewModel
|
||||
/// </summary>
|
||||
public partial class PlossTableViewModel : ObservableObject
|
||||
{
|
||||
private readonly ScenarioService _scenarioService;
|
||||
private readonly ILogger<PlossTableViewModel> _logger;
|
||||
|
||||
[ObservableProperty]
|
||||
private Guid _scenarioId;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<PlossRecord> _records = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLoading;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _loadingMessage = "";
|
||||
|
||||
public PlossTableViewModel(
|
||||
ScenarioService scenarioService,
|
||||
ILogger<PlossTableViewModel> logger)
|
||||
{
|
||||
_scenarioService = scenarioService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ScenarioId 属性变更时自动触发数据加载
|
||||
/// </summary>
|
||||
partial void OnScenarioIdChanged(Guid value)
|
||||
{
|
||||
if (value != Guid.Empty)
|
||||
{
|
||||
_ = LoadDataAsync().ContinueWith(t =>
|
||||
{
|
||||
if (t.Exception != null)
|
||||
{
|
||||
_logger.LogError(t.Exception, "LoadDataAsync 失败: ScenarioId={ScenarioId}", value);
|
||||
}
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoadDataAsync()
|
||||
{
|
||||
if (IsLoading) return; // 防并发
|
||||
|
||||
IsLoading = true;
|
||||
LoadingMessage = "正在加载数据...";
|
||||
|
||||
try
|
||||
{
|
||||
var records = await _scenarioService.GetPlossRecordsByScenarioIdAsync(ScenarioId);
|
||||
Records = new ObservableCollection<PlossRecord>(records);
|
||||
_logger.LogInformation("加载 Ploss 表格数据成功: ScenarioId={ScenarioId}, 记录数={Count}", ScenarioId, records.Count);
|
||||
LoadingMessage = "";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "加载 Ploss 表格数据失败: ScenarioId={ScenarioId}", ScenarioId);
|
||||
LoadingMessage = $"加载失败: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void SwitchToChart()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateToPlossChartMessage(ScenarioId));
|
||||
}
|
||||
}
|
||||
87
src/WCTDataMiner.Wpf/ViewModels/QfodTableViewModel.cs
Normal file
87
src/WCTDataMiner.Wpf/ViewModels/QfodTableViewModel.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using WCTDataMiner.Core.Models;
|
||||
using WCTDataMiner.Core.Services;
|
||||
using WCTDataMiner.Wpf.Messages;
|
||||
|
||||
namespace WCTDataMiner.Wpf.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Qfod 数据表格 ViewModel
|
||||
/// </summary>
|
||||
public partial class QfodTableViewModel : ObservableObject
|
||||
{
|
||||
private readonly ScenarioService _scenarioService;
|
||||
private readonly ILogger<QfodTableViewModel> _logger;
|
||||
|
||||
[ObservableProperty]
|
||||
private Guid _scenarioId;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<QfodRecord> _records = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLoading;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _loadingMessage = "";
|
||||
|
||||
public QfodTableViewModel(
|
||||
ScenarioService scenarioService,
|
||||
ILogger<QfodTableViewModel> logger)
|
||||
{
|
||||
_scenarioService = scenarioService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ScenarioId 属性变更时自动触发数据加载
|
||||
/// </summary>
|
||||
partial void OnScenarioIdChanged(Guid value)
|
||||
{
|
||||
if (value != Guid.Empty)
|
||||
{
|
||||
_ = LoadDataAsync().ContinueWith(t =>
|
||||
{
|
||||
if (t.Exception != null)
|
||||
{
|
||||
_logger.LogError(t.Exception, "LoadDataAsync 失败: ScenarioId={ScenarioId}", value);
|
||||
}
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoadDataAsync()
|
||||
{
|
||||
if (IsLoading) return; // 防并发
|
||||
|
||||
IsLoading = true;
|
||||
LoadingMessage = "正在加载数据...";
|
||||
|
||||
try
|
||||
{
|
||||
var records = await _scenarioService.GetQfodRecordsByScenarioIdAsync(ScenarioId);
|
||||
Records = new ObservableCollection<QfodRecord>(records);
|
||||
_logger.LogInformation("加载 Qfod 表格数据成功: ScenarioId={ScenarioId}, 记录数={Count}", ScenarioId, records.Count);
|
||||
LoadingMessage = "";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "加载 Qfod 表格数据失败: ScenarioId={ScenarioId}", ScenarioId);
|
||||
LoadingMessage = $"加载失败: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void SwitchToChart()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateToQfodChartMessage(ScenarioId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user