@supermsy/smart-chat-widget 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -0
- package/dist/index.css +1 -0
- package/dist/index.html +12 -0
- package/dist/smart-chat-widget.cjs.js +3 -0
- package/dist/smart-chat-widget.es.js +505 -0
- package/dist/smart-chat-widget.umd.js +4 -0
- package/package.json +50 -0
- package/src/App.vue +72 -0
- package/src/api/chat.js +179 -0
- package/src/assets/data/car-loading4-data.json +1 -0
- package/src/assets/imgs/jiqirentouxiang.png +0 -0
- package/src/assets/imgs/new_logo2.png +0 -0
- package/src/assets/imgs/touxiang6.png +0 -0
- package/src/components/ChatHeader.vue +118 -0
- package/src/components/ChatInput.vue +198 -0
- package/src/components/ChatMessageList.vue +334 -0
- package/src/components/ChatToggleButton.vue +179 -0
- package/src/components/ChatWindow.vue +237 -0
- package/src/components/FAQCard.vue +82 -0
- package/src/components/SmartChatWidget.vue +220 -0
- package/src/index.js +12 -0
- package/src/main.js +5 -0
- package/src/styles/index.scss +8 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="chat-message-list"
|
|
4
|
+
ref="scrollContainer">
|
|
5
|
+
<div
|
|
6
|
+
v-for="(msg, index) in messages"
|
|
7
|
+
:key="index"
|
|
8
|
+
:class="['message', msg.type]">
|
|
9
|
+
<div class="avatar">
|
|
10
|
+
<img
|
|
11
|
+
v-if="msg.type === 'user'"
|
|
12
|
+
:src="userInfo.avatar || userAvatar" />
|
|
13
|
+
<img
|
|
14
|
+
v-else
|
|
15
|
+
:src="botAvatar" />
|
|
16
|
+
</div>
|
|
17
|
+
<div class="content">
|
|
18
|
+
<div
|
|
19
|
+
class="message-text"
|
|
20
|
+
v-html="formatMessage(msg.content)"></div>
|
|
21
|
+
<div
|
|
22
|
+
v-if="!msg.isFinished"
|
|
23
|
+
class="typing-indicator">
|
|
24
|
+
<span></span>
|
|
25
|
+
<span></span>
|
|
26
|
+
<span></span>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script setup>
|
|
34
|
+
import { ref, watch, nextTick } from 'vue';
|
|
35
|
+
import userAvatar from '@/assets/imgs/touxiang6.png';
|
|
36
|
+
import botAvatar from '@/assets/imgs/jiqirentouxiang.png';
|
|
37
|
+
|
|
38
|
+
const formatMessage = (content) => {
|
|
39
|
+
if (!content) return '';
|
|
40
|
+
return content
|
|
41
|
+
.replace(/&/g, '&')
|
|
42
|
+
.replace(/</g, '<')
|
|
43
|
+
.replace(/>/g, '>')
|
|
44
|
+
.replace(/"/g, '')
|
|
45
|
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
|
46
|
+
.replace(/\n/g, '<br/>');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const props = defineProps({
|
|
50
|
+
messages: {
|
|
51
|
+
type: Array,
|
|
52
|
+
default: () => []
|
|
53
|
+
},
|
|
54
|
+
userInfo: {
|
|
55
|
+
type: Object,
|
|
56
|
+
default: () => ({ id: '', name: '', avatar: '' })
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const scrollContainer = ref(null);
|
|
61
|
+
|
|
62
|
+
const scrollToBottom = () => {
|
|
63
|
+
nextTick(() => {
|
|
64
|
+
if (scrollContainer.value) {
|
|
65
|
+
scrollContainer.value.scrollTop = scrollContainer.value.scrollHeight;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
watch(() => props.messages.length, scrollToBottom);
|
|
71
|
+
watch(
|
|
72
|
+
() => props.messages,
|
|
73
|
+
(newMessages) => {
|
|
74
|
+
if (newMessages.length > 0) {
|
|
75
|
+
const lastMessage = newMessages[newMessages.length - 1];
|
|
76
|
+
if (lastMessage && !lastMessage.isFinished) {
|
|
77
|
+
scrollToBottom();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{ deep: true }
|
|
82
|
+
);
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<style scoped>
|
|
86
|
+
.chat-message-list {
|
|
87
|
+
flex: 1;
|
|
88
|
+
overflow-y: auto;
|
|
89
|
+
padding: 16px;
|
|
90
|
+
background: #f9fafb;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.chat-message-list::-webkit-scrollbar {
|
|
94
|
+
width: 6px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.chat-message-list::-webkit-scrollbar-track {
|
|
98
|
+
background: transparent;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.chat-message-list::-webkit-scrollbar-thumb {
|
|
102
|
+
background: #d1d5db;
|
|
103
|
+
border-radius: 3px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.chat-message-list::-webkit-scrollbar-thumb:hover {
|
|
107
|
+
background: #9ca3af;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.message {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
margin-bottom: 16px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.message.user {
|
|
117
|
+
justify-content: flex-end;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.message.user .content {
|
|
121
|
+
background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
|
|
122
|
+
color: white;
|
|
123
|
+
border-radius: 16px 16px 4px 16px;
|
|
124
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
125
|
+
order: 1;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.message.user .avatar {
|
|
129
|
+
margin-left: 8px;
|
|
130
|
+
order: 2;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.message.bot {
|
|
134
|
+
justify-content: flex-start;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.message.bot .content {
|
|
138
|
+
background: #f3f4f6;
|
|
139
|
+
color: #1f2937;
|
|
140
|
+
border-radius: 16px 16px 16px 4px;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.message.bot .avatar {
|
|
144
|
+
margin-right: 8px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.avatar {
|
|
148
|
+
width: 28px;
|
|
149
|
+
height: 28px;
|
|
150
|
+
border-radius: 6px;
|
|
151
|
+
background: #f3f4f6;
|
|
152
|
+
display: flex;
|
|
153
|
+
align-items: center;
|
|
154
|
+
justify-content: center;
|
|
155
|
+
flex-shrink: 0;
|
|
156
|
+
overflow: hidden;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.avatar img {
|
|
160
|
+
width: 100%;
|
|
161
|
+
height: 100%;
|
|
162
|
+
object-fit: cover;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.content {
|
|
166
|
+
max-width: 75%;
|
|
167
|
+
padding: 12px 16px;
|
|
168
|
+
font-size: 14px;
|
|
169
|
+
line-height: 1.6;
|
|
170
|
+
word-break: break-word;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.message-text {
|
|
174
|
+
white-space: pre-wrap;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.message-text strong {
|
|
178
|
+
color: #8b5cf6;
|
|
179
|
+
font-weight: 600;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.message-text ol {
|
|
183
|
+
padding-left: 20px;
|
|
184
|
+
margin: 8px 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.message-text li {
|
|
188
|
+
margin-bottom: 4px;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.message.user .message-text strong {
|
|
192
|
+
color: rgba(255, 255, 255, 0.9);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.thinking-header {
|
|
196
|
+
display: flex;
|
|
197
|
+
align-items: center;
|
|
198
|
+
justify-content: space-between;
|
|
199
|
+
margin-bottom: 12px;
|
|
200
|
+
padding-bottom: 8px;
|
|
201
|
+
border-bottom: 1px dashed #e5e7eb;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.thinking-title {
|
|
205
|
+
display: flex;
|
|
206
|
+
align-items: center;
|
|
207
|
+
gap: 6px;
|
|
208
|
+
font-size: 13px;
|
|
209
|
+
color: #6b7280;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.thinking-icon {
|
|
213
|
+
width: 16px;
|
|
214
|
+
height: 16px;
|
|
215
|
+
color: #10b981;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.check-icon {
|
|
219
|
+
width: 14px;
|
|
220
|
+
height: 14px;
|
|
221
|
+
color: #10b981;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.thinking-time {
|
|
225
|
+
background: #d1fae5;
|
|
226
|
+
color: #10b981;
|
|
227
|
+
padding: 2px 10px;
|
|
228
|
+
border-radius: 12px;
|
|
229
|
+
font-size: 12px;
|
|
230
|
+
font-weight: 500;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.collapse-btn {
|
|
234
|
+
width: 24px;
|
|
235
|
+
height: 24px;
|
|
236
|
+
border: none;
|
|
237
|
+
background: transparent;
|
|
238
|
+
color: #6b7280;
|
|
239
|
+
cursor: pointer;
|
|
240
|
+
border-radius: 4px;
|
|
241
|
+
transition: all 0.2s;
|
|
242
|
+
display: flex;
|
|
243
|
+
align-items: center;
|
|
244
|
+
justify-content: center;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.collapse-btn:hover {
|
|
248
|
+
background: rgba(0, 0, 0, 0.05);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.message-footer {
|
|
252
|
+
display: flex;
|
|
253
|
+
align-items: center;
|
|
254
|
+
justify-content: space-between;
|
|
255
|
+
margin-top: 12px;
|
|
256
|
+
padding-top: 8px;
|
|
257
|
+
border-top: 1px solid #e5e7eb;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.footer-info {
|
|
261
|
+
display: flex;
|
|
262
|
+
align-items: center;
|
|
263
|
+
gap: 12px;
|
|
264
|
+
font-size: 11px;
|
|
265
|
+
color: #9ca3af;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.info-item {
|
|
269
|
+
display: flex;
|
|
270
|
+
align-items: center;
|
|
271
|
+
gap: 4px;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.footer-actions {
|
|
275
|
+
display: flex;
|
|
276
|
+
gap: 8px;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.footer-actions button {
|
|
280
|
+
display: flex;
|
|
281
|
+
align-items: center;
|
|
282
|
+
gap: 3px;
|
|
283
|
+
padding: 4px 8px;
|
|
284
|
+
border: none;
|
|
285
|
+
background: transparent;
|
|
286
|
+
color: #6b7280;
|
|
287
|
+
font-size: 11px;
|
|
288
|
+
cursor: pointer;
|
|
289
|
+
border-radius: 4px;
|
|
290
|
+
transition: all 0.2s;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.footer-actions button:hover {
|
|
294
|
+
background: rgba(0, 0, 0, 0.05);
|
|
295
|
+
color: #1f2937;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.typing-indicator {
|
|
299
|
+
display: flex;
|
|
300
|
+
gap: 4px;
|
|
301
|
+
padding: 8px 0;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.typing-indicator span {
|
|
305
|
+
width: 6px;
|
|
306
|
+
height: 6px;
|
|
307
|
+
border-radius: 50%;
|
|
308
|
+
background: #6b7280;
|
|
309
|
+
animation: typing 1.4s infinite ease-in-out;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.typing-indicator span:nth-child(1) {
|
|
313
|
+
animation-delay: 0s;
|
|
314
|
+
}
|
|
315
|
+
.typing-indicator span:nth-child(2) {
|
|
316
|
+
animation-delay: 0.2s;
|
|
317
|
+
}
|
|
318
|
+
.typing-indicator span:nth-child(3) {
|
|
319
|
+
animation-delay: 0.4s;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
@keyframes typing {
|
|
323
|
+
0%,
|
|
324
|
+
80%,
|
|
325
|
+
100% {
|
|
326
|
+
transform: scale(0.6);
|
|
327
|
+
opacity: 0.5;
|
|
328
|
+
}
|
|
329
|
+
40% {
|
|
330
|
+
transform: scale(1);
|
|
331
|
+
opacity: 1;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
</style>
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="chat-toggle-btn"
|
|
4
|
+
@click="handleClick"
|
|
5
|
+
@mouseenter="showTooltip = true"
|
|
6
|
+
@mouseleave="showTooltip = false">
|
|
7
|
+
<div class="avatar-wrapper">
|
|
8
|
+
<div class="avatar">
|
|
9
|
+
<div class="face">
|
|
10
|
+
<div class="eye left-eye"></div>
|
|
11
|
+
<div class="eye right-eye"></div>
|
|
12
|
+
</div>
|
|
13
|
+
<div class="glow"></div>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
<div
|
|
17
|
+
v-if="showTooltip"
|
|
18
|
+
class="tooltip">
|
|
19
|
+
<div style="font-weight: 600; color: #1f2937">需要帮助么</div>
|
|
20
|
+
<div style="font-size: 12px; color: #9ca3af; margin-top: 2px">点击我,与我对话</div>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script setup>
|
|
26
|
+
import { ref } from 'vue';
|
|
27
|
+
|
|
28
|
+
const emit = defineEmits(['click']);
|
|
29
|
+
|
|
30
|
+
const showTooltip = ref(false);
|
|
31
|
+
|
|
32
|
+
const handleClick = () => {
|
|
33
|
+
showTooltip.value = false;
|
|
34
|
+
emit('click');
|
|
35
|
+
};
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<style scoped>
|
|
39
|
+
.chat-toggle-btn {
|
|
40
|
+
width: 56px;
|
|
41
|
+
height: 56px;
|
|
42
|
+
border-radius: 50%;
|
|
43
|
+
background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
|
|
44
|
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
justify-content: center;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
transition: all 0.3s ease;
|
|
50
|
+
position: relative;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.chat-toggle-btn:hover {
|
|
54
|
+
transform: translateY(-2px);
|
|
55
|
+
box-shadow: 0 10px 15px rgba(0, 0, 0, 0.12);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.avatar-wrapper {
|
|
59
|
+
width: 36px;
|
|
60
|
+
height: 36px;
|
|
61
|
+
position: relative;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.avatar {
|
|
65
|
+
width: 100%;
|
|
66
|
+
height: 100%;
|
|
67
|
+
border-radius: 50%;
|
|
68
|
+
background: linear-gradient(180deg, #ffffff 0%, #f3f4f6 100%);
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: center;
|
|
72
|
+
position: relative;
|
|
73
|
+
overflow: hidden;
|
|
74
|
+
animation: float 3s ease-in-out infinite;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@keyframes float {
|
|
78
|
+
0%,
|
|
79
|
+
100% {
|
|
80
|
+
transform: translateY(0);
|
|
81
|
+
}
|
|
82
|
+
50% {
|
|
83
|
+
transform: translateY(-2px);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.face {
|
|
88
|
+
position: relative;
|
|
89
|
+
width: 20px;
|
|
90
|
+
height: 16px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.eye {
|
|
94
|
+
position: absolute;
|
|
95
|
+
width: 6px;
|
|
96
|
+
height: 6px;
|
|
97
|
+
background: #1f2937;
|
|
98
|
+
border-radius: 50%;
|
|
99
|
+
animation: blink 4s ease-in-out infinite;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.left-eye {
|
|
103
|
+
left: 0;
|
|
104
|
+
top: 2px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.right-eye {
|
|
108
|
+
right: 0;
|
|
109
|
+
top: 2px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@keyframes blink {
|
|
113
|
+
0%,
|
|
114
|
+
45%,
|
|
115
|
+
55%,
|
|
116
|
+
100% {
|
|
117
|
+
transform: scaleY(1);
|
|
118
|
+
}
|
|
119
|
+
50% {
|
|
120
|
+
transform: scaleY(0.1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.glow {
|
|
125
|
+
position: absolute;
|
|
126
|
+
top: -8px;
|
|
127
|
+
left: 50%;
|
|
128
|
+
transform: translateX(-50%);
|
|
129
|
+
width: 30px;
|
|
130
|
+
height: 15px;
|
|
131
|
+
background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.6) 0%, transparent 70%);
|
|
132
|
+
border-radius: 50%;
|
|
133
|
+
animation: pulse 2s ease-in-out infinite;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@keyframes pulse {
|
|
137
|
+
0%,
|
|
138
|
+
100% {
|
|
139
|
+
opacity: 0.6;
|
|
140
|
+
transform: translateX(-50%) scale(1);
|
|
141
|
+
}
|
|
142
|
+
50% {
|
|
143
|
+
opacity: 1;
|
|
144
|
+
transform: translateX(-50%) scale(1.2);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.tooltip {
|
|
149
|
+
position: absolute;
|
|
150
|
+
bottom: calc(100% + 12px);
|
|
151
|
+
right: 0;
|
|
152
|
+
background: white;
|
|
153
|
+
padding: 12px 16px;
|
|
154
|
+
border-radius: 8px;
|
|
155
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
156
|
+
white-space: nowrap;
|
|
157
|
+
animation: fadeIn 0.2s ease;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@keyframes fadeIn {
|
|
161
|
+
from {
|
|
162
|
+
opacity: 0;
|
|
163
|
+
transform: translateY(5px);
|
|
164
|
+
}
|
|
165
|
+
to {
|
|
166
|
+
opacity: 1;
|
|
167
|
+
transform: translateY(0);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.tooltip::after {
|
|
172
|
+
content: '';
|
|
173
|
+
position: absolute;
|
|
174
|
+
top: 100%;
|
|
175
|
+
right: 16px;
|
|
176
|
+
border: 6px solid transparent;
|
|
177
|
+
border-top-color: white;
|
|
178
|
+
}
|
|
179
|
+
</style>
|