2025-06-24 20:48:38 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-06-25 22:33:57 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
2025-06-26 19:36:27 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
2025-06-24 20:48:38 +08:00
|
|
|
|
using PMSWPF.Data.Entities;
|
|
|
|
|
|
using PMSWPF.Data.Repositories;
|
2025-06-28 19:32:51 +08:00
|
|
|
|
using PMSWPF.Enums;
|
2025-06-26 19:36:27 +08:00
|
|
|
|
using PMSWPF.Message;
|
2025-06-25 22:33:57 +08:00
|
|
|
|
using PMSWPF.Models;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
using PMSWPF.Services;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
namespace PMSWPF.ViewModels;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
public partial class MainViewModel : ViewModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly NavgatorServices _navgatorServices;
|
2025-06-28 19:32:51 +08:00
|
|
|
|
private readonly DataServices _dataServices;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
[ObservableProperty] private ViewModelBase currentViewModel;
|
2025-06-24 20:48:38 +08:00
|
|
|
|
[ObservableProperty]
|
2025-06-25 22:33:57 +08:00
|
|
|
|
private ObservableCollection<MenuBean> _menus;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-26 19:36:27 +08:00
|
|
|
|
private readonly MenuRepository _menuRepository;
|
|
|
|
|
|
|
2025-06-28 19:32:51 +08:00
|
|
|
|
public MainViewModel(NavgatorServices navgatorServices,DataServices dataServices)
|
2025-06-23 17:01:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
_navgatorServices = navgatorServices;
|
2025-06-28 19:32:51 +08:00
|
|
|
|
_dataServices = dataServices;
|
|
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
_navgatorServices.OnViewModelChanged += () => { CurrentViewModel = _navgatorServices.CurrentViewModel; };
|
|
|
|
|
|
CurrentViewModel = new HomeViewModel();
|
2025-06-24 20:48:38 +08:00
|
|
|
|
CurrentViewModel.OnLoaded();
|
2025-06-26 19:36:27 +08:00
|
|
|
|
|
2025-06-28 19:32:51 +08:00
|
|
|
|
WeakReferenceMessenger.Default.Send<LoadMessage>(new LoadMessage(LoadTypes.Menu));
|
|
|
|
|
|
dataServices.OnMenuListChanged += (menus) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Menus = new ObservableCollection<MenuBean>(menus);
|
|
|
|
|
|
};
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-26 19:36:27 +08:00
|
|
|
|
}
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-25 22:33:57 +08:00
|
|
|
|
|
2025-06-28 19:32:51 +08:00
|
|
|
|
public override void OnLoaded()
|
2025-06-26 19:36:27 +08:00
|
|
|
|
{
|
2025-06-28 19:32:51 +08:00
|
|
|
|
|
2025-05-29 08:58:58 +08:00
|
|
|
|
}
|
2025-06-23 17:01:06 +08:00
|
|
|
|
}
|