终端一体化运控平台
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.
 
 
 

138 lines
5.4 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 System.Windows.Media;
  10. using BPASmartClient.CustomResource.Pages.Model;
  11. using BPASmartClient.Helper;
  12. using BPASmartClient.Model;
  13. using Microsoft.Toolkit.Mvvm.ComponentModel;
  14. using Microsoft.Toolkit.Mvvm.Input;
  15. namespace BPASmartClient.CustomResource.Pages.ViewModel
  16. {
  17. public class MainViewModel : ObservableObject
  18. {
  19. public MainViewModel()
  20. {
  21. NavChangedCommand = new RelayCommand<object>(DoNavChanged);
  22. BPA.Helper.MessageLog.GetInstance.NotifyShow = new Action<string>((o) =>
  23. {
  24. Application.Current?.Dispatcher?.Invoke(() =>
  25. {
  26. //ff20aefe
  27. var temp = new MessageModel()
  28. {
  29. LogInfo = o,
  30. Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254))
  31. };
  32. if (DebugLogViewModel.MessageModels.Count > 0)
  33. DebugLogViewModel.MessageModels.Insert(0, temp);
  34. else
  35. DebugLogViewModel.MessageModels.Add(temp);
  36. });
  37. });
  38. BPA.Helper.MessageLog.GetInstance.NotifyShowEx = new Action<string>((o) =>
  39. {
  40. Application.Current?.Dispatcher?.Invoke(() =>
  41. {
  42. //FFF53F62
  43. var temp = new MessageModel()
  44. {
  45. LogInfo = o,
  46. Forground = new SolidColorBrush(Color.FromArgb(255, 245, 63, 98))
  47. };
  48. if (DebugLogViewModel.MessageModels.Count > 0)
  49. DebugLogViewModel.MessageModels.Insert(0, temp);
  50. else
  51. DebugLogViewModel.MessageModels.Add(temp);
  52. });
  53. });
  54. menuModels = MenuManage.GetInstance.menuModels;
  55. PermissionChange();
  56. ActionManage.GetInstance.Register(new Action(() =>
  57. {
  58. PermissionChange();
  59. }), "PermissionChange");
  60. }
  61. private void PermissionChange()
  62. {
  63. int MainIndex = Array.FindIndex(menuModels.ToArray(), P => P.MainMenuVisibility == Visibility.Visible);
  64. if (MainIndex >= 0 && MainIndex < menuModels.Count)
  65. {
  66. int SubIndex; SubIndex = Array.FindIndex(menuModels.ElementAt(MainIndex).subMenumodels.ToArray(), p => p.SubMenuVisibility == Visibility.Visible);
  67. if (SubIndex >= 0 && SubIndex < menuModels.ElementAt(MainIndex).subMenumodels.Count)
  68. {
  69. //DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex).ToggleWindowPath);
  70. DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex));
  71. }
  72. }
  73. }
  74. public ObservableCollection<MenuModel> menuModels { get; set; }
  75. private void DoNavChanged(object obj)
  76. {
  77. if (obj != null && obj is SubMenumodel menumodel)
  78. {
  79. DisplayName = menumodel.SubMenuName;
  80. var end = menumodel.AssemblyName.Substring(menumodel.AssemblyName.Length - 1);
  81. var start = menumodel.ToggleWindowPath.Substring(0, 1);
  82. bool isAddPoint = end != "." && start != ".";
  83. string point = isAddPoint ? "." : "";
  84. Type type = Assembly.Load(menumodel.AssemblyName)?.GetType($"{menumodel.AssemblyName}{point}{menumodel.ToggleWindowPath}");
  85. ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  86. if (type?.BaseType.Name == "Window") ((Window)cti?.Invoke(null)).ShowDialog();
  87. else if (type?.BaseType.Name == "UserControl")
  88. {
  89. MainContent = null;
  90. MainContent = (FrameworkElement)cti?.Invoke(null);
  91. MainContent?.GetType()?.GetProperty("Name").SetValue(MainContent, menumodel.SubMenuName);
  92. }
  93. }
  94. }
  95. private bool _status;
  96. /// <summary>
  97. /// 设备初始化状态
  98. /// </summary>
  99. public bool Status
  100. {
  101. get { return _status; }
  102. set
  103. {
  104. if (value)
  105. {
  106. ActionManage.GetInstance.Send("StartPlcInite");
  107. }
  108. else
  109. {
  110. ActionManage.GetInstance.Send("EndPlcInite");
  111. }
  112. _status = value;
  113. OnPropertyChanged();
  114. }
  115. }
  116. /// <summary>
  117. /// 开机自启
  118. /// </summary>
  119. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  120. public RelayCommand<object> NavChangedCommand { get; set; }
  121. public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
  122. private FrameworkElement _mMainContent;
  123. public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
  124. private string _mDisplayName;
  125. }
  126. }