using CommunityToolkit.Mvvm.Input; using Microsoft.UI.Xaml.Controls; using XFEWarframe.Player.Models; using XFEWarframe.Player.Views; using XFEWarframe.Player.Views.Dialogs; namespace XFEWarframe.Player.ViewModels; public partial class AccountPageViewModel : PlayerViewModelBase { public PlayerAccountState Account => App.Accounts.State; protected override async Task LoadAsync(object? parameter) { await base.LoadAsync(parameter); await App.Accounts.InitializeAsync(); if(Account.IsLoggedIn) await App.Accounts.RefreshAsync(); } [RelayCommand] private Task LoginAsync() => RunAsync(async () => { await App.Accounts.InitializeAsync(); while(!Account.IsLoggedIn) { var login = new LoginDialog(); if(await Interaction.ShowAsync(login) != ContentDialogResult.Secondary || !Account.RegistrationEnabled) break; if(await Interaction.ShowAsync(new RegisterDialog()) == ContentDialogResult.Primary) Notify("注册成功,请登录你的账号"); } }); [RelayCommand] private Task LogoutAsync() => RunAsync(App.Accounts.LogoutAsync); [RelayCommand] private Task EditIdentityAsync() => RunAsync(async () => { if(await Interaction.ShowAsync(new IdentityDialog()) == ContentDialogResult.Primary) Notify("账号修改已保存"); }); [RelayCommand] private Task RefreshAsync() => RunAsync(async () => { await App.Accounts.InitializeAsync(); if(Account.IsLoggedIn) await App.Accounts.RefreshAsync(); }); [RelayCommand] private void OpenInventory() => Navigation.NavigateTo(); }