131 lines
3.4 KiB
C#
131 lines
3.4 KiB
C#
using OrpaonEMS.App.Models;
|
|
using OrpaonEMS.App.Services;
|
|
using OrpaonEMS.Core;
|
|
using Prism.Commands;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Threading;
|
|
|
|
namespace OrpaonEMS.App.ViewModels
|
|
{
|
|
public class MainViewModel : NavigationViewModel
|
|
{
|
|
public MainViewModel(IRegionManager region, INavigationMenuService menuService)
|
|
{
|
|
this.region = region;
|
|
MenuService = menuService;
|
|
NavigateCommand = new DelegateCommand<NavigationItem>(Navigate);
|
|
|
|
DispatcherTimer timer = new DispatcherTimer();
|
|
timer.Interval = TimeSpan.FromSeconds(3);
|
|
timer.Tick += timer_Tick;
|
|
timer.Start();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 时间定时器
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private void timer_Tick(object? sender, EventArgs e)
|
|
{
|
|
CurrentTime=DateTime.Now;
|
|
}
|
|
|
|
|
|
public INavigationMenuService MenuService { get; }
|
|
|
|
public DelegateCommand<NavigationItem> NavigateCommand { get; private set; }
|
|
|
|
private int selectedIndex = -1;
|
|
|
|
public int SelectedIndex
|
|
{
|
|
get { return selectedIndex; }
|
|
set { selectedIndex = value; RaisePropertyChanged(); }
|
|
}
|
|
|
|
private bool isTopDrawerOpen;
|
|
private readonly IRegionManager region;
|
|
|
|
public bool IsTopDrawerOpen
|
|
{
|
|
get { return isTopDrawerOpen; }
|
|
set
|
|
{
|
|
isTopDrawerOpen = value;
|
|
if (SelectedIndex == 0 && !value)
|
|
SelectedIndex = -1;
|
|
RaisePropertyChanged();
|
|
}
|
|
}
|
|
|
|
private void Navigate(NavigationItem item)
|
|
{
|
|
if (item == null) return;
|
|
|
|
if (item.Name.Equals("全部"))
|
|
{
|
|
IsTopDrawerOpen = true;
|
|
return;
|
|
}
|
|
|
|
NavigatePage(item.PageName);
|
|
|
|
|
|
|
|
IsTopDrawerOpen = false;
|
|
}
|
|
|
|
private DateTime _CurrentTime=DateTime.Now;
|
|
/// <summary>
|
|
/// 当前时间
|
|
/// </summary>
|
|
public DateTime CurrentTime
|
|
{
|
|
get { return _CurrentTime; }
|
|
set
|
|
{
|
|
_CurrentTime = value;
|
|
RaisePropertyChanged();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 导航到页面信息
|
|
/// </summary>
|
|
/// <param name="pageName"></param>
|
|
private void NavigatePage(string pageName)
|
|
{
|
|
region.Regions["MainViewContentRegion"].RequestNavigate(pageName, back =>
|
|
{
|
|
if (!(bool)back.Result)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(back.Error.Message);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
public override void OnNavigatedTo(NavigationContext navigationContext)
|
|
{
|
|
MenuService.Initialize();
|
|
//region.Regions["MainViewContentRegion"].RequestNavigate("DashboardView", back =>
|
|
//{
|
|
// if (!(bool)back.Result)
|
|
// {
|
|
|
|
// }
|
|
//});
|
|
base.OnNavigatedTo(navigationContext);
|
|
}
|
|
}
|
|
}
|