174 lines
5.3 KiB
C#
174 lines
5.3 KiB
C#
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;
|
|
|
|
namespace WCTDataMiner.Wpf.ViewModels;
|
|
|
|
/// <summary>
|
|
/// 主窗口 ViewModel - 导航控制
|
|
/// </summary>
|
|
public partial class MainViewModel : ObservableObject,
|
|
IRecipient<NavigateToPlossChartMessage>,
|
|
IRecipient<NavigateToQfodChartMessage>,
|
|
IRecipient<NavigateToPlossTableMessage>,
|
|
IRecipient<NavigateToQfodTableMessage>
|
|
{
|
|
private readonly ImportViewModel _importViewModel;
|
|
private readonly ScenarioListViewModel _scenarioListViewModel;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
[ObservableProperty]
|
|
private ObservableObject _currentView = null!;
|
|
|
|
[ObservableProperty]
|
|
private string? _selectedTxPanel;
|
|
|
|
[ObservableProperty]
|
|
private string? _selectedTxHardware;
|
|
|
|
[ObservableProperty]
|
|
private string? _selectedTxSoftware;
|
|
|
|
[ObservableProperty]
|
|
private string? _selectedRxType;
|
|
|
|
// 筛选选项列表(动态加载)
|
|
[ObservableProperty]
|
|
private List<string> _txPanels = new() { FilterConstants.AllOption };
|
|
|
|
[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);
|
|
WeakReferenceMessenger.Default.Register<NavigateToPlossTableMessage>(this);
|
|
WeakReferenceMessenger.Default.Register<NavigateToQfodTableMessage>(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]
|
|
private void NavigateToImport()
|
|
{
|
|
CurrentView = _importViewModel;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task NavigateToScenarios()
|
|
{
|
|
CurrentView = _scenarioListViewModel;
|
|
await _scenarioListViewModel.LoadScenariosAsync();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void NavigateToPlossChart(Guid scenarioId)
|
|
{
|
|
var vm = _serviceProvider.GetRequiredService<PlossChartViewModel>();
|
|
vm.ScenarioId = scenarioId;
|
|
CurrentView = vm;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void NavigateToQfodChart(Guid 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)
|
|
{
|
|
Application.Current.Dispatcher.InvokeAsync(() =>
|
|
{
|
|
var vm = _serviceProvider.GetRequiredService<PlossChartViewModel>();
|
|
vm.ScenarioId = message.ScenarioId;
|
|
CurrentView = vm;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接收导航到 Qfod 图表消息
|
|
/// </summary>
|
|
public void Receive(NavigateToQfodChartMessage message)
|
|
{
|
|
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;
|
|
});
|
|
}
|
|
} |