终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
4.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using BPASmartClient.CustomResource.Pages.Model;
  10. using BPASmartClient.Helper;
  11. using BPASmartClient.Model;
  12. using Microsoft.Toolkit.Mvvm.ComponentModel;
  13. using Microsoft.Toolkit.Mvvm.Input;
  14. namespace BPASmartClient.CustomResource.Pages.ViewModel
  15. {
  16. public class MainViewModel : ObservableObject
  17. {
  18. public MainViewModel()
  19. {
  20. NavChangedCommand = new RelayCommand<object>(DoNavChanged);
  21. menuModels = MenuManage.GetInstance.menuModels;
  22. PermissionChange();
  23. ActionManage.GetInstance.Register(new Action(() =>
  24. {
  25. PermissionChange();
  26. }), "PermissionChange");
  27. }
  28. private void PermissionChange()
  29. {
  30. int MainIndex = Array.FindIndex(menuModels.ToArray(), P => P.MainMenuVisibility == Visibility.Visible);
  31. if (MainIndex >= 0 && MainIndex < menuModels.Count)
  32. {
  33. int SubIndex; SubIndex = Array.FindIndex(menuModels.ElementAt(MainIndex).subMenumodels.ToArray(), p => p.SubMenuVisibility == Visibility.Visible);
  34. if (SubIndex >= 0 && SubIndex < menuModels.ElementAt(MainIndex).subMenumodels.Count)
  35. {
  36. //DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex).ToggleWindowPath);
  37. DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex));
  38. }
  39. }
  40. }
  41. public ObservableCollection<MenuModel> menuModels { get; set; }
  42. private void DoNavChanged(object obj)
  43. {
  44. if (obj != null && obj is SubMenumodel menumodel)
  45. {
  46. DisplayName = menumodel.SubMenuName;
  47. var end = menumodel.AssemblyName.Substring(menumodel.AssemblyName.Length - 1);
  48. var start = menumodel.ToggleWindowPath.Substring(0, 1);
  49. bool isAddPoint = end != "." && start != ".";
  50. string point = isAddPoint ? "." : "";
  51. Type type = Assembly.Load(menumodel.AssemblyName)?.GetType($"{menumodel.AssemblyName}{point}{menumodel.ToggleWindowPath}");
  52. ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  53. if (type?.BaseType.Name == "Window") ((Window)cti?.Invoke(null)).ShowDialog();
  54. else if (type?.BaseType.Name == "UserControl")
  55. {
  56. MainContent = null;
  57. MainContent = (FrameworkElement)cti?.Invoke(null);
  58. MainContent?.GetType()?.GetProperty("Name").SetValue(MainContent, menumodel.SubMenuName);
  59. }
  60. }
  61. }
  62. private bool _status;
  63. /// <summary>
  64. /// 设备初始化状态
  65. /// </summary>
  66. public bool Status
  67. {
  68. get { return _status; }
  69. set
  70. {
  71. if (value)
  72. {
  73. ActionManage.GetInstance.Send("StartPlcInite");
  74. }
  75. else
  76. {
  77. ActionManage.GetInstance.Send("EndPlcInite");
  78. }
  79. _status = value;
  80. OnPropertyChanged();
  81. }
  82. }
  83. /// <summary>
  84. /// 开机自启
  85. /// </summary>
  86. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  87. public RelayCommand<object> NavChangedCommand { get; set; }
  88. public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
  89. private FrameworkElement _mMainContent;
  90. public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
  91. private string _mDisplayName;
  92. }
  93. }