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-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-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-23 17:01:06 +08:00
|
|
|
|
public MainViewModel(NavgatorServices navgatorServices)
|
|
|
|
|
|
{
|
|
|
|
|
|
_navgatorServices = navgatorServices;
|
2025-06-26 19:36:27 +08:00
|
|
|
|
_menuRepository = new MenuRepository();
|
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
|
|
|
|
|
|
|
|
|
|
WeakReferenceMessenger.Default.Register<UpdateMenuMessage>( this,UpdateMenu);
|
|
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
}
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-26 19:36:27 +08:00
|
|
|
|
private async void UpdateMenu(object recipient, UpdateMenuMessage message)
|
|
|
|
|
|
{
|
|
|
|
|
|
await LoadMenu();
|
|
|
|
|
|
}
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-25 22:33:57 +08:00
|
|
|
|
|
2025-06-24 20:48:38 +08:00
|
|
|
|
public override async void OnLoaded()
|
2025-06-26 19:36:27 +08:00
|
|
|
|
{
|
|
|
|
|
|
await LoadMenu();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task LoadMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
var menuList= await _menuRepository.GetMenu();
|
|
|
|
|
|
Menus=new ObservableCollection<MenuBean>(menuList);
|
2025-05-29 08:58:58 +08:00
|
|
|
|
}
|
2025-06-23 17:01:06 +08:00
|
|
|
|
}
|