You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/AI/Views/MainWindow.axaml

367 lines
12 KiB
Plaintext

1 month ago
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:AI.ViewModels"
xmlns:md="clr-namespace:LiveMarkdown.Avalonia;assembly=LiveMarkdown.Avalonia"
xmlns:models="using:AI.Models"
xmlns:converters="using:AI.Converters"
xmlns:storage="using:Avalonia.Platform.Storage"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="1200" d:DesignHeight="700"
x:Class="AI.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Title="AI"
Width="1200" Height="700">
<Grid Background="#FFFFFF">
<Grid.ColumnDefinitions>
<!-- 左侧会话列表 -->
<ColumnDefinition Width="280" />
<!-- 分隔线 -->
<ColumnDefinition Width="1" />
<!-- 右侧聊天区域 -->
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- 左侧会话列表区域 -->
<Grid Grid.Column="0" Background="#F5F5F5">
<Border Padding="10,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- 新建会话按钮 -->
<Button Grid.Row="0"
Content="创建新会话"
Background="Transparent"
Foreground="#333333"
Height="36"
CornerRadius="10"
HorizontalAlignment="Stretch"
FontWeight="SemiBold"
Command="{Binding CreateNewSessionCommand}" />
<!-- 空白间隔 -->
<Border Grid.Row="1" Height="10" />
<!-- 所有对话标签 -->
<TextBlock Grid.Row="2"
Text="所有对话"
Foreground="#999999"
Height="32"
FontSize="14"
Margin="10,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom" />
<!-- 会话列表 -->
<ListBox x:Name="SessionsListBox"
Grid.Row="3"
ItemsSource="{Binding Sessions}"
SelectedItem="{Binding SelectedSessionItem}"
Background="Transparent"
BorderThickness="0"
Margin="0,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate DataType="vm:ChatSessionItemViewModel">
<Grid Margin="8,0" Height="36">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0"
Grid.Column="0"
Text="{Binding Title}"
FontSize="14"
FontWeight="SemiBold"
TextTrimming="CharacterEllipsis"
VerticalAlignment="Center"
Foreground="#333333" />
<Button Grid.Row="0"
Grid.Column="1"
Content=""
Width="20"
Height="20"
FontSize="16"
Background="Transparent"
Foreground="#999999"
BorderThickness="0"
Padding="0"
Click="OnDeleteSessionClick"
Tag="{Binding Id}"
ToolTip.Tip="删除会话"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<Button.Styles>
<Style Selector="Button">
<Setter Property="CornerRadius" Value="10" />
</Style>
</Button.Styles>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Padding" Value="0" />
</Style>
<Style Selector="ListBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="#EAEAEA" />
<Setter Property="CornerRadius" Value="10" />
</Style>
<Style Selector="ListBoxItem:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="#EFEFEF" />
<Setter Property="CornerRadius" Value="10" />
</Style>
</ListBox.Styles>
</ListBox>
</Grid>
</Border>
</Grid>
<!-- 分隔线 -->
<Border Grid.Column="1" Background="#E0E0E0" />
<!-- 右侧聊天区域 -->
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- 聊天消息区域 -->
<ScrollViewer x:Name="ChatMessagesScrollViewer" Grid.Row="0" Margin="20,20,20,0">
<ItemsControl x:Name="ChatMessagesItemsControl"
ItemsSource="{Binding ChatMessages}"
ItemTemplate="{StaticResource MessageTemplateSelector}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
<!-- 聊天输入区域 -->
<Grid Grid.Row="1" Margin="20,0,20,20">
<!-- 输入框容器 -->
<Border Background="#F7F8FC"
CornerRadius="20"
Padding="12,8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- 显示待上传文件列表 -->
<WrapPanel Grid.Row="0"
Orientation="Horizontal"
Margin="0,0,0,5">
<ItemsControl ItemsSource="{Binding PendingFiles}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="models:PendingFileModel">
<Grid Margin="2,2">
<Border Background="White"
CornerRadius="8"
BorderBrush="#E1E3EA"
BorderThickness="1"
Padding="8,4">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- 文件图标 -->
<Viewbox Grid.Row="0" Grid.Column="0"
Grid.RowSpan="2"
Width="16" Height="16"
VerticalAlignment="Center"
Margin="0,0,8,0">
<Path Fill="#666666"
Data="M886.7 247.6L713.4 73.4c-6-6-14.2-9.4-22.7-9.4H192c-35.3 0-64 28.7-64 64v768c0 35.3 28.7 64 64 64h640c35.3 0 64-28.7 64-64V270.2c0-8.5-3.3-16.6-9.3-22.6zM832 864c0 17.7-14.3 32-32 32H224c-17.7 0-32-14.3-32-32V160c0-17.7 14.3-32 32-32h384v160c0 35.3 28.7 64 64 64h160v512zM704 288c-17.7 0-32-14.3-32-32V128l160 160H704z M671 672H287c-17.7 0-32 14.3-32 32s14.3 32 32 32h384c17.7 0 32-14.3 32-32s-14.3-32-32-32zM287 480c-17.7 0-32 14.3-32 32s14.3 32 32 32h384c17.7 0 32-14.3 32-32s-14.3-32-32-32H287zM287 352h192c17.7 0 32-14.3 32-32s-14.3-32-32-32H287c-17.7 0-32 14.3-32 32s14.3 32 32 32z" />
</Viewbox>
<TextBlock Grid.Row="0" Grid.Column="1"
Text="{Binding Name}"
VerticalAlignment="Center"
FontSize="12"
Foreground="#333333"
Margin="0,0,16,0"
TextTrimming="CharacterEllipsis"/>
<TextBlock Grid.Row="1" Grid.Column="1"
Text="{Binding FormattedSize}"
VerticalAlignment="Center"
FontSize="10"
Foreground="#666666"
Margin="0,0,16,0"/>
</Grid>
</Border>
<!-- 删除按钮 -->
<Button Content=""
Width="14"
Height="14"
FontSize="10"
Background="Transparent"
CornerRadius="7"
Foreground="#999999"
BorderThickness="0"
Padding="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Margin="0,3,3,0"
Command="{Binding $parent[Window].DataContext.RemovePendingFileCommand}"
CommandParameter="{Binding}">
</Button>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</WrapPanel>
<!-- 文本输入框 -->
<TextBox Grid.Row="1"
Name="ChatInputBox"
Background="Transparent"
Foreground="#333333"
BorderThickness="0"
AcceptsReturn="True"
TextWrapping="Wrap"
MaxHeight="100"
MinHeight="30"
Margin="0,0,0,5"
Text="{Binding ChatInput, UpdateSourceTrigger=PropertyChanged}">
<TextBox.Styles>
<Style Selector="TextBox">
<Setter Property="Background" Value="Transparent" />
</Style>
<Style Selector="TextBox:focus">
<Setter Property="Background" Value="Transparent" />
</Style>
<Style Selector="TextBox /template/ Border#border">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="TextBox:focus /template/ Border#border">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="TextBox:focus /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent" />
</Style>
</TextBox.Styles>
</TextBox>
<!-- 底部控制栏 -->
<Grid Grid.Row="2" Height="36">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- 文件上传按钮 -->
<Button Grid.Column="0"
Content="+"
Background="Transparent"
Foreground="#666666"
BorderThickness="0"
FontSize="22"
Width="32"
Height="32"
Padding="0"
Margin="0,0,8,0"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Command="{Binding AddPendingFileCommand}">
<Button.Styles>
<Style Selector="Button:pointerover">
<Setter Property="Background" Value="#E8E8E8" />
</Style>
</Button.Styles>
</Button>
<!-- 模式切换 ComboBox -->
<ComboBox Grid.Column="1"
SelectedIndex="{Binding CurrentWorkflowModeIndex}"
Width="100"
Height="32"
Padding="8,4"
Background="Transparent"
BorderThickness="1"
BorderBrush="#E0E0E0"
CornerRadius="8"
FontSize="13">
<ComboBoxItem Content="Ask" />
<ComboBoxItem Content="Workflow" />
</ComboBox>
<!-- 发送按钮 -->
<Button Grid.Column="3"
Background="#007AFF"
Foreground="White"
CornerRadius="8"
Width="70"
Height="32"
FontSize="14"
FontWeight="SemiBold"
Content="发送"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
BorderThickness="0"
Command="{Binding SendMessageCommand}">
</Button>
<!-- 取消工作流按钮(仅工作流模式且执行中时可用) -->
<Button Grid.Column="4"
Background="#FF3B30"
Foreground="White"
CornerRadius="8"
Width="70"
Height="32"
FontSize="14"
FontWeight="SemiBold"
Content="取消"
Margin="8,0,0,0"
IsVisible="{Binding IsWorkflowRunning}"
IsEnabled="{Binding IsWorkflowRunning}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
BorderThickness="0"
Command="{Binding CancelWorkflowCommand}">
</Button>
</Grid>
</Grid>
</Border>
</Grid>
</Grid>
</Grid>
</Window>