1
1
<template >
2
- <section class =" ai-chat" >
2
+ <section class =" ai-chat-inner " >
3
3
<div class =" chat-container" >
4
- <div class =" chat-header" >
5
- <h2 >Vuepress Reco AI Chat (Beta)</h2 >
6
- </div >
7
4
<div class =" chat-messages" ref =" chatMessagesRef" >
8
5
<div v-for =" (message, index) in messages" :key =" index"
9
6
:class =" ['message', message.role === 'user' ? 'user-message' : 'assistant-message']" >
20
17
<!-- 移除多余的loading效果,只使用消息中的"正在思考..."文本作为loading指示 -->
21
18
</div >
22
19
<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 >
28
20
<div class =" chat-input" >
29
21
<input
30
22
type =" text"
34
26
:disabled =" loading || typing"
35
27
/>
36
28
<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 >
38
30
<span v-else-if =" typing" >回复中...</span >
39
31
<span v-else >处理中...</span >
40
32
</button >
41
33
</div >
42
34
</div >
43
35
</div >
44
-
45
-
46
36
</section >
47
37
</template >
48
38
@@ -999,15 +989,173 @@ const scrollToBottom = () => {
999
989
// 组件挂载时滚动到底部
1000
990
onMounted (() => {
1001
991
scrollToBottom ()
992
+ // 将原来的欢迎消息替换为更适合弹窗的消息
993
+ messages .value = [
994
+ {
995
+ role: ' assistant' ,
996
+ content: ' 你好!我是Vuepress Reco文档智能助手,有什么可以帮到你的?' ,
997
+ displayContent: ' 你好!我是Vuepress Reco文档智能助手,有什么可以帮到你的?'
998
+ }
999
+ ]
1002
1000
})
1003
1001
1004
1002
// 消息已经在渲染时高亮,不需要额外的监听处理
1005
1003
</script >
1006
1004
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
+
1007
1151
<style >
1008
1152
/* 引入Prism的默认主题样式 */
1009
1153
@import ' prismjs/themes/prism-tomorrow.css' ;
1010
1154
@import ' prismjs/plugins/line-numbers/prism-line-numbers.css' ;
1155
+
1156
+ .chat-messages .vuepress-markdown-body p {
1157
+ @apply my- 1;
1158
+ }
1011
1159
</style >
1012
1160
1013
1161
<style scoped>
@@ -1018,8 +1166,8 @@ onMounted(() => {
1018
1166
}
1019
1167
1020
1168
.chat-container {
1021
- @apply rounded- 2 xl 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 ;
1023
1171
}
1024
1172
1025
1173
.chat-header {
@@ -1116,8 +1264,7 @@ onMounted(() => {
1116
1264
1117
1265
/* Chat Control Area */
1118
1266
.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 ;
1121
1268
}
1122
1269
1123
1270
.chat-control-buttons {
@@ -1140,7 +1287,7 @@ onMounted(() => {
1140
1287
}
1141
1288
1142
1289
.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;
1144
1291
@apply border border-reco-border-lightmode dark :border-reco-border-darkmode;
1145
1292
@apply bg-white dark :bg-reco-bg-darkmode;
1146
1293
@apply text-reco-text-lightmode dark :text-reco-text-darkmode;
@@ -1151,7 +1298,7 @@ onMounted(() => {
1151
1298
}
1152
1299
1153
1300
.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 ;
1155
1302
@apply border-block rounded-lg bg-reco-primary /90 font-semibold text-white ;
1156
1303
@apply dark :text-reco-text-darkmode;
1157
1304
@apply hover :bg-reco-primary;
0 commit comments