add: 基础的聊天对话框

This commit is contained in:
jackfiled 2023-10-07 18:55:22 +08:00
parent e2419a1ebd
commit 6bf583151c
10 changed files with 178 additions and 5 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,3 +0,0 @@
@inherits LayoutComponentBase
<main> @Body </main>

View File

@ -0,0 +1,10 @@
namespace Frontend.Models;
public class ChatMessage
{
public required string Sender { get; init; }
public required string Text { get; init; }
public required bool Left { get; init; }
}

View File

@ -1,3 +1,55 @@
@page "/" @page "/"
@using Frontend.Models
<h1>Hello, world!</h1> <Layout>
<Sider Width="200">
</Sider>
<Content>
<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>
</Content>
</Layout>
@code
{
private readonly List<ChatMessage> _messages = new()
{
new ChatMessage
{
Sender = "凯瑟琳",
Text = "向着星辰和深渊!",
Left = true
},
new ChatMessage
{
Sender = "凯瑟琳",
Text = "欢迎来到冒险家协会。",
Left = true
},
new ChatMessage
{
Sender = "旅行者",
Text = "领取每日委托奖励。",
Left = false
}
};
}

View File

@ -0,0 +1,12 @@
.chat-column {
margin-left: auto;
}
.chat-zone {
min-width: inherit;
background: linear-gradient(180deg,
#f5f4f6,
#b5bddf);
min-height: calc(100vh - 64px);
padding: 20px;
}

View File

@ -0,0 +1,27 @@
@inherits LayoutComponentBase
<div>
<Layout>
<Header class="header">
<Space >
<SpaceItem>
<p class="title-text">
自律型可重编程对话机器人
</p>
</SpaceItem>
<SpaceItem>
<p class="subtitle-text">
a.k.a 凯瑟琳
</p>
</SpaceItem>
</Space>
</Header>
<Layout>
<Content>
@Body
</Content>
</Layout>
</Layout>
</div>

View File

@ -0,0 +1,11 @@
.title-text {
font-size: 2rem;
color: white;
margin: 0;
}
.subtitle-text {
font-size: 0.8rem;
color: grey;
margin: 0;
}

View File

@ -0,0 +1,50 @@
@using Frontend.Models
@if (Message.Left)
{
<Space Align="start">
<SpaceItem>
<Avatar Icon="user" Size="2.5rem"/>
</SpaceItem>
<SpaceItem>
<div class="bubble">
<p style="font-size: 1.1rem">
@Message.Text
</p>
<p style="font-size: 0.8rem; color: rgb(128,128,128)">
@Message.Sender
</p>
</div>
</SpaceItem>
</Space>
}
else
{
<Space Align="start">
<SpaceItem>
<div class="bubble">
<p style="font-size: 1.1rem; align-self: flex-end">
@Message.Text
</p>
<p style="font-size: 0.8rem; align-self: flex-end; color: rgb(128, 128, 128)">
@Message.Sender
</p>
</div>
</SpaceItem>
<SpaceItem>
<Avatar Icon="user" Size="2.5rem"/>
</SpaceItem>
</Space>
}
@code {
[Parameter]
public ChatMessage Message { get; set; } = new()
{
Left = true,
Sender = "default",
Text = "default"
};
}

View File

@ -0,0 +1,7 @@
.bubble {
background-color: white;
border-radius: 10px;
padding: 5px;
display: flex;
flex-direction: column;
}

View File

@ -3,3 +3,4 @@
@using Microsoft.JSInterop @using Microsoft.JSInterop
@using AntDesign @using AntDesign
@using Frontend @using Frontend
@using Frontend.Shared