2025-06-24 20:48:38 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-07-13 16:22:07 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
2025-07-26 10:05:43 +08:00
|
|
|
|
using DMS.Core.Enums;
|
|
|
|
|
|
using DMS.Core.Models;
|
|
|
|
|
|
using DMS.WPF.Helper;
|
2025-09-03 18:22:01 +08:00
|
|
|
|
using DMS.WPF.Interfaces;
|
2025-09-04 17:29:24 +08:00
|
|
|
|
using DMS.WPF.Services;
|
2025-10-06 18:17:56 +08:00
|
|
|
|
using DMS.WPF.ItemViewModel;
|
2025-09-04 17:29:24 +08:00
|
|
|
|
using DMS.WPF.Views;
|
2025-07-02 12:01:20 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-07-16 18:39:00 +08:00
|
|
|
|
|
2025-07-16 19:37:13 +08:00
|
|
|
|
// AddAsync this using directive
|
|
|
|
|
|
// AddAsync this using directive
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-07-19 11:11:01 +08:00
|
|
|
|
namespace DMS.WPF.ViewModels;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
|
2025-07-03 15:03:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 主视图模型,负责应用程序的主导航和数据管理。
|
|
|
|
|
|
/// </summary>
|
2025-06-23 17:01:06 +08:00
|
|
|
|
public partial class MainViewModel : ViewModelBase
|
|
|
|
|
|
{
|
2025-07-02 12:01:20 +08:00
|
|
|
|
private readonly IDialogService _dialogService;
|
2025-09-09 13:35:16 +08:00
|
|
|
|
private readonly IWPFDataService _wpfDataService;
|
2025-10-20 19:39:17 +08:00
|
|
|
|
private readonly IWpfDataService _dataStorageService;
|
2025-07-26 18:58:52 +08:00
|
|
|
|
private readonly INavigationService _navigationService;
|
2025-07-02 12:01:20 +08:00
|
|
|
|
private readonly ILogger<MainViewModel> _logger;
|
2025-06-26 19:36:27 +08:00
|
|
|
|
|
2025-07-03 15:03:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前显示的视图模型。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2025-07-26 18:58:52 +08:00
|
|
|
|
private ViewModelBase _currentViewModel;
|
2025-07-02 12:01:20 +08:00
|
|
|
|
|
2025-07-03 15:03:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 应用程序的菜单列表。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private ObservableCollection<MenuItem> _menuTrees;
|
2025-07-03 15:03:36 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化 <see cref="MainViewModel"/> 类的新实例。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="navgatorServices">导航服务。</param>
|
|
|
|
|
|
/// <param name="dataServices">数据服务。</param>
|
|
|
|
|
|
/// <param name="dialogService">对话框服务。</param>
|
|
|
|
|
|
/// <param name="logger">日志记录器。</param>
|
2025-09-09 13:35:16 +08:00
|
|
|
|
/// <param name="wpfDataService"></param>
|
2025-10-20 19:39:17 +08:00
|
|
|
|
public MainViewModel(IWPFDataService wpfDataService ,IWpfDataService dataStorageService,INavigationService navigationService,
|
2025-07-26 10:05:43 +08:00
|
|
|
|
ILogger<MainViewModel> logger)
|
2025-06-23 17:01:06 +08:00
|
|
|
|
{
|
2025-09-09 13:35:16 +08:00
|
|
|
|
_wpfDataService = wpfDataService;
|
|
|
|
|
|
_dataStorageService = dataStorageService;
|
2025-07-26 18:58:52 +08:00
|
|
|
|
_navigationService = navigationService;
|
2025-07-02 12:01:20 +08:00
|
|
|
|
_logger = logger;
|
2025-09-09 13:35:16 +08:00
|
|
|
|
MenuTrees = _dataStorageService.MenuTrees;
|
2025-06-28 19:32:51 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
CurrentViewModel = new HomeViewModel();
|
2025-06-24 20:48:38 +08:00
|
|
|
|
CurrentViewModel.OnLoaded();
|
2025-07-02 12:01:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-07 14:01:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 显示主窗口的命令。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
|
private void ShowWindow()
|
|
|
|
|
|
{
|
2025-08-24 18:29:26 +08:00
|
|
|
|
if (App.Current.MainWindow is MainView mainWindow)
|
|
|
|
|
|
{
|
|
|
|
|
|
mainWindow.ShowApplication();
|
|
|
|
|
|
}
|
2025-07-07 14:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 退出应用程序的命令。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
|
private void ExitApplication()
|
|
|
|
|
|
{
|
2025-07-26 10:05:43 +08:00
|
|
|
|
// Application.Current.Shutdown();
|
2025-07-07 14:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-03 15:03:36 +08:00
|
|
|
|
|
2025-10-03 22:28:58 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
}
|