forked from AcaMate/AcaMate_Web
1. 로그인 동작을 위해서 viewmodel 로 관련 뷰에서 동작할 모든 로직을 viewmodel에서 관리 1.1. view 와 viewmodel의 관계는 1:N으로 동작하는것을 기반으로 두고 있음 2. API 접근하는 방식도 웹만의 접근 방법에서 수정 3. 로그인 동작 정보 받는 로직 수정
77 lines
2.9 KiB
C#
77 lines
2.9 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
|
|
using Front.Program.Views.Project;
|
|
using Front.Program.Views.Academy;
|
|
using Front.Program.Services;
|
|
|
|
namespace Front.Program.Layout;
|
|
|
|
public partial class MainLayout : LayoutComponentBase, IDisposable
|
|
{
|
|
[Inject]
|
|
NavigationManager Navigation { get; set; } = default!;
|
|
|
|
[Inject]
|
|
LoadingService LoadingService { get; set; } = default!;
|
|
|
|
[Inject]
|
|
StorageService StorageService { get; set; } = default!;
|
|
|
|
// 경로의 시작 부분
|
|
// protected bool isHidePrjTop => Navigation.ToBaseRelativePath(Navigation.Uri).StartsWith("auth", StringComparison.OrdinalIgnoreCase);
|
|
|
|
// 경로의 끝 부분
|
|
protected bool isHidePrjTop => Navigation.ToBaseRelativePath(Navigation.Uri).EndsWith("auth", StringComparison.OrdinalIgnoreCase);
|
|
protected bool isAcademy => Navigation.ToBaseRelativePath(Navigation.Uri).StartsWith("am", StringComparison.OrdinalIgnoreCase);
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
LoadingService.OnChange += StateHasChanged;
|
|
Navigation.LocationChanged += HandleLocationChanged;
|
|
HandleLocationChanged(this, new LocationChangedEventArgs(Navigation.Uri, false));
|
|
}
|
|
|
|
// 페이지의 URL이 변경될 때마다 실행되는 이벤트 핸들러
|
|
private async void HandleLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
LoadingService.HideNavigationLoading();
|
|
//
|
|
// var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
|
|
// Console.WriteLine($"리다이렉트된 URI: {uri}");
|
|
//
|
|
// if (uri.Query.Contains("auth="))
|
|
// {
|
|
// var query = uri.Query.TrimStart('?');
|
|
// var parameters = query.Split('&')
|
|
// .Select(p => p.Split('='))
|
|
// .Where(p => p.Length == 2)
|
|
// .ToDictionary(p => p[0], p => p[1]);
|
|
//
|
|
// if (parameters.TryGetValue("auth", out var auth))
|
|
// {
|
|
// Console.WriteLine($"auth 파라미터 값: {auth}");
|
|
// if (auth == "true")
|
|
// {
|
|
// await StorageService.SetItemAsync("IsLogin", "true");
|
|
// Console.WriteLine("로그인 상태를 true로 설정했습니다.");
|
|
// }
|
|
// else
|
|
// {
|
|
// await StorageService.RemoveItemAsync("IsLogin");
|
|
// Console.WriteLine("로그인 상태를 제거했습니다.");
|
|
// }
|
|
//
|
|
// // 파라미터를 제거하고 리다이렉트
|
|
// var baseUri = uri.GetLeftPart(UriPartial.Path);
|
|
// Navigation.NavigateTo(baseUri, forceLoad: false);
|
|
// }
|
|
// }
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
LoadingService.OnChange -= StateHasChanged;
|
|
Navigation.LocationChanged -= HandleLocationChanged;
|
|
}
|
|
} |