83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using DM_Weight.Common;
|
|
using DM_Weight.Models;
|
|
using DM_Weight.util;
|
|
using Prism.Commands;
|
|
using Prism.Common;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
public class SettingMainWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
|
|
{
|
|
//设置页面数据集
|
|
private ObservableCollection<SettingPage> _settingPages;
|
|
public ObservableCollection<SettingPage> SettingPages
|
|
{
|
|
get => _settingPages;
|
|
set => SetProperty(ref _settingPages, value);
|
|
}
|
|
//默认加载页面
|
|
string defaultView = string.Empty;
|
|
|
|
IRegionManager _regionManager;
|
|
|
|
public SettingMainWindowViewModel(IRegionManager regionManager)
|
|
{
|
|
this._regionManager = regionManager;
|
|
}
|
|
//选中事件
|
|
public DelegateCommand<string> NavigateCommand { get => new DelegateCommand<string>(navigateAction); }
|
|
|
|
public bool KeepAlive => false;
|
|
|
|
private void navigateAction(string obj)
|
|
{
|
|
if (obj == null || string.IsNullOrWhiteSpace(obj))
|
|
{
|
|
return;
|
|
}
|
|
defaultView = obj;
|
|
_regionManager.RequestNavigate(PrismManager.SettingViewRegionName, defaultView);
|
|
}
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
{
|
|
}
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
{
|
|
if (SettingPages is null || SettingPages.Count <= 0)
|
|
{
|
|
if (Convert.ToInt32(ConfigurationManager.AppSettings["hasFridge"]) <= 1)
|
|
{
|
|
SettingPages = new ObservableCollection<SettingPage>(SqlSugarHelper.Db.Queryable<SettingPage>().Where(p=>p.Id!="2").ToList());
|
|
}
|
|
else
|
|
{
|
|
SettingPages = new ObservableCollection<SettingPage>(SqlSugarHelper.Db.Queryable<SettingPage>().Where(p => p.Id != "3").ToList());
|
|
}
|
|
if (SettingPages.Count > 0)
|
|
{
|
|
if (string.IsNullOrEmpty(defaultView))
|
|
{
|
|
defaultView = SettingPages[0].ViewName;
|
|
}
|
|
_regionManager.RequestNavigate(PrismManager.SettingViewRegionName, defaultView);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|