Skip to content

Commit

Permalink
增加退出登录
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Dec 31, 2024
1 parent 38cd952 commit 7beb2de
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
20 changes: 15 additions & 5 deletions src/ChatBox/Controls/ChatWelcome.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="ChatBox.Controls.ChatWelcome">
<Grid>
<TextBlock
<StackPanel>
<SelectableTextBlock
FontSize="24"
Margin="0,60,0,0"
Margin="0,120,0,0"
VerticalAlignment="Center"
TextWrapping="Wrap"
HorizontalAlignment="Center">
嗨🖖,我是 AI Chat!欢迎使用AI Chat!
</TextBlock>
</Grid>
</SelectableTextBlock>
<Line></Line>
<SelectableTextBlock
FontSize="16"
Margin="0,100,0,0"
VerticalAlignment="Center"
TextWrapping="Wrap"
HorizontalAlignment="Center">
请在输入框输入您的问题,我会尽力回答您的问题!
</SelectableTextBlock>

</StackPanel>
</UserControl>
22 changes: 15 additions & 7 deletions src/ChatBox/Pages/Setting.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
</Design.DataContext>

<StackPanel>
<Grid>
<Grid Background="Transparent"

PointerPressed="OnPointerPressed">
<TextBlock
FontSize="24"
Margin="0,60,0,0"
Expand All @@ -27,25 +29,31 @@
<Grid HorizontalAlignment="Center" VerticalAlignment="Center"
Width="400"
Margin="20" ColumnDefinitions="Auto,*"
RowDefinitions="Auto,Auto,Auto,Auto,Auto">
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto">
<TextBlock
Width="130"
Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="0,0,10,10" >
Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="0,0,10,10">
<Run Text="最大Token:"></Run>
<Run Text="{Binding Setting.MaxToken}"></Run>
</TextBlock>

<Slider
Minimum="500"
Maximum="128000"
Value="{Binding Setting.MaxToken}"
Name="MaxTokenTextBox" Grid.Row="2" Grid.Column="1" Margin="0,0,0,10"
/>

Name="MaxTokenTextBox" Grid.Row="2" Grid.Column="1" Margin="0,0,0,10" />

<Button Content="保存"
Width="260"
Grid.Row="4" Grid.Column="1"
Click="SaveSetting" />
<Button
Click="Logout"
Foreground="Red"
Margin="0,10,0,0"
Width="260" Grid.Row="5" Grid.Column="1">
退出登录
</Button>
</Grid>
</StackPanel>
</UserControl>
24 changes: 24 additions & 0 deletions src/ChatBox/Pages/Setting.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using ChatBox.Service;
using ChatBox.ViewModels;
using ChatBox.Views;
Expand Down Expand Up @@ -63,4 +65,26 @@ private void InitializeSetting()

ViewModel.SelectedModelProvider = item ?? models.FirstOrDefault();
}

private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
// 获取当前窗口并调用 BeginMoveDrag
var window = this.GetVisualRoot() as Window;
if (window != null)
{
window.BeginMoveDrag(e);
}
}

private void Logout(object? sender, RoutedEventArgs e)
{
// 如果返回401,清空ApiKey
var settings = HostApplication.Services.GetRequiredService<ISettingService>().LoadSetting();

settings.ApiKey = string.Empty;
HostApplication.Services.GetRequiredService<ISettingService>().SaveSetting(settings);

HostApplication.Logout?.Invoke();

}
}

0 comments on commit 7beb2de

Please sign in to comment.