Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 优化登录体验 #33

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 41 additions & 29 deletions src/HyPlayer.App/Views/Controls/Dialogs/SignInDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,51 @@
x:Class="HyPlayer.Views.Controls.Dialogs.SignInDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="登录 HyPlayer"
Title="登录"
KeyDown="ContentDialog_KeyDown"
Background="{ThemeResource SystemControlAltLowAcrylicElementBrush}"
CloseButtonText="取消"
DefaultButton="Primary"
PrimaryButtonClick="{x:Bind ContentDialog_PrimaryButtonClickAsync}"
PrimaryButtonText="登录"
Style="{ThemeResource DefaultContentDialogStyle}"
mc:Ignorable="d">

<Grid>
<Grid Margin="12,16">
<StackPanel Orientation="Vertical" Spacing="12">
<TextBox
x:Name="TextBoxAccount"
Margin="0,6"
BorderThickness="0"
PlaceholderText="手机 / 邮箱" />
<PasswordBox
x:Name="TextBoxPassword"
Margin="0,6"
BorderThickness="0"
PlaceholderText="密码" />
<Grid>
<TextBlock
VerticalAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
Text="登录代表你同意相关条款" />
</Grid>

</StackPanel>
</Grid>

</Grid>
<StackPanel
Margin="0,8,0,0"
Orientation="Vertical"
Spacing="12">
<TextBox
x:Name="TextBoxAccount"
BorderThickness="0"
PlaceholderText="手机 / 邮箱" />
<PasswordBox
x:Name="TextBoxPassword"
BorderThickness="0"
PlaceholderText="密码" />
<TextBlock
VerticalAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
Text="登录代表你同意相关条款" />
<InfoBar
x:Name="LoginFailedInfoBar"
Title="登录失败"
Message="请重试"
Severity="Error" />
<StackPanel
HorizontalAlignment="Right"
Orientation="Horizontal"
Spacing="8">
<Button
x:Name="CancelButton"
Click="CancelButton_Click"
Content="取消" />
<Button
x:Name="LoginButton"
Click="LoginButton_Click"
Content="登录"
Style="{ThemeResource AccentButtonStyle}" />
</StackPanel>
</StackPanel>
</ContentDialog>
33 changes: 32 additions & 1 deletion src/HyPlayer.App/Views/Controls/Dialogs/SignInDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,41 @@ public SignInDialog()
DataContext = ViewModel;
}

private async Task ContentDialog_PrimaryButtonClickAsync(ContentDialog sender, ContentDialogButtonClickEventArgs args)

private void CancelButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
Hide();
}

private void LoginButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
Login();
}
public async void Login()
{
await ViewModel.SignInAsync(TextBoxAccount.Text, TextBoxPassword.Password);
if (!ViewModel.IsLogin)
{
LoginFailedInfoBar.IsOpen = true;
return;
}
HyPlayer.App.GetService<INavigationService>().NavigateTo(typeof(Pages.HomePage));
Hide();
}

private void ContentDialog_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if(TextBoxAccount.Text == "")
{
TextBoxAccount.Focus(Microsoft.UI.Xaml.FocusState.Programmatic);
return;
}
if (TextBoxPassword.Password == "")
{
TextBoxPassword.Focus(Microsoft.UI.Xaml.FocusState.Programmatic);
return;
}
Login();
}
}
}