优化聊天界面样式与功能支持

更新聊天气泡样式,增加圆角、阴影及悬停动画,分离发送与接收消息的样式,改进消息元信息布局。
支持深色模式,优化滚动条样式,增强小屏设备的响应式设计。
调整文件上传组件样式,更新颜色变量,替换背景为单色设计,提升层次感。
改进Markdown与代码块样式,增加`.think`类样式调整,统一消息布局。
新增消息气泡弹出动画,优化输入栏样式,整体提升用户体验与视觉效果。
This commit is contained in:
zyxucp
2025-10-05 15:31:49 +08:00
parent d6b2c3a08b
commit 97548b0d2b

View File

@@ -15,42 +15,50 @@
<Virtualize Items="@(MessageList.OrderBy(o => o.CreateTime).ToList())" Context="item">
@if (item.IsSend)
{
<GridRow>
<GridRow Class="message-row" Gutter="(8,8)">
<GridCol Span="23">
<div class="chat-bubble sent">
<Popover Title="@item.CreateTime.ToString()">
<Unbound>
<Flex Vertical RefBack="context">
@if (item.FileName != null)
{
<p class="message-file">
<Upload DefaultFileList="[new(){ FileName= item.FileName }]" />
</p>
}
<p class="bubble-text">@(item.Context)</p>
</Flex>
</Unbound>
</Popover>
<div class="message-shell sent">
<div class="chat-bubble sent">
<Popover Title="@item.CreateTime.ToString()">
<Unbound>
<Flex Vertical RefBack="context" Class="bubble-body">
@if (item.FileName != null)
{
<p class="message-file">
<Upload DefaultFileList="[new(){ FileName= item.FileName }]" />
</p>
}
<p class="bubble-text">@(item.Context)</p>
</Flex>
</Unbound>
</Popover>
</div>
<div class="message-meta meta-right">
<span>@item.CreateTime.ToString("HH:mm")</span>
<Icon Class="meta-action" Type="copy" Theme="outline" OnClick="async () =>await OnCopyAsync(item)" />
</div>
</div>
<div class="message-meta meta-right">@item.CreateTime.ToString("HH:mm")</div>
<Icon Style="float:right;margin-top:10px;" Type="copy" Theme="outline" OnClick="async () =>await OnCopyAsync(item)" />
</GridCol>
<GridCol Span="1">
<Image Class="avatar" Width="28px" Height="28px" Src="./assets/KDpgvguMpGfqaHPjicRK.svg" />
<GridCol Span="1" Class="avatar-col">
<Image Class="avatar" Width="32px" Height="32px" Src="./assets/KDpgvguMpGfqaHPjicRK.svg" />
</GridCol>
</GridRow>
}
else
{
<GridRow>
<GridCol Span="1">
<Image Class="avatar" Width="28px" Height="28px" Style="margin-top:10px;" Src="./assets/method-draw-image.svg" />
<GridRow Class="message-row" Gutter="(8,8)">
<GridCol Span="1" Class="avatar-col">
<Image Class="avatar" Width="32px" Height="32px" Src="./assets/method-draw-image.svg" />
</GridCol>
<GridCol Span="23">
<div class="chat-bubble received">
@((MarkupString)(item.Context))
<div class="message-shell received">
<div class="chat-bubble received">
@((MarkupString)(item.Context))
</div>
<div class="message-meta meta-left">
<span>@item.CreateTime.ToString("HH:mm")</span>
</div>
</div>
<div class="message-meta meta-left">@item.CreateTime.ToString("HH:mm")</div>
</GridCol>
</GridRow>
}
@@ -83,12 +91,23 @@
<style>
:root {
--bg-start: #f7f9fc;
--bg-end: #eef2f7;
--surface-base: #ffffff;
--surface-elevated: #f5f7fb;
--border-subtle: rgba(15, 23, 42, 0.07);
--shadow-soft: 0 16px 28px rgba(15, 23, 42, 0.08);
--primary-color: var(--ant-primary-color, #1677ff);
--primary-soft: rgba(22, 119, 255, 0.12);
--bubble-recv: #ffffff;
--bubble-sent: #daf8cb;
--bubble-border: rgba(0,0,0,0.06);
--text-secondary: #8a8f98;
--bubble-sent: #dce8ff;
--bubble-border-sent: rgba(22, 119, 255, 0.25);
--text-primary: #1f2329;
--text-secondary: #7a808a;
}
@@supports (color: color-mix(in srgb, white 50%, black 50%)) {
:root {
--bubble-sent: color-mix(in srgb, var(--primary-color) 28%, white);
}
}
#chat {
@@ -97,116 +116,279 @@
gap: 8px;
height: 100%;
min-height: 65vh;
background: linear-gradient(180deg, var(--bg-start), var(--bg-end));
border-radius: 8px;
padding: 8px 8px 0 8px;
background: var(--surface-base);
border-radius: 16px;
padding: 12px 12px 0 12px;
box-sizing: border-box;
border: 1px solid var(--border-subtle);
box-shadow: var(--shadow-soft);
}
#scrollDiv {
background: transparent;
border-radius: 8px;
background: var(--surface-base);
border-radius: 12px;
box-sizing: border-box;
scroll-behavior: smooth;
padding: 6px 8px 18px;
}
/* custom scrollbar */
#scrollDiv::-webkit-scrollbar { height: 8px; width: 8px; }
#scrollDiv::-webkit-scrollbar-thumb { background: #c7cbd1; border-radius: 8px; }
#scrollDiv::-webkit-scrollbar-track { background: transparent; }
#scrollDiv::-webkit-scrollbar-thumb { background: rgba(22, 119, 255, 0.22); border-radius: 8px; }
#scrollDiv::-webkit-scrollbar-track { background: rgba(15, 23, 42, 0.03); }
.message-row {
margin-bottom: 4px;
}
.message-shell {
display: flex;
flex-direction: column;
gap: 6px;
}
.message-shell.sent {
align-items: flex-end;
}
.message-shell.received {
align-items: flex-start;
}
.chat-bubble {
padding: 12px 14px;
margin: 6px 10px;
border-radius: 14px;
display: inline-flex;
flex-direction: column;
gap: 6px;
padding: 14px 16px;
border-radius: 16px;
max-width: 78%;
position: relative;
box-shadow: 0 1px 2px rgba(0,0,0,0.04);
border: 1px solid var(--bubble-border);
box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
border: none;
word-break: break-word;
line-height: 1.6;
animation: pop .18s ease-out;
line-height: 1.65;
animation: pop .2s ease-out;
transition: transform .2s ease, box-shadow .2s ease;
}
.chat-bubble .bubble-text { margin: 0; white-space: pre-wrap; }
.received {
background-color: var(--bubble-recv);
align-self: flex-start;
float: left;
.chat-bubble:hover {
transform: translateY(-1px);
box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
}
.sent {
background-color: var(--bubble-sent);
align-self: flex-end;
float: right;
.chat-bubble .bubble-text {
margin: 0;
white-space: pre-wrap;
color: var(--text-primary);
}
.chat-bubble .bubble-body {
gap: 10px;
}
.chat-bubble.received {
background: var(--bubble-recv);
box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06), inset 0 0 0 1px rgba(15, 23, 42, 0.05);
}
.chat-bubble.sent {
background: var(--bubble-sent);
color: #0c1a33;
box-shadow: 0 12px 26px rgba(22, 119, 255, 0.18);
}
.chat-bubble.sent .bubble-text {
color: #102347;
}
/* bubble tails */
.chat-bubble.received::after {
content: "";
position: absolute; left: -6px; bottom: 10px;
width: 10px; height: 10px; background: var(--bubble-recv);
border-left: 1px solid var(--bubble-border);
border-bottom: 1px solid var(--bubble-border);
transform: rotate(45deg);
border-bottom-left-radius: 2px;
}
.chat-bubble.received::after,
.chat-bubble.sent::after {
content: "";
position: absolute; right: -6px; bottom: 10px;
width: 10px; height: 10px; background: var(--bubble-sent);
border-right: 1px solid var(--bubble-border);
border-bottom: 1px solid var(--bubble-border);
transform: rotate(45deg);
border-bottom-right-radius: 2px;
position: absolute;
bottom: 16px;
width: 16px;
height: 18px;
transform: none;
border-radius: 0;
box-shadow: none !important;
filter: none !important;
}
.chat-bubble.received::after {
left: -12px;
background: var(--bubble-recv);
clip-path: polygon(100% 0, 0 50%, 100% 100%);
}
.chat-bubble.sent::after {
right: -12px;
background: var(--bubble-sent);
clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.message-meta {
font-size: 12px;
color: var(--text-secondary);
margin: 2px 12px 4px;
clear: both;
display: flex;
align-items: center;
gap: 8px;
margin: 0;
}
@@keyframes pop {
from { transform: translateY(4px); opacity: .65; }
to { transform: translateY(0); opacity: 1; }
}
.meta-right { text-align: right; }
.meta-left { text-align: left; }
.avatar { border-radius: 50%; box-shadow: 0 0 0 1px #e6e8eb inset; }
.meta-right {
justify-content: flex-end;
}
.meta-left {
justify-content: flex-start;
padding-left: 4px;
}
.meta-action {
color: var(--text-secondary);
cursor: pointer;
transition: color .2s ease;
}
.meta-action:hover {
color: var(--primary-color);
}
.avatar-col {
display: flex;
justify-content: center;
}
.avatar {
border-radius: 50%;
box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12) inset, 0 6px 16px rgba(15, 23, 42, 0.12);
}
.input-bar {
gap: 8px;
padding: 8px 8px 12px;
border-top: 1px solid #e6e8eb;
background: rgba(255,255,255,0.6);
backdrop-filter: blur(4px);
padding: 12px;
border-top: 1px solid rgba(15, 23, 42, 0.06);
background: var(--surface-base);
position: sticky;
bottom: 0;
box-shadow: 0 -12px 24px rgba(15, 23, 42, 0.06);
}
.input-bar .ant-input {
border-radius: 10px;
}
/* markdown & code inside bubbles */
.chat-bubble pre { background:#0b1021; color:#e6e6e6; padding:12px; border-radius:10px; overflow:auto; }
.chat-bubble code { background: rgba(27,31,35,0.06); padding: .15rem .35rem; border-radius: 6px; }
.chat-bubble pre code { background: transparent; padding: 0; }
.chat-bubble table { width: 100%; border-collapse: collapse; }
.chat-bubble table td, .chat-bubble table th { border: 1px solid #e6e8eb; padding: 6px 8px; }
.chat-bubble pre {
background: #0b1021;
color: #e6e6e6;
padding: 12px;
border-radius: 12px;
overflow: auto;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.ant-card-body { height: 90% !important; }
.chat-bubble code {
background: rgba(27, 31, 35, 0.08);
padding: .15rem .35rem;
border-radius: 6px;
}
.chat-bubble pre code {
background: transparent;
padding: 0;
}
.chat-bubble table {
width: 100%;
border-collapse: collapse;
}
.chat-bubble table td,
.chat-bubble table th {
border: 1px solid rgba(15, 23, 42, 0.08);
padding: 6px 8px;
}
.think {
color: gray;
color: rgba(22, 119, 255, 0.9);
font-style: italic;
text-align: left !important;
display: block;
margin-top: 5px;
margin-left: 8px;
padding-left: 8px;
border-left: 2px solid #7F7FFF;
padding-left: 10px;
border-left: 3px solid rgba(22, 119, 255, 0.4);
}
.message-file { margin: 0 0 6px 0; }
.message-file {
margin: 0;
border-radius: 10px;
overflow: hidden;
}
.message-file .ant-upload-list-item {
background: rgba(22, 119, 255, 0.08);
border: none !important;
}
@@media (max-width: 992px) {
#chat {
border-radius: 12px;
padding: 10px 10px 0;
}
.chat-bubble {
max-width: 88%;
}
.input-bar {
flex-wrap: wrap;
}
}
@@media (prefers-color-scheme: dark) {
:root {
--surface-base: #111827;
--surface-elevated: #1f2937;
--border-subtle: rgba(148, 163, 184, 0.16);
--shadow-soft: 0 18px 34px rgba(0, 0, 0, 0.45);
--text-primary: #f1f5f9;
--text-secondary: #94a3b8;
--bubble-recv: #1f2937;
}
#chat {
background: var(--surface-elevated);
}
#scrollDiv {
background: transparent;
}
.chat-bubble {
border: 1px solid rgba(148, 163, 184, 0.16);
}
.chat-bubble.received::after {
background: var(--bubble-recv);
border: none;
}
.message-file .ant-upload-list-item {
background: rgba(22, 119, 255, 0.16);
}
.input-bar {
background: var(--surface-elevated);
}
}
@@keyframes pop {
from { transform: translateY(6px); opacity: .55; }
to { transform: translateY(0); opacity: 1; }
}
</style>
@code {