2023-10-09 19:32:56 +08:00
|
|
|
@using Frontend.Models
|
2023-10-11 14:23:38 +08:00
|
|
|
@using Katheryne.Abstractions
|
2023-10-09 19:32:56 +08:00
|
|
|
|
|
|
|
<div class="content-zone">
|
|
|
|
<div class="chat-zone">
|
2023-10-11 11:54:28 +08:00
|
|
|
<AntList TItem="ChatMessage" DataSource="@Messages" Split="@false">
|
2023-10-09 19:32:56 +08:00
|
|
|
<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;
|
|
|
|
|
2023-10-11 11:54:28 +08:00
|
|
|
[Parameter]
|
|
|
|
public List<ChatMessage> Messages { get; set; } = null!;
|
2023-10-09 19:32:56 +08:00
|
|
|
|
2023-10-11 14:23:38 +08:00
|
|
|
[Parameter]
|
|
|
|
public IChatRobot Robot { get; set; } = null!;
|
|
|
|
|
2023-10-09 19:32:56 +08:00
|
|
|
private void SendMessageClicked()
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(MessageSending))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-11 11:54:28 +08:00
|
|
|
Messages.Add(new ChatMessage
|
2023-10-09 19:32:56 +08:00
|
|
|
{
|
|
|
|
Left = false,
|
|
|
|
Sender = "旅行者",
|
|
|
|
Text = MessageSending
|
|
|
|
});
|
|
|
|
|
2023-10-11 14:23:38 +08:00
|
|
|
foreach (string answer in Robot.ChatNext(MessageSending))
|
2023-10-09 19:32:56 +08:00
|
|
|
{
|
2023-10-11 14:23:38 +08:00
|
|
|
Messages.Add(new ChatMessage
|
|
|
|
{
|
|
|
|
Left = true,
|
|
|
|
Sender = Robot.RobotName,
|
|
|
|
Text = answer
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageSending = string.Empty;
|
2023-10-09 19:32:56 +08:00
|
|
|
}
|
|
|
|
}
|