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

172 lines
6.7 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. BPASmartClient.Message. MessageLog.GetInstance.InfoNotify = 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. BPASmartClient.Message.MessageLog.GetInstance.ExInfoNotify = 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. BPA.Helper.MessageLog.GetInstance.NotifyShow = new Action<string>((o) =>
  55. {
  56. Application.Current?.Dispatcher?.Invoke(() =>
  57. {
  58. //ff20aefe
  59. var temp = new MessageModel()
  60. {
  61. LogInfo = o,
  62. Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254))
  63. };
  64. if (DebugLogViewModel.MessageModels.Count > 0)
  65. DebugLogViewModel.MessageModels.Insert(0, temp);
  66. else
  67. DebugLogViewModel.MessageModels.Add(temp);
  68. });
  69. });
  70. BPA.Helper.MessageLog.GetInstance.NotifyShowEx = new Action<string>((o) =>
  71. {
  72. Application.Current?.Dispatcher?.Invoke(() =>
  73. {
  74. //FFF53F62
  75. var temp = new MessageModel()
  76. {
  77. LogInfo = o,
  78. Forground = new SolidColorBrush(Color.FromArgb(255, 245, 63, 98))
  79. };
  80. if (DebugLogViewModel.MessageModels.Count > 0)
  81. DebugLogViewModel.MessageModels.Insert(0, temp);
  82. else
  83. DebugLogViewModel.MessageModels.Add(temp);
  84. });
  85. });
  86. menuModels = MenuManage.GetInstance.menuModels;
  87. PermissionChange();
  88. ActionManage.GetInstance.Register(new Action(() =>
  89. {
  90. PermissionChange();
  91. }), "PermissionChange");
  92. }
  93. private void PermissionChange()
  94. {
  95. int MainIndex = Array.FindIndex(menuModels.ToArray(), P => P.MainMenuVisibility == Visibility.Visible);
  96. if (MainIndex >= 0 && MainIndex < menuModels.Count)
  97. {
  98. int SubIndex; SubIndex = Array.FindIndex(menuModels.ElementAt(MainIndex).subMenumodels.ToArray(), p => p.SubMenuVisibility == Visibility.Visible);
  99. if (SubIndex >= 0 && SubIndex < menuModels.ElementAt(MainIndex).subMenumodels.Count)
  100. {
  101. //DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex).ToggleWindowPath);
  102. DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex));
  103. }
  104. }
  105. }
  106. public ObservableCollection<MenuModel> menuModels { get; set; }
  107. private void DoNavChanged(object obj)
  108. {
  109. if (obj != null && obj is SubMenumodel menumodel)
  110. {
  111. DisplayName = menumodel.SubMenuName;
  112. var end = menumodel.AssemblyName.Substring(menumodel.AssemblyName.Length - 1);
  113. var start = menumodel.ToggleWindowPath.Substring(0, 1);
  114. bool isAddPoint = end != "." && start != ".";
  115. string point = isAddPoint ? "." : "";
  116. Type type = Assembly.Load(menumodel.AssemblyName)?.GetType($"{menumodel.AssemblyName}{point}{menumodel.ToggleWindowPath}");
  117. ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  118. if (type?.BaseType.Name == "Window") ((Window)cti?.Invoke(null)).ShowDialog();
  119. else if (type?.BaseType.Name == "UserControl")
  120. {
  121. MainContent = null;
  122. MainContent = (FrameworkElement)cti?.Invoke(null);
  123. MainContent?.GetType()?.GetProperty("Name").SetValue(MainContent, menumodel.SubMenuName);
  124. }
  125. }
  126. }
  127. private bool _status;
  128. /// <summary>
  129. /// 设备初始化状态
  130. /// </summary>
  131. public bool Status
  132. {
  133. get { return _status; }
  134. set
  135. {
  136. if (value)
  137. {
  138. ActionManage.GetInstance.Send("StartPlcInite");
  139. }
  140. else
  141. {
  142. ActionManage.GetInstance.Send("EndPlcInite");
  143. }
  144. _status = value;
  145. OnPropertyChanged();
  146. }
  147. }
  148. /// <summary>
  149. /// 开机自启
  150. /// </summary>
  151. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  152. public RelayCommand<object> NavChangedCommand { get; set; }
  153. public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
  154. private FrameworkElement _mMainContent;
  155. public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
  156. private string _mDisplayName;
  157. }
  158. }