Skip to content

Commit ac1cf33

Browse files
authored
Merge pull request #345 from vuepress-reco/feature/ai-component
chore: Rebuilding the interactive form of ai chat
2 parents 40adef8 + 2dbdd6f commit ac1cf33

File tree

3 files changed

+399
-28
lines changed

3 files changed

+399
-28
lines changed

packages/@vuepress-reco/plugin-ai-chat/src/client/components/AIChat.vue

Lines changed: 165 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<template>
2-
<section class="ai-chat">
2+
<section class="ai-chat-inner">
33
<div class="chat-container">
4-
<div class="chat-header">
5-
<h2>Vuepress Reco AI Chat (Beta)</h2>
6-
</div>
74
<div class="chat-messages" ref="chatMessagesRef">
85
<div v-for="(message, index) in messages" :key="index"
96
:class="['message', message.role === 'user' ? 'user-message' : 'assistant-message']">
@@ -20,11 +17,6 @@
2017
<!-- 移除多余的loading效果,只使用消息中的"正在思考..."文本作为loading指示 -->
2118
</div>
2219
<div class="chat-input-container">
23-
<div class="chat-control-buttons">
24-
<button class="control-button" @click="clearChatHistory" :disabled="loading || typing">
25-
<span>清除历史</span>
26-
</button>
27-
</div>
2820
<div class="chat-input">
2921
<input
3022
type="text"
@@ -34,15 +26,13 @@
3426
:disabled="loading || typing"
3527
/>
3628
<button @click="sendMessage" :disabled="loading || typing || !userInput.trim()">
37-
<span v-if="!loading && !typing">发送</span>
29+
<svg v-if="!loading && !typing" class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 14L21 3"></path><path d="M21 3l-6.5 18a.55.55 0 0 1-1 0L10 14l-7-3.5a.55.55 0 0 1 0-1L21 3"></path></g></svg>
3830
<span v-else-if="typing">回复中...</span>
3931
<span v-else>处理中...</span>
4032
</button>
4133
</div>
4234
</div>
4335
</div>
44-
45-
4636
</section>
4737
</template>
4838

@@ -999,15 +989,173 @@ const scrollToBottom = () => {
999989
// 组件挂载时滚动到底部
1000990
onMounted(() => {
1001991
scrollToBottom()
992+
// 将原来的欢迎消息替换为更适合弹窗的消息
993+
messages.value = [
994+
{
995+
role: 'assistant',
996+
content: '你好!我是Vuepress Reco文档智能助手,有什么可以帮到你的?',
997+
displayContent: '你好!我是Vuepress Reco文档智能助手,有什么可以帮到你的?'
998+
}
999+
]
10021000
})
10031001
10041002
// 消息已经在渲染时高亮,不需要额外的监听处理
10051003
</script>
10061004

1005+
<style>
1006+
/* 为嵌入弹窗的AI聊天组件添加样式 */
1007+
.ai-chat-inner {
1008+
display: flex;
1009+
flex-direction: column;
1010+
height: 100%;
1011+
width: 100%;
1012+
overflow: hidden;
1013+
}
1014+
1015+
.ai-chat-inner .chat-container {
1016+
display: flex;
1017+
flex-direction: column;
1018+
height: 100%;
1019+
width: 100%;
1020+
overflow: hidden;
1021+
padding: 0;
1022+
margin: 0;
1023+
border-radius: 0;
1024+
box-shadow: none;
1025+
}
1026+
1027+
.ai-chat-inner .chat-messages {
1028+
flex: 1;
1029+
overflow-y: auto;
1030+
padding: 16px;
1031+
display: flex;
1032+
flex-direction: column;
1033+
}
1034+
1035+
.ai-chat-inner .chat-input-container {
1036+
padding: 10px;
1037+
border-top: 1px solid rgba(0, 0, 0, 0.1);
1038+
background-color: #fff;
1039+
}
1040+
1041+
.ai-chat-inner .message {
1042+
margin-bottom: 16px;
1043+
display: flex;
1044+
flex-direction: column;
1045+
}
1046+
1047+
.ai-chat-inner .message-content {
1048+
display: flex;
1049+
max-width: 100%;
1050+
}
1051+
1052+
.ai-chat-inner .user-message .message-content {
1053+
justify-content: flex-end;
1054+
}
1055+
1056+
.ai-chat-inner .message-text {
1057+
padding: 10px 14px;
1058+
border-radius: 10px;
1059+
max-width: 85%;
1060+
overflow-wrap: break-word;
1061+
font-size: 14px;
1062+
line-height: 1.5;
1063+
}
1064+
1065+
.ai-chat-inner .user-message .message-text {
1066+
background-color: var(--c-brand, #3eaf7c);
1067+
color: white;
1068+
}
1069+
1070+
.ai-chat-inner .assistant-message .message-text {
1071+
background-color: #f1f1f1;
1072+
color: #333;
1073+
}
1074+
1075+
.ai-chat-inner .message-avatar {
1076+
width: 30px;
1077+
height: 30px;
1078+
border-radius: 50%;
1079+
display: flex;
1080+
align-items: center;
1081+
justify-content: center;
1082+
margin: 0 8px;
1083+
}
1084+
1085+
.ai-chat-inner .assistant-avatar {
1086+
background-color: var(--c-brand, #3eaf7c);
1087+
color: white;
1088+
}
1089+
1090+
.ai-chat-inner .user-avatar {
1091+
background-color: #6c757d;
1092+
color: white;
1093+
}
1094+
1095+
/* 控制按钮样式 */
1096+
.ai-chat-inner .chat-control-buttons {
1097+
display: flex;
1098+
justify-content: flex-end;
1099+
margin-bottom: 8px;
1100+
}
1101+
1102+
.ai-chat-inner .control-button {
1103+
background: none;
1104+
border: none;
1105+
color: #666;
1106+
cursor: pointer;
1107+
font-size: 12px;
1108+
padding: 4px 8px;
1109+
border-radius: 4px;
1110+
}
1111+
1112+
.ai-chat-inner .control-button:hover {
1113+
background-color: #f1f1f1;
1114+
}
1115+
1116+
/* 聊天输入框 */
1117+
.ai-chat-inner .chat-input {
1118+
@apply bg-block;
1119+
display: flex;
1120+
align-items: center;
1121+
border-radius: 20px;
1122+
padding: 6px 12px;
1123+
}
1124+
1125+
.ai-chat-inner .chat-input input {
1126+
flex: 1;
1127+
border: none;
1128+
background: transparent;
1129+
outline: none;
1130+
padding: 8px 0;
1131+
font-size: 14px;
1132+
}
1133+
1134+
.ai-chat-inner .chat-input button {
1135+
@apply flex items-center justify-center;
1136+
color: white;
1137+
border: none;
1138+
border-radius: 20px;
1139+
padding: 6px 6px;
1140+
cursor: pointer;
1141+
font-size: 14px;
1142+
margin-left: 8px;
1143+
}
1144+
1145+
.ai-chat-inner .chat-input button:disabled {
1146+
background-color: #ccc;
1147+
cursor: not-allowed;
1148+
}
1149+
</style>
1150+
10071151
<style>
10081152
/* 引入Prism的默认主题样式 */
10091153
@import 'prismjs/themes/prism-tomorrow.css';
10101154
@import 'prismjs/plugins/line-numbers/prism-line-numbers.css';
1155+
1156+
.chat-messages .vuepress-markdown-body p {
1157+
@apply my-1;
1158+
}
10111159
</style>
10121160

10131161
<style scoped>
@@ -1018,8 +1166,8 @@ onMounted(() => {
10181166
}
10191167
10201168
.chat-container {
1021-
@apply rounded-2xl overflow-hidden border border-primary flex flex-col h-[600px];
1022-
@apply bg-white dark:bg-reco-bg-darkmode-code;
1169+
@apply overflow-hidden border border-primary flex flex-col h-[600px];
1170+
@apply bg-basic;
10231171
}
10241172
10251173
.chat-header {
@@ -1116,8 +1264,7 @@ onMounted(() => {
11161264
11171265
/* Chat Control Area */
11181266
.chat-input-container {
1119-
@apply border-t border-reco-border-lightmode dark:border-reco-border-darkmode;
1120-
@apply bg-white dark:bg-reco-bg-darkmode-code;
1267+
@apply bg-basic;
11211268
}
11221269
11231270
.chat-control-buttons {
@@ -1140,7 +1287,7 @@ onMounted(() => {
11401287
}
11411288
11421289
.chat-input input {
1143-
@apply flex-1 px-4 py-3 text-base outline-none transition-colors rounded-full mr-2;
1290+
@apply flex-1 px-4 h-10 text-base outline-none transition-colors rounded-full mr-2;
11441291
@apply border border-reco-border-lightmode dark:border-reco-border-darkmode;
11451292
@apply bg-white dark:bg-reco-bg-darkmode;
11461293
@apply text-reco-text-lightmode dark:text-reco-text-darkmode;
@@ -1151,7 +1298,7 @@ onMounted(() => {
11511298
}
11521299
11531300
.chat-input button {
1154-
@apply py-1 px-5 text-sm cursor-pointer transition-colors;
1301+
@apply h-9 px-4 text-sm cursor-pointer transition-colors;
11551302
@apply border-block rounded-lg bg-reco-primary/90 font-semibold text-white;
11561303
@apply dark:text-reco-text-darkmode;
11571304
@apply hover:bg-reco-primary;

0 commit comments

Comments
 (0)