Skip to content

Commit

Permalink
完善此前内容+可继承历史对话
Browse files Browse the repository at this point in the history
  • Loading branch information
mehaifeng committed May 5, 2023
1 parent 9dc7649 commit 4939adb
Show file tree
Hide file tree
Showing 9 changed files with 437 additions and 31 deletions.
15 changes: 9 additions & 6 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<SolidColorBrush x:Key="ForegroundColor" Color="Black"/>
<SolidColorBrush x:Key="TextBoxBackgroundColor" Color="#F5F5F5"/>
<SolidColorBrush x:Key="TextBoxForegroundColor" Color="Black"/>
<SolidColorBrush x:Key="LabelForegroundColor" Color="LightGray"/>
<SolidColorBrush x:Key="LabelForegroundColor" Color="#36454f"/>
<SolidColorBrush x:Key="ButtonBackgroundColor" Color="LightGray"/>
<!--黑暗模式颜色-->
<SolidColorBrush x:Key="DarkBackgroundColor" Color="#1F1F1F"/>
Expand All @@ -29,11 +29,14 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer x:Name="PART_ContentHost"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer
x:Name="PART_ContentHost"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
Expand Down
3 changes: 3 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ namespace VisualChatBot
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
}
}
}
28 changes: 28 additions & 0 deletions Assets/Styles/DefaultStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!--菜单TroggleButton样式-->
<ControlTemplate TargetType="ToggleButton" x:Key="MenuToggleTemplate">
<Border
x:Name="borderBack"
Cursor="Hand"
BorderThickness="0,0,0,1">
<TextBlock
Cursor="Hand"
Background="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToggleButton}, Path=Background}"
Text="{Binding Content, RelativeSource={RelativeSource AncestorType=ToggleButton,Mode=FindAncestor}}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="borderBack" Property="Background" Value="#C0C0C0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!--TextBox样式-->
<ControlTemplate TargetType="TextBox" x:Key="TextBoxStyle">
<Border
Expand Down Expand Up @@ -174,4 +193,13 @@
</Grid>
</Border>
</ControlTemplate>
<!--ListBoxItem样式-->
<Style TargetType="ListBoxItem" x:Key="ListBoxItemStyle">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
2 changes: 1 addition & 1 deletion Models/HistoryRecode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace VisualChatBot.Models
{
public class LastMessage
public class HistoryMessage
{
/// <summary>
/// 上次的所有对话
Expand Down
5 changes: 5 additions & 0 deletions Models/HttpGetModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class HttpGetModel
/// </summary>
[JsonIgnore]
public static bool IsValidApiKey { get; set; } = true;
/// <summary>
/// 请求是否成功
/// </summary>
[JsonIgnore]
public static bool IsRequestSuccess { get; set; }

[JsonProperty("id")]
public string? Id { get; set; }
Expand Down
23 changes: 23 additions & 0 deletions Tools/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
using System.Xml;

namespace VisualChatBot.Tools
{
public static class Extensions
{
public static string ToXAMLString(this UIElement element)
{
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
XamlWriter.Save(element, xmlWriter);
return stringWriter.ToString();
}
}
}
11 changes: 8 additions & 3 deletions Tools/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class WebRequest
responType = JsonConvert.DeserializeObject<HttpGetModel>(responseContent);
if (response.IsSuccessStatusCode == false)
{
HttpGetModel.IsRequestSuccess = false;
if (responType.error.code == "invalid_api_key")
{
HttpGetModel.IsValidApiKey = false;
Expand All @@ -38,9 +39,13 @@ public class WebRequest
string errorInfo = $"\n#错误类型:{responType.error.type}\n#错误内容:{responType.error.message}";
return errorInfo;
}
HttpGetModel.IsValidApiKey = true;
// 返回接收到的内容
return await Task.FromResult(result: responType?.Choicese?.First().MessageDetail.content);
else
{
HttpGetModel.IsRequestSuccess = true;
HttpGetModel.IsValidApiKey = true;
// 返回接收到的内容
return await Task.FromResult(result: responType?.Choicese?.First().MessageDetail.content);
}
}
catch(Exception ex)
{
Expand Down
Loading

0 comments on commit 4939adb

Please sign in to comment.