using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DMS.Core.Enums;
using DMS.Core.Models;
using DMS.WPF.Helper;
using DMS.WPF.Interfaces;
using DMS.WPF.Services;
using DMS.WPF.ViewModels.Items;
using DMS.WPF.Views;
using Microsoft.Extensions.Logging;
// AddAsync this using directive
// AddAsync this using directive
namespace DMS.WPF.ViewModels;
///
/// 主视图模型,负责应用程序的主导航和数据管理。
///
public partial class MainViewModel : ViewModelBase
{
private readonly IDialogService _dialogService;
private readonly IWPFDataService _wpfDataService;
private readonly IDataStorageService _dataStorageService;
private readonly INavigationService _navigationService;
private readonly ILogger _logger;
///
/// 当前显示的视图模型。
///
[ObservableProperty]
private ViewModelBase _currentViewModel;
///
/// 应用程序的菜单列表。
///
[ObservableProperty]
private ObservableCollection _menuTrees;
///
/// 初始化 类的新实例。
///
/// 导航服务。
/// 数据服务。
/// 对话框服务。
/// 日志记录器。
///
public MainViewModel(IWPFDataService wpfDataService ,IDataStorageService dataStorageService,INavigationService navigationService,
ILogger logger)
{
_wpfDataService = wpfDataService;
_dataStorageService = dataStorageService;
_navigationService = navigationService;
_logger = logger;
MenuTrees = _dataStorageService.MenuTrees;
CurrentViewModel = new HomeViewModel();
CurrentViewModel.OnLoaded();
}
///
/// 显示主窗口的命令。
///
[RelayCommand]
private void ShowWindow()
{
if (App.Current.MainWindow is MainView mainWindow)
{
mainWindow.ShowApplication();
}
}
///
/// 退出应用程序的命令。
///
[RelayCommand]
private void ExitApplication()
{
// Application.Current.Shutdown();
}
}