feat(wpf): 实现场景列表加载、筛选与消息导航功能
- ScenarioService新增筛选查询方法和动态筛选选项 - 使用WeakReferenceMessenger实现导入完成通知和导航消息 - ViewModel改为Singleton生命周期确保消息订阅正确工作 - 场景列表支持数据库加载和按维度筛选 - ScenarioId类型从int改为Guid Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WCTDataMiner.Core.Services;
|
||||
using WCTDataMiner.Wpf.Messages;
|
||||
|
||||
namespace WCTDataMiner.Wpf.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// 主窗口 ViewModel - 导航控制
|
||||
/// </summary>
|
||||
public partial class MainViewModel : ObservableObject
|
||||
public partial class MainViewModel : ObservableObject,
|
||||
IRecipient<NavigateToPlossChartMessage>,
|
||||
IRecipient<NavigateToQfodChartMessage>
|
||||
{
|
||||
private readonly ImportViewModel _importViewModel;
|
||||
private readonly ScenarioListViewModel _scenarioListViewModel;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableObject _currentView = null!;
|
||||
@@ -26,17 +33,48 @@ public partial class MainViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string? _selectedRxType;
|
||||
|
||||
// 筛选选项列表
|
||||
public List<string> TxPanels { get; } = new() { "全部", "singleMold", "dualMold" };
|
||||
public List<string> TxHardwares { get; } = new() { "全部", "v1.0", "v2.0" };
|
||||
public List<string> TxSoftwares { get; } = new() { "全部", "hex2_1", "hex2_2" };
|
||||
public List<string> RxTypes { get; } = new() { "全部", "iPhone15", "iPhone16", "Android" };
|
||||
// 筛选选项列表(动态加载)
|
||||
[ObservableProperty]
|
||||
private List<string> _txPanels = new() { FilterConstants.AllOption };
|
||||
|
||||
public MainViewModel(ImportViewModel importViewModel, ScenarioListViewModel scenarioListViewModel)
|
||||
[ObservableProperty]
|
||||
private List<string> _txHardwares = new() { FilterConstants.AllOption };
|
||||
|
||||
[ObservableProperty]
|
||||
private List<string> _txSoftwares = new() { FilterConstants.AllOption };
|
||||
|
||||
[ObservableProperty]
|
||||
private List<string> _rxTypes = new() { FilterConstants.AllOption };
|
||||
|
||||
public MainViewModel(
|
||||
ImportViewModel importViewModel,
|
||||
ScenarioListViewModel scenarioListViewModel,
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
_importViewModel = importViewModel;
|
||||
_scenarioListViewModel = scenarioListViewModel;
|
||||
_serviceProvider = serviceProvider;
|
||||
_currentView = _scenarioListViewModel;
|
||||
|
||||
// 注册导航消息订阅
|
||||
WeakReferenceMessenger.Default.Register<NavigateToPlossChartMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<NavigateToQfodChartMessage>(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载场景数据和筛选选项
|
||||
/// </summary>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
// 加载筛选选项
|
||||
var filterOptions = await _scenarioListViewModel.GetFilterOptionsAsync();
|
||||
TxPanels = filterOptions.TxPanels;
|
||||
TxHardwares = filterOptions.TxHardwares;
|
||||
TxSoftwares = filterOptions.TxSoftwares;
|
||||
RxTypes = filterOptions.RxTypes;
|
||||
|
||||
// 加载场景列表
|
||||
await _scenarioListViewModel.LoadScenariosAsync();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -46,20 +84,54 @@ public partial class MainViewModel : ObservableObject
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateToScenarios()
|
||||
private async Task NavigateToScenarios()
|
||||
{
|
||||
CurrentView = _scenarioListViewModel;
|
||||
await _scenarioListViewModel.LoadScenariosAsync();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateToPlossChart(int scenarioId)
|
||||
private void NavigateToPlossChart(Guid scenarioId)
|
||||
{
|
||||
CurrentView = new PlossChartViewModel { ScenarioId = scenarioId };
|
||||
var vm = _serviceProvider.GetRequiredService<PlossChartViewModel>();
|
||||
vm.ScenarioId = scenarioId;
|
||||
CurrentView = vm;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateToQfodChart(int scenarioId)
|
||||
private void NavigateToQfodChart(Guid scenarioId)
|
||||
{
|
||||
CurrentView = new QfodChartViewModel { ScenarioId = scenarioId };
|
||||
var vm = _serviceProvider.GetRequiredService<QfodChartViewModel>();
|
||||
vm.ScenarioId = scenarioId;
|
||||
CurrentView = vm;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用筛选条件并刷新场景列表
|
||||
/// </summary>
|
||||
public async Task ApplyFilterAsync()
|
||||
{
|
||||
await _scenarioListViewModel.LoadScenariosByFilterAsync(
|
||||
SelectedTxPanel, SelectedTxHardware, SelectedTxSoftware, SelectedRxType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收导航到 Ploss 图表消息
|
||||
/// </summary>
|
||||
public void Receive(NavigateToPlossChartMessage message)
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<PlossChartViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收导航到 Qfod 图表消息
|
||||
/// </summary>
|
||||
public void Receive(NavigateToQfodChartMessage message)
|
||||
{
|
||||
var vm = _serviceProvider.GetRequiredService<QfodChartViewModel>();
|
||||
vm.ScenarioId = message.ScenarioId;
|
||||
CurrentView = vm;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user