终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

159 行
5.1 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.Pages.View;
  3. using BPASmartClient.Helper;
  4. using Microsoft.Toolkit.Mvvm.ComponentModel;
  5. using Microsoft.Toolkit.Mvvm.Input;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace BPASmartClient.CustomResource.Pages.ViewModel
  13. {
  14. public class UserConfigViewModel:ObservableObject
  15. {
  16. /// <summary>
  17. /// 页面列表集合
  18. /// </summary>
  19. public ObservableCollection<UserTreeViewModel> pageTreeViewModels { get; set; } = new ObservableCollection<UserTreeViewModel>();
  20. /// <summary>
  21. /// 已选择页面
  22. /// </summary>
  23. public ObservableCollection<UserTreeViewModel> SelectePage { get; set; } = new ObservableCollection<UserTreeViewModel>();
  24. /// <summary>
  25. /// 用户名
  26. /// </summary>
  27. public string UserName { get { return _username; } set { _username = value; OnPropertyChanged(); } }
  28. private string _username;
  29. public RelayCommand<object> AddUserPageCommand { get; set; }
  30. public RelayCommand<object> DeleteUserPageCommand { get; set; }
  31. public RelayCommand DeleteAllPageCommand { get; set; }
  32. public RelayCommand AddAllPageCommand { get; set; }
  33. public RelayCommand SaveCommand { get; set; }
  34. public RelayCommand CancelCommand { get; set; }
  35. private void AddUserPage(object o)
  36. {
  37. if (o == null) return;
  38. if(o is string name)
  39. {
  40. var s = SelectePage.FirstOrDefault(x => x.Name == name);
  41. if (!SelectePage.Contains(s))
  42. {
  43. foreach (UserTreeViewModel item in pageTreeViewModels)
  44. {
  45. var res = item.TreeViewItems.FirstOrDefault(P => P.Name == name);
  46. if(res != null)
  47. {
  48. SelectePage.Add(res);
  49. return;
  50. }
  51. }
  52. }
  53. }
  54. }
  55. private void DeleteUserPage(object o)
  56. {
  57. if (o == null) return;
  58. if (o is string name)
  59. {
  60. var res = SelectePage.FirstOrDefault(p=>p.Name == name);
  61. SelectePage.Remove(res);
  62. }
  63. }
  64. public UserConfigViewModel()
  65. {
  66. AddUserPageCommand = new RelayCommand<object>(AddUserPage);
  67. DeleteUserPageCommand = new RelayCommand<object>(DeleteUserPage);
  68. DeleteAllPageCommand = new RelayCommand(() =>
  69. {
  70. SelectePage.Clear();
  71. });
  72. AddAllPageCommand = new RelayCommand(() =>
  73. {
  74. foreach(UserTreeViewModel item in pageTreeViewModels)
  75. {
  76. foreach(var res in item.TreeViewItems)
  77. {
  78. if (!SelectePage.Contains(res)) SelectePage.Add(res);
  79. }
  80. }
  81. });
  82. SaveCommand = new RelayCommand(() =>
  83. {
  84. var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == Global.changeUserInfo.UserName && p.Password == Global.changeUserInfo.Password);
  85. if(res != null)
  86. {
  87. res.userTreeViewModels = new List<UserTreeViewModel>();
  88. res.userTreeViewModels.AddRange(SelectePage);
  89. Config.GetInstance.SaveUser();
  90. }
  91. Global.changeUserInfo = null;
  92. ActionManage.GetInstance.Send("UserConfigViewConfirm");
  93. });
  94. CancelCommand = new RelayCommand(() =>
  95. {
  96. Global.changeUserInfo = null;
  97. ActionManage.GetInstance.Send("UserConfigViewCancel");
  98. });
  99. foreach (var item in MenuManage.GetInstance.menuModels)
  100. {
  101. List<UserTreeViewModel> list = new List<UserTreeViewModel>();
  102. foreach(var res in item.subMenumodels)
  103. {
  104. list.Add(new UserTreeViewModel { Name = res.SubMenuName});
  105. }
  106. pageTreeViewModels.Add(new UserTreeViewModel
  107. {
  108. Name = item.MainMenuName,
  109. TreeViewItems = list
  110. });
  111. }
  112. if(Global.changeUserInfo != null)
  113. {
  114. UserName = Global.changeUserInfo.UserName;
  115. if (Global.changeUserInfo.userTreeViewModels != null)
  116. {
  117. if(Global.changeUserInfo.userTreeViewModels.Count > 0)
  118. {
  119. foreach(UserTreeViewModel item in Global.changeUserInfo.userTreeViewModels)
  120. {
  121. SelectePage.Add(item);
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }