RightContent.razor.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using wispro.sp.web.Models;
  2. using wispro.sp.web.Services;
  3. using AntDesign.ProLayout;
  4. using Microsoft.AspNetCore.Components;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using AntDesign;
  9. using Microsoft.AspNetCore.Components.Authorization;
  10. using wispro.sp.web.Auth;
  11. namespace wispro.sp.web.Components
  12. {
  13. public partial class RightContent
  14. {
  15. private CurrentUser _currentUser = new CurrentUser();
  16. private NoticeIconData[] _notifications = { };
  17. private NoticeIconData[] _messages = { };
  18. private NoticeIconData[] _events = { };
  19. private int _count = 0;
  20. private List<AutoCompleteDataItem<string>> DefaultOptions { get; set; } = new List<AutoCompleteDataItem<string>>
  21. {
  22. new AutoCompleteDataItem<string>
  23. {
  24. Label = "umi ui",
  25. Value = "umi ui"
  26. },
  27. new AutoCompleteDataItem<string>
  28. {
  29. Label = "Pro Table",
  30. Value = "Pro Table"
  31. },
  32. new AutoCompleteDataItem<string>
  33. {
  34. Label = "Pro Layout",
  35. Value = "Pro Layout"
  36. }
  37. };
  38. public AvatarMenuItem[] AvatarMenuItems { get; set; } = new AvatarMenuItem[]
  39. {
  40. new() { Key = "center", IconType = "user", Option = "个人中心"},
  41. new() { Key = "setting", IconType = "setting", Option = "个人设置"},
  42. new() { IsDivider = true },
  43. new() { Key = "logout", IconType = "logout", Option = "退出登录"}
  44. };
  45. [Inject] protected NavigationManager NavigationManager { get; set; }
  46. [Inject] protected IUserService UserService { get; set; }
  47. [Inject] protected IProjectService ProjectService { get; set; }
  48. [Inject] protected MessageService MessageService { get; set; }
  49. [Inject] protected IAuthService authorProvider { get; set; }
  50. protected override async System.Threading.Tasks.Task OnInitializedAsync()
  51. {
  52. await base.OnInitializedAsync();
  53. SetClassMap();
  54. _currentUser = UserService.CurrentUser;
  55. var notices = await ProjectService.GetNoticesAsync();
  56. _notifications = notices.Where(x => x.Type == "notification").Cast<NoticeIconData>().ToArray();
  57. _messages = notices.Where(x => x.Type == "message").Cast<NoticeIconData>().ToArray();
  58. _events = notices.Where(x => x.Type == "event").Cast<NoticeIconData>().ToArray();
  59. _count = notices.Length;
  60. }
  61. protected void SetClassMap()
  62. {
  63. ClassMapper
  64. .Clear()
  65. .Add("right");
  66. }
  67. public void HandleSelectUser(MenuItem item)
  68. {
  69. switch (item.Key)
  70. {
  71. case "center":
  72. NavigationManager.NavigateTo("/account/center");
  73. break;
  74. case "setting":
  75. NavigationManager.NavigateTo("/account/settings");
  76. break;
  77. case "logout":
  78. authorProvider.LogoutAsync();
  79. //NavigationManager.NavigateTo("/LoginPages");
  80. break;
  81. }
  82. }
  83. public void HandleSelectLang(MenuItem item)
  84. {
  85. }
  86. public async System.Threading.Tasks.Task HandleClear(string key)
  87. {
  88. switch (key)
  89. {
  90. case "notification":
  91. _notifications = new NoticeIconData[] { };
  92. break;
  93. case "message":
  94. _messages = new NoticeIconData[] { };
  95. break;
  96. case "event":
  97. _events = new NoticeIconData[] { };
  98. break;
  99. }
  100. await MessageService.Success($"清空了{key}");
  101. }
  102. public async System.Threading.Tasks.Task HandleViewMore(string key)
  103. {
  104. await MessageService.Info("Click on view more");
  105. }
  106. }
  107. }