Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

182 linhas
6.1 KiB

  1. @using Components
  2. @using Newtonsoft.Json
  3. @using Models.Identity
  4. @inject ILoadingSpinner _LoadingSpinner
  5. @inherits LayoutComponentBase
  6. <RoundContainerContainer Padding="0" Scroll=true>
  7. <style>
  8. div.scroll-div {
  9. background-color: #F1F1F1;
  10. overflow-y: hidden;
  11. height: calc(100vh - 122px)
  12. }
  13. @@media only screen and (min-width: 600px) {
  14. div.scroll-div {
  15. height: calc(100vh - 120px)
  16. }
  17. }
  18. </style>
  19. <div class="@BT.FlexJustifyAround" style="flex-direction:column" @onclick="@(()=>ToggleMenu(close:true))">
  20. @*Top Header*@
  21. <div class="@BT.Row @BT.Background(ColorType.white) @BT.Margin(0) @BT.Padding(2) @BT.SmallShadow" style="height:60px;">
  22. <div style="@Styles.VerticalSelfAlign(TextAlignment.center)" class="@BT.Col(6) @BT.TextAlign(TextAlignment.left)">
  23. <img role="button" @onclick="@(()=>ToggleMenu(close:false))" src="/assets/images/Hamburger_icon.svg" width="30">
  24. <img src="/assets/images/logo-blue.png" alt="" width="60">
  25. </div>
  26. <div class="@BT.Col(6) @BT.TextAlign(TextAlignment.right)">
  27. </div>
  28. </div>
  29. @*end of Top Header*@
  30. <div class="scroll-div @BT.Row @BT.Margin(0) @BT.DisplayBlock">
  31. @Body
  32. </div>
  33. @*Footer*@
  34. <div class="@BT.Background(ColorType.white) @(BT.Row) @(BT.TextAlign(TextAlignment.center)) @(BT.SmallShadow) "
  35. style="height:60px;font-size:12px;width:100%;margin:0 auto;">
  36. <div @onclick="@(()=>NavManager.NavigateTo("/dashboard"))" role="button" style="@(Styles.VerticalSelfAlign(TextAlignment.center)) " class="@(BT.Col(4)) @(BT.TextAlign(TextAlignment.right))">
  37. <img src="/assets/images/ico-dashboard.png" alt="" width="26">
  38. <br />
  39. داشبورد
  40. </div>
  41. <div @onclick="@(()=>NavManager.NavigateTo("/Suit/Subject/Level1"))" role="button" style="@(Styles.VerticalSelfAlign(TextAlignment.center))" class="@(BT.Col(4)) @(BT.TextAlign(TextAlignment.right))">
  42. <img src="/assets/images/ico-add.png" alt="" width="26">
  43. <br />
  44. دعوی جدید
  45. </div>
  46. <div role="button" style="@(Styles.VerticalSelfAlign(TextAlignment.center))" class="@(BT.Col(4)) @(BT.TextAlign(TextAlignment.right))">
  47. <img src="/assets/images/ico-user.png" alt="" width="26">
  48. <br />
  49. پروفایل
  50. </div>
  51. </div>
  52. @*End Of Footer*@
  53. </div>
  54. <div class="menu @(BT.Background(ColorType.dark)) @BT.Position(Postion.Position_Fixed)"
  55. style="top:auto;height:100vh;top:0;width:@(MenuWidth)%;max-width:450px;">
  56. @if (!MenuIsChanging && MenuWidth > 10)
  57. {
  58. <a href="/about">درباره حق‌تو</a>
  59. <a href="/Privacy">حریم ‌خصوصی</a>
  60. <a href="/Contact">تماس با ما</a>
  61. }
  62. </div>
  63. </RoundContainerContainer>
  64. <style>
  65. div.menu a {
  66. line-height: 1.5em;
  67. padding: 10px;
  68. border-bottom: 1px white solid;
  69. width: 100%;
  70. text-decoration: none;
  71. font-size: 1.5em;
  72. opacity: 1;
  73. color: white;
  74. display: block;
  75. }
  76. </style>
  77. @code
  78. {
  79. public int MenuWidth { set; get; } = 0;
  80. public bool ShowMenu { set; get; } = false;
  81. public bool MenuIsChanging { set; get; } = false;
  82. protected async Task ToggleMenu(bool close = false)
  83. {
  84. if (MenuIsChanging)
  85. return;
  86. MenuIsChanging = true;
  87. if (close)
  88. {
  89. Console.WriteLine("closing menu");
  90. while (MenuWidth > 0)
  91. {
  92. MenuWidth = Math.Max(MenuWidth -= 2, 0);
  93. StateHasChanged();
  94. await Task.Delay(5);
  95. }
  96. MenuIsChanging = false;
  97. return;
  98. }
  99. else
  100. {
  101. Console.WriteLine("opening menu");
  102. while (MenuWidth < 60)
  103. {
  104. Console.WriteLine(MenuWidth);
  105. MenuWidth = Math.Min(MenuWidth += 2, 60);
  106. StateHasChanged();
  107. await Task.Delay(5);
  108. }
  109. MenuIsChanging = false;
  110. }
  111. }
  112. protected override async void OnAfterRender(bool firstRender)
  113. {
  114. if (firstRender)
  115. await CheckLogin();
  116. base.OnAfterRender(firstRender);
  117. NavManager.LocationChanged += HideMenu;
  118. }
  119. private void HideMenu(object sender, LocationChangedEventArgs e)
  120. {
  121. MenuWidth = 0;
  122. StateHasChanged();
  123. }
  124. async Task CheckLogin()
  125. {
  126. Console.WriteLine("" + Statics.LastCheck);
  127. if (Statics.LastCheck.HasValue && DateTime.Now.Subtract(Statics.LastCheck.Value).TotalMinutes < 5)
  128. {
  129. Console.WriteLine("less than 5 minutes login check");
  130. base.OnInitialized();
  131. return;
  132. }
  133. Console.WriteLine("checking login...");
  134. Statics.LastCheck = DateTime.Now;
  135. var hasToken = await LocalStorage.ContainKeyAsync(Statics.LoginTokenKey);
  136. if (!hasToken)
  137. NavManager.NavigateTo("/");
  138. else
  139. {
  140. var token = await LocalStorage.GetItemAsStringAsync(Statics.LoginTokenKey);
  141. var res = await _userUtils.CheckLogin();
  142. if (res.StatusCode == System.Net.HttpStatusCode.Unauthorized)
  143. {
  144. await _LoadingSpinner.HideLoading();
  145. NavManager.NavigateTo("/login");
  146. }
  147. else
  148. {
  149. var result =
  150. JsonConvert.DeserializeObject<CheckLoginResponse>(
  151. await res.Content.ReadAsStringAsync());
  152. Statics.CurrentLoginInfo = result;
  153. }
  154. await _LoadingSpinner.HideLoading();
  155. StateHasChanged();
  156. }
  157. }
  158. private async void SignOut()
  159. {
  160. await LocalStorage.RemoveItemAsync(Statics.LoginTokenKey);
  161. await LocalStorage.RemoveItemAsync(Statics.RefreshTokenKey);
  162. NavManager.NavigateTo("/login");
  163. }
  164. }