PWA Fundvelo der Caritas.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NavMenu.razor 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. @using cwebplusApp.Shared.Services;
  2. @inject AppState AppState;
  3. @inject NavigationManager NavigationManager;
  4. @inject IStringLocalizer<Resources> i18n
  5. @inject IJSRuntime jsRuntime;
  6. @inject PageHistoryManager PageHistoryManager;
  7. @implements IDisposable;
  8. @if (HandleAppBarContainer()) {
  9. <div class="sidebar">
  10. <MatAppBarContainer>
  11. <MatAppBar Fixed="true">
  12. <MatAppBarRow>
  13. <MatAppBarSection>
  14. <MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton>
  15. @if (PageHistoryManager.CanGoBack()) {
  16. <MatIconButton Icon="keyboard_backspace" OnClick="@((e) => ButtonBackClicked())" Disabled="@BackButtonDisabled()"></MatIconButton>
  17. }
  18. <MatAppBarTitle Class="navBar-title">@LocationUrl</MatAppBarTitle>
  19. </MatAppBarSection>
  20. <MatAppBarSection align="@MatAppBarSectionAlign.End" Style="max-width:min-content">
  21. <NavLink rel="noopener" target="_blank" class="text-white small" href="https://www.caritas.ch" align="@MatAppBarSectionAlign.End" style="padding-right:1em">@i18n["Learnmore"]</NavLink>
  22. </MatAppBarSection>
  23. </MatAppBarRow>
  24. </MatAppBar>
  25. <MatAppBarContent>
  26. <MatDrawerContainer>
  27. <MatDrawer @bind-Opened="@Opened" Mode="@MatDrawerMode.Modal">
  28. <MatList>
  29. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  30. <MatListItem Class="@((Index == 1) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  31. Href="caritas_services"
  32. @onclick="@((e) => ButtonClicked(1))">
  33. <MatIcon Icon="@MatIconNames.Apps"></MatIcon>
  34. <MatListItemText Style="padding-left:0.5em">@i18n["CaritasServices"]</MatListItemText>
  35. </MatListItem>
  36. </MatRipple>
  37. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  38. <MatListItem Class="@((Index == 2) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  39. Href="account"
  40. @onclick="@((e) => ButtonClicked(2))">
  41. <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon>
  42. <MatListItemText Style="padding-left:0.5em">@i18n["account"]</MatListItemText>
  43. </MatListItem>
  44. </MatRipple>
  45. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  46. <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  47. Href="info"
  48. @onclick="@((e) => ButtonClicked(3))">
  49. <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
  50. <MatListItemText Style="padding-left:0.5em">@i18n["info"]</MatListItemText>
  51. </MatListItem>
  52. </MatRipple>
  53. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  54. <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  55. href=""
  56. Match="NavLinkMatch.All"
  57. @onclick="@((e) => ButtonClicked(4))">
  58. <MatIcon Icon="@MatIconNames.Exit_to_app"></MatIcon>
  59. <MatListItemText Style="padding-left:0.5em">@i18n["Logout"]</MatListItemText>
  60. </MatListItem>
  61. </MatRipple>
  62. </MatList>
  63. </MatDrawer>
  64. </MatDrawerContainer>
  65. </MatAppBarContent>
  66. </MatAppBarContainer>
  67. </div>
  68. }
  69. @code {
  70. private bool Opened = false;
  71. private static int Index = 1;
  72. private string locUrl;
  73. private string LocationUrl {
  74. get => locUrl;
  75. set {
  76. locUrl = value;
  77. StateHasChanged();
  78. }
  79. }
  80. public void Dispose() {
  81. AppState.OnChange -= StateHasChanged;
  82. NavigationManager.LocationChanged -= LocationChanged;
  83. }
  84. protected override void OnInitialized() {
  85. AppState.OnChange += StateHasChanged;
  86. NavigationManager.LocationChanged += LocationChanged;
  87. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  88. base.OnInitialized();
  89. }
  90. private void ButtonClicked() {
  91. Opened = !Opened;
  92. }
  93. private void ButtonClicked(int _Index) {
  94. Index = _Index;
  95. ButtonClicked();
  96. if (_Index == 4) {
  97. AppState.LoggedIn = false;
  98. }
  99. }
  100. private void ButtonBackClicked() {
  101. NavigationManager.NavigateTo(PageHistoryManager.GetPreviousPage());
  102. }
  103. private void LocationChanged(object sender, LocationChangedEventArgs e) {
  104. locUrl = i18n.GetString(e.Location.Replace(NavigationManager.BaseUri, ""));
  105. if (IsInServicesUrl(e)) {
  106. Index = 1;
  107. } else if (e.Location.Contains("account")) {
  108. Index = 2;
  109. } else if (e.Location.Contains("info")) {
  110. Index = 3;
  111. } else {
  112. Index = 4;
  113. }
  114. StateHasChanged();
  115. }
  116. private bool IsInServicesUrl(LocationChangedEventArgs e) {
  117. return (e.Location.Contains("caritas_services") || e.Location.Contains("lost_found") || e.Location.Contains("keydata")
  118. || e.Location.Contains("account/") || e.Location.Contains("conclusion_"));
  119. }
  120. private bool HandleAppBarContainer() {
  121. string uri = NavigationManager.Uri;
  122. string baseUri = NavigationManager.BaseUri;
  123. string delta = uri.Replace(baseUri, "");
  124. if (delta == null || delta.Equals("")) {
  125. Index = 4;
  126. return false;
  127. } else {
  128. if (delta.Equals("caritas_services")) {
  129. Index = 1;
  130. } else if (delta.Equals("account")) {
  131. Index = 2;
  132. } else if (delta.Equals("info")) {
  133. Index = 3;
  134. }
  135. return true;
  136. }
  137. }
  138. private bool BackButtonDisabled() {
  139. return !PageHistoryManager.CanGoBack();
  140. }
  141. }