Learn.VideoAnalysis/VideoAnalysis/Components/Layouts/BasicLayout.razor.cs

90 lines
2.5 KiB
C#

using AntDesign.Extensions.Localization;
using AntDesign.ProLayout;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using Microsoft.Identity.Client.Extensions.Msal;
using Microsoft.JSInterop;
using System.Globalization;
using System.Net.Http.Json;
namespace VideoAnalysisRazor.Layouts
{
public partial class BasicLayout : LayoutComponentBase, IDisposable
{
private MenuDataItem[] _menuData;
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
[Inject] IHttpContextAccessor HttpContextAccessor { get; set; } = default!;
[Inject] private ReuseTabsService TabService { get; set; }
[Inject] private IJSRuntime JSRuntime { get; set; }
[Inject] private ProtectedSessionStorage session { get; set; } = default!;
bool collapsed;
void Toggle()
{
collapsed = !collapsed;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!await CheckLogin())
{
NavigationManager.NavigateTo("/Login");
}
}
protected override async Task OnInitializedAsync()
{
_menuData = [
new MenuDataItem
{
Path = "/",
Name = "任务队列",
Key = "VideoTaskPage",
Icon = "unordered-list",
},
new MenuDataItem
{
Path = "/Project",
Name = "课堂指标",
Key = "EvaluationProject",
Icon = "question-circle",
},
new MenuDataItem
{
Path = "/Login",
Name = "登录页",
Key = "Login",
HideInMenu = true,
}
];
}
public async Task<bool> CheckLogin()
{
try
{
return (await session.GetAsync<bool>("Login")).Value;
}
catch
{
return false;
}
}
void Reload()
{
TabService.ReloadPage();
}
async Task ToSwagger()
{
await JSRuntime.InvokeVoidAsync("open", "/swagger/index.html", "_blank");
}
public void Dispose()
{
}
}
}