终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

162 Zeilen
6.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPASmartClient.Helper;
  11. using Microsoft.Toolkit.Mvvm.Input;
  12. using BPASmartClient.DosingSystem.Model;
  13. using Newtonsoft.Json;
  14. using System.IO;
  15. using System.Reflection;
  16. namespace BPASmartClient.DosingSystem.ViewModel
  17. {
  18. public class MainViewModel : ObservableObject
  19. {
  20. //ObservableCollection<ActionMenu> menus = new ObservableCollection<ActionMenu>();
  21. //private Permission _permission;
  22. //public Permission permission
  23. //{
  24. // get { return _permission; }
  25. // set
  26. // {
  27. // var res = menus.Where(p => Array.FindIndex(p.permission, s => s == value) >= 0).ToList();
  28. // if (res != null && res.Count > 0)
  29. // {
  30. // Menus.Clear();
  31. // res.ForEach((item) => { Menus.Add(item); });
  32. // }
  33. // _permission = value;
  34. // }
  35. //}
  36. public MainViewModel()
  37. {
  38. //Json<LocaPar>.Read();
  39. TogglePag = new RelayCommand<object>(DoNavChanged);
  40. Login = new RelayCommand(() => { DoNavChanged("BPASmartClient.DosingSystem.View.AdminstratorsView_用户登录"); UserManagement = false; });
  41. PasswordChange = new RelayCommand(() =>
  42. {
  43. //DoNavChanged("PasswordChangeView.密码修改");
  44. UserManagement = false;
  45. });
  46. ExitLogin = new RelayCommand(() =>
  47. {
  48. //SystemUtils.ShowScreenKeyboard();
  49. //DoNavChanged("LoginView.退出登录");
  50. UserManagement = false;
  51. });
  52. //Config.GetInstance.Init();
  53. LoginRegister();
  54. MenuInit();
  55. //permission = Permission.管理员;
  56. //if (Menus.Count > 0) DoNavChanged(Menus.ElementAt(0).CommandParameter);
  57. DeviceInquire.GetInstance.Init();
  58. }
  59. private void LoginRegister()
  60. {
  61. ActionManage.GetInstance.Register(new Func<object, object>((o) =>
  62. {
  63. //if (o != null && o is string str)
  64. //{
  65. // var strs = str.Split("-=");
  66. // if (strs != null && strs.Length == 3)
  67. // {
  68. // var us = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == strs[0]);
  69. // if (us != null && strs[1] == us.Password && strs[2] == us.permission.ToString())
  70. // {
  71. // permission = us.permission;
  72. // return string.Empty;
  73. // }
  74. // }
  75. //}
  76. return "用户名或密码错误";
  77. }), "LoginBPASmartClient.DosingSystem");
  78. }
  79. private void MenuInit()
  80. {
  81. //menus.Add(new ActionMenu()
  82. //{
  83. // MenuName = "配方设置",
  84. // CommandParameter = "BPASmartClient.DosingSystem.View.RecipeSettingsView_配方设置",
  85. // permission = new Permission[] { Permission.管理员, Permission.技术员 },
  86. //});
  87. //menus.Add(new ActionMenu()
  88. //{
  89. // MenuName = "设备列表",
  90. // CommandParameter = "BPASmartClient.DosingSystem.View.DeviceListView_设备列表",
  91. // permission = new Permission[] { Permission.管理员, Permission.技术员 },
  92. //});
  93. //menus.Add(new ActionMenu()
  94. //{
  95. // MenuName = "硬件状态",
  96. // CommandParameter = "BPASmartClient.DosingSystem.View.HardwareStatusView_硬件状态",
  97. // permission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  98. //});
  99. //menus.Add(new ActionMenu()
  100. //{
  101. // MenuName = "报警记录",
  102. // CommandParameter = "BPASmartClient.CustomResource.Pages.View.AlarmView_报警记录",
  103. // permission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  104. //});
  105. //menus.Add(new ActionMenu()
  106. //{
  107. // MenuName = "配方下发",
  108. // CommandParameter = "BPASmartClient.DosingSystem.View.RecipeControlView_配方控制",
  109. // permission = new Permission[] { Permission.管理员, Permission.操作员 },
  110. //});
  111. }
  112. public void DoNavChanged(object obj)
  113. {
  114. if (obj != null && obj is string stobj)
  115. {
  116. var strs = stobj.Split('_');
  117. if (strs != null && strs.Length == 2)
  118. {
  119. Type type;
  120. if (!stobj.Contains("BPASmartClient.DosingSystem"))
  121. {
  122. type = Assembly.Load("BPASmartClient.CustomResource").GetType(strs[0]);
  123. }
  124. else type = Type.GetType(strs[0]);
  125. var res = type?.GetConstructor(System.Type.EmptyTypes)?.Invoke(null);
  126. if (res != null && res is FrameworkElement fe) MyWindow = fe;
  127. WindowTitleName = strs[1];
  128. }
  129. }
  130. }
  131. public RelayCommand<object> TogglePag { get; set; }
  132. public RelayCommand Login { get; set; }
  133. public RelayCommand PasswordChange { get; set; }
  134. public RelayCommand ExitLogin { get; set; }
  135. public ObservableCollection<ActionMenu> Menus { get; set; } = new ObservableCollection<ActionMenu>();
  136. public FrameworkElement MyWindow { get { return _mMyWindow; } set { _mMyWindow = value; OnPropertyChanged(); } }
  137. private FrameworkElement _mMyWindow;
  138. public string WindowTitleName { get { return _mWindowTitleName; } set { _mWindowTitleName = value; OnPropertyChanged(); } }
  139. private string _mWindowTitleName;
  140. public bool UserManagement { get { return _mUserManagement; } set { _mUserManagement = value; OnPropertyChanged(); } }
  141. private bool _mUserManagement;
  142. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  143. }
  144. }