dev: robot interface

This commit is contained in:
jackfiled 2023-10-09 19:32:56 +08:00
parent 70ebd98f14
commit 92b00a3477
8 changed files with 184 additions and 130 deletions

View File

@ -1,6 +1,5 @@
@page "/" @page "/"
@using Frontend.Models
@inject ILogger<Index> Logger
<Layout> <Layout>
<Sider Width="200"> <Sider Width="200">
@ -8,91 +7,10 @@
</Sider> </Sider>
<Content> <Content>
<div class="content-zone"> <Chat />
<div class="chat-zone">
<AntList TItem="ChatMessage" DataSource="@_messages" Split="@false">
<ListItem>
@if (context.Left)
{
<div>
<MessageBubble Message="context"/>
</div>
}
else
{
<div style="margin-left: auto">
<MessageBubble Message="context"/>
</div>
}
</ListItem>
</AntList>
<div style="height: 200px; width: 100%; flex: none">
</div>
</div>
<div class="control-zone">
<div style="padding: 10px 82px 20px">
<div class="input-zone">
<GridRow>
<GridCol Span="22">
<Input TValue="@string" @bind-Value="@MessageSending"
Placeholder="输入以对话" Bordered="@false" OnPressEnter="@SendMessageClicked"/>
</GridCol>
<GridCol Span="2">
<Button Type="@ButtonType.Primary" @onclick="@SendMessageClicked">
发送
</Button>
</GridCol>
</GridRow>
</div>
</div>
</div>
</div>
</Content> </Content>
</Layout> </Layout>
@code @code {
{
private string MessageSending { get; set; } = string.Empty;
private readonly List<ChatMessage> _messages = new()
{
new ChatMessage
{
Sender = "凯瑟琳",
Text = "向着星辰和深渊!",
Left = true
},
new ChatMessage
{
Sender = "凯瑟琳",
Text = "欢迎来到冒险家协会。",
Left = true
}
};
private void SendMessageClicked()
{
if (string.IsNullOrWhiteSpace(MessageSending))
{
return;
}
_messages.Add(new ChatMessage
{
Left = false,
Sender = "旅行者",
Text = MessageSending
});
MessageSending = string.Empty;
_messages.Add(new ChatMessage
{
Left = true,
Sender = "凯瑟琳",
Text = "对不起,做不到。"
});
}
} }

View File

@ -1,42 +0,0 @@
.chat-column {
margin-left: auto;
}
.content-zone {
align-items: center;
display: flex;
flex-direction: column;
width: 100%;
min-height: calc(100vh - 64px);
max-height: calc(100vh - 64px);
padding: 10px;
position: relative;
background: linear-gradient(180deg,
#f5f4f6,
#b5bddf);
overflow: hidden;
}
.chat-zone {
min-width: 100%;
display: flex;
flex-direction: column;
position: relative;
height: 100%;
overflow-y: auto;
}
.control-zone {
min-width: 100%;
bottom: 0;
position: absolute;
background-color: #b5bddf;
display: block;
box-shadow: 3px 0 0 #b5bddf;
}
.input-zone {
padding: 10px;
border-radius: 15px;
background-color: white;
}

View File

@ -0,0 +1,88 @@
@using Frontend.Models
<div class="content-zone">
<div class="chat-zone">
<AntList TItem="ChatMessage" DataSource="@_messages" Split="@false">
<ListItem>
@if (context.Left)
{
<div>
<MessageBubble Message="context"/>
</div>
}
else
{
<div style="margin-left: auto">
<MessageBubble Message="context"/>
</div>
}
</ListItem>
</AntList>
<div style="height: 200px; width: 100%; flex: none">
</div>
</div>
<div class="control-zone">
<div style="padding: 10px 82px 20px">
<div class="input-zone">
<GridRow>
<GridCol Span="22">
<Input TValue="@string" @bind-Value="@MessageSending"
Placeholder="输入以对话" Bordered="@false" OnPressEnter="@SendMessageClicked"/>
</GridCol>
<GridCol Span="2">
<Button Type="@ButtonType.Primary" @onclick="@SendMessageClicked">
发送
</Button>
</GridCol>
</GridRow>
</div>
</div>
</div>
</div>
@code
{
private string MessageSending { get; set; } = string.Empty;
private readonly List<ChatMessage> _messages = new()
{
new ChatMessage
{
Sender = "凯瑟琳",
Text = "向着星辰和深渊!",
Left = true
},
new ChatMessage
{
Sender = "凯瑟琳",
Text = "欢迎来到冒险家协会。",
Left = true
}
};
private void SendMessageClicked()
{
if (string.IsNullOrWhiteSpace(MessageSending))
{
return;
}
_messages.Add(new ChatMessage
{
Left = false,
Sender = "旅行者",
Text = MessageSending
});
MessageSending = string.Empty;
_messages.Add(new ChatMessage
{
Left = true,
Sender = "凯瑟琳",
Text = "对不起,做不到。"
});
}
}

View File

@ -0,0 +1,58 @@
.chat-column {
margin-left: auto;
}
.content-zone {
align-items: center;
display: flex;
flex-direction: column;
width: 100%;
min-height: calc(100vh - 64px);
max-height: calc(100vh - 64px);
padding: 10px;
position: relative;
background: linear-gradient(180deg,
#f5f4f6,
#b5bddf);
overflow: hidden;
}
.chat-zone {
min-width: 100%;
display: flex;
flex-direction: column;
position: relative;
height: 100%;
overflow-y: auto;
}
.chat-zone::-webkit-scrollbar {
width: 10px;
height: 1px;
}
.chat-zone::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
background: #bdbdbd;
}
.chat-zone::-webkit-scrollbar-track {
border-radius: 10px;
background: #fff;
}
.control-zone {
min-width: 100%;
bottom: 0;
position: absolute;
background-color: #b5bddf;
display: block;
box-shadow: 3px 0 0 #b5bddf;
}
.input-zone {
padding: 10px;
border-radius: 15px;
background-color: white;
}

View File

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend", "Frontend\Frontend.csproj", "{6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend", "Frontend\Frontend.csproj", "{6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Katheryne", "Katheryne\Katheryne.csproj", "{74F745FB-2F2B-4B56-A387-3B490EFE9615}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}.Debug|Any CPU.Build.0 = Debug|Any CPU {6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}.Release|Any CPU.ActiveCfg = Release|Any CPU {6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}.Release|Any CPU.Build.0 = Release|Any CPU {6DD57D75-C2C2-48DA-A7FB-8FA9BEBBBA99}.Release|Any CPU.Build.0 = Release|Any CPU
{74F745FB-2F2B-4B56-A387-3B490EFE9615}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74F745FB-2F2B-4B56-A387-3B490EFE9615}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74F745FB-2F2B-4B56-A387-3B490EFE9615}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74F745FB-2F2B-4B56-A387-3B490EFE9615}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Katheryne/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -0,0 +1,15 @@
namespace Katheryne.Abstractions;
/// <summary>
/// 对话机器人接口
/// </summary>
public interface IChatRobot
{
public string RobotName { get; }
public IEnumerable<string> OnChatStart();
public IEnumerable<string> OnChatStop();
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>