yt-chat-components 1.1.2 → 1.1.3
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/.idea/modules.xml +1 -1
- package/.idea/sonarlint/issuestore/3/6/364385cedcce4c06de1901392ffeeac0caef0f3c +0 -0
- package/.idea/sonarlint/issuestore/3/9/39129446b425a1d640160c068e4194e96639eedf +0 -0
- package/.idea/sonarlint/issuestore/4/a/4a2f33951ce07c1ff7184f91877aa13db05d3785 +0 -0
- package/.idea/sonarlint/issuestore/4/a/4a7b99bdbee5792679d347b6474463bf5e14b66d +0 -0
- package/.idea/sonarlint/issuestore/4/b/4b015aa5428c4d4c3d672893ec23f5fe3969f9be +0 -0
- package/.idea/sonarlint/issuestore/4/b/4b6989b8ccae808ebc45d02230d336ea53800365 +0 -0
- package/.idea/sonarlint/issuestore/6/1/61ebb9fd6e8cf9082658121d5d81e297791dacd0 +0 -0
- package/.idea/sonarlint/issuestore/6/c/6c024c1d0ad64656b9d4b0695ec3c49c0454addf +0 -0
- package/.idea/sonarlint/issuestore/6/e/6e75fc1c07c3a427a86fc213ca9479caaaff00ea +0 -0
- package/.idea/sonarlint/issuestore/8/d/8d6123af13a140f93e06299fff7ea23c547e9ec8 +0 -0
- package/.idea/sonarlint/issuestore/c/c/cc2352788140b6778ac06df4b33f50b390d2d8be +0 -0
- package/.idea/sonarlint/issuestore/d/5/d5595158cc48f9bf3e51b06f6e6805a8fd2d6262 +0 -0
- package/.idea/sonarlint/issuestore/d/7/d747cbed4201192dfa83a1a51345b020a050b647 +0 -0
- package/.idea/sonarlint/issuestore/d/9/d938938695d447dadda115e28781c6541f53fc4f +0 -0
- package/.idea/sonarlint/issuestore/index.pb +31 -3
- package/build/static/js/bundle.min.js +2 -0
- package/build/static/js/bundle.min.js.LICENSE.txt +132 -0
- package/package.json +79 -78
- package/public/index.html +108 -108
- package/src/YtChatView/chatWidget/chatWindow/chatMessage/index.tsx +498 -464
- package/src/YtChatView/chatWidget/chatWindow/controllers/index.ts +249 -249
- package/src/YtChatView/chatWidget/chatWindow/index.module.css +196 -196
- package/src/YtChatView/chatWidget/chatWindow/index.tsx +1099 -1086
- package/src/YtChatView/chatWidget/chatWindow/types/chatWidget/index.ts +50 -50
- package/src/YtChatView/chatWidget/index.tsx +2593 -2591
- package/src/YtChatView/logoBtn/index.css +3 -3
- package/src/YtChatView/logoBtn/index.jsx +103 -103
- package/src/YtChatView/logoSplitBtn/index.css +3 -3
- package/src/YtChatView/logoSplitBtn/index.jsx +105 -105
- package/src/YtChatView/mobileChat/index.jsx +945 -945
- package/src/YtChatView/mobileChat/index.module.css +253 -253
- package/src/YtChatView/previewDialog/index.jsx +600 -600
- package/src/YtChatView/previewDialog/index.module.css +253 -253
- package/src/chatWidget/chatWindow/index.tsx +426 -426
- package/src/chatWidget/index.tsx +2193 -2193
- package/src/index.tsx +10 -10
- package/webpack.config.js +50 -50
- package/dist/build/static/js/bundle.min.js +0 -1
- /package/.idea/{langflow-embedded-chat-clone.iml → langflow-embedded-chat.iml} +0 -0
- /package/.idea/sonarlint/issuestore/{7/0/7030d0b2f71b999ff89a343de08c414af32fc93a → 0/f/0f8c0c92cf798431ebb931ff6e997b1af86ecee5} +0 -0
- /package/.idea/sonarlint/issuestore/{9/c/9cfff9a6d27bd6c255aa751213163c7901fb8ce7 → 2/7/27e69cb561aeea20c1afbdd32d260dd60b89a81b} +0 -0
|
@@ -1,464 +1,498 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import Markdown from 'react-markdown';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const [
|
|
69
|
-
const [
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
case '
|
|
83
|
-
case '
|
|
84
|
-
case '
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
case '
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
case '
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
utterance.
|
|
121
|
-
utterance.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
<
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Markdown from 'react-markdown';
|
|
3
|
+
import EChartsReact from 'echarts-for-react';
|
|
4
|
+
import {ChatMessageType, InputValueType, MessageType} from '../types/chatWidget';
|
|
5
|
+
import remarkGfm from 'remark-gfm';
|
|
6
|
+
import rehypeMathjax from 'rehype-mathjax';
|
|
7
|
+
// import './index.module.css';
|
|
8
|
+
import upFilePng from '../../../../assets/aicenter/upfile.png';
|
|
9
|
+
import {Form, Image, Input, message as messageTip, Select, DatePicker, Button, Spin, Skeleton} from 'antd';
|
|
10
|
+
import React, {useState, useRef} from 'react';
|
|
11
|
+
import typePdfPng from '../../../../assets/aicenter/type-pdf.png';
|
|
12
|
+
import typeWordPng from '../../../../assets/aicenter/type-word.png';
|
|
13
|
+
import typeExcelPng from '../../../../assets/aicenter/type-excel.png';
|
|
14
|
+
import typeMarkdownPng from '../../../../assets/aicenter/type-markdown.png';
|
|
15
|
+
import typeTextPng from '../../../../assets/aicenter/type-text.png';
|
|
16
|
+
import typeMobiPng from '../../../../assets/aicenter/type-mobi.png';
|
|
17
|
+
import typeRPubPng from '../../../../assets/aicenter/type-rpub.png';
|
|
18
|
+
import playPng from '../../../../assets/aicenter/play.png';
|
|
19
|
+
import playRunGif from '../../../../assets/aicenter/play-run.gif';
|
|
20
|
+
import copyPng from '../../../../assets/aicenter/copy.png';
|
|
21
|
+
|
|
22
|
+
let speechSynth = window.speechSynthesis;
|
|
23
|
+
let utterance = null;
|
|
24
|
+
|
|
25
|
+
export default function ChatMessage({
|
|
26
|
+
type = MessageType.text,
|
|
27
|
+
rawInfo,
|
|
28
|
+
message,
|
|
29
|
+
isSend,
|
|
30
|
+
error,
|
|
31
|
+
host_url,
|
|
32
|
+
user_message_style,
|
|
33
|
+
bot_message_style,
|
|
34
|
+
error_message_style,
|
|
35
|
+
handleSendMessage
|
|
36
|
+
}: ChatMessageType) {
|
|
37
|
+
const parseFileName = (
|
|
38
|
+
text: string,
|
|
39
|
+
): { fileName: string | null; fileType: string | null; isImg: boolean } => {
|
|
40
|
+
// 检查输入是否有效
|
|
41
|
+
if (!text || typeof text !== 'string') {
|
|
42
|
+
return { fileName: null, fileType: null };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 找到最后一个反斜杠的位置
|
|
46
|
+
const lastBackslashIndex = text.lastIndexOf('\\');
|
|
47
|
+
if (lastBackslashIndex === -1) {
|
|
48
|
+
return { fileName: null, fileType: null }; // 如果没有找到反斜杠,返回空结果
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 截取反斜杠后面的部分
|
|
52
|
+
const fileNameWithExtension = text.substring(lastBackslashIndex + 1);
|
|
53
|
+
|
|
54
|
+
// 分割文件名和文件类型
|
|
55
|
+
const parts = fileNameWithExtension.split('.');
|
|
56
|
+
const fileName = parts.slice(0, -1).join('.'); // 文件名(不含扩展名)
|
|
57
|
+
const fileType = parts.length > 1 ? parts.pop() : null; // 文件类型
|
|
58
|
+
|
|
59
|
+
const isImg = fileType && ['jpg', 'jpeg', 'png', 'gif'].includes(fileType.toLowerCase());
|
|
60
|
+
// 返回结果对象
|
|
61
|
+
return {
|
|
62
|
+
fileName: fileName,
|
|
63
|
+
fileType: fileType,
|
|
64
|
+
isImg,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const [isPlay, setIsPlay] = useState(false) // 是否正在播放文字
|
|
69
|
+
const [isSubmittingForm, setIsSubmittingForm] = useState(false) // 正在提交form
|
|
70
|
+
const [isShowFormBtns, setIsShowFormBtns] = useState(true) // 正在提交form
|
|
71
|
+
const formRef = useRef(null);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 根据文件URL获取文件类型
|
|
75
|
+
* @param url
|
|
76
|
+
*/
|
|
77
|
+
const getFileTypeByUrl = (url) => {
|
|
78
|
+
if (!url) {
|
|
79
|
+
return 'file';
|
|
80
|
+
}
|
|
81
|
+
switch (url.split('.').pop().toLowerCase()) {
|
|
82
|
+
case 'jpg':
|
|
83
|
+
case 'jpeg':
|
|
84
|
+
case 'png':
|
|
85
|
+
case 'gif':
|
|
86
|
+
return 'image';
|
|
87
|
+
case 'pdf':
|
|
88
|
+
return 'pdf';
|
|
89
|
+
case 'doc':
|
|
90
|
+
case 'docx':
|
|
91
|
+
return 'word';
|
|
92
|
+
case 'xls':
|
|
93
|
+
case 'xlsx':
|
|
94
|
+
return 'excel';
|
|
95
|
+
case 'md':
|
|
96
|
+
return 'markdown';
|
|
97
|
+
case 'txt':
|
|
98
|
+
return 'txt';
|
|
99
|
+
case 'mobi':
|
|
100
|
+
return 'mobi';
|
|
101
|
+
case 'rpub':
|
|
102
|
+
return 'rpub';
|
|
103
|
+
default:
|
|
104
|
+
return 'file';
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 播放文字
|
|
110
|
+
* @param text 文字
|
|
111
|
+
*/
|
|
112
|
+
const playVoice = (text)=>{
|
|
113
|
+
if (isPlay) {
|
|
114
|
+
speechSynth.cancel();
|
|
115
|
+
setIsPlay(false)
|
|
116
|
+
}else{
|
|
117
|
+
if (text) {
|
|
118
|
+
utterance = new SpeechSynthesisUtterance(text);
|
|
119
|
+
const voices = speechSynth.getVoices();
|
|
120
|
+
utterance.voice = voices[61];
|
|
121
|
+
utterance.rate = 1;
|
|
122
|
+
utterance.pitch = 1;
|
|
123
|
+
speechSynth.speak(utterance);
|
|
124
|
+
setIsPlay(true)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 复制文字
|
|
131
|
+
* @param text 文字
|
|
132
|
+
*/
|
|
133
|
+
const copyText = async (text) => {
|
|
134
|
+
if(text){
|
|
135
|
+
await navigator.clipboard.writeText(text);
|
|
136
|
+
messageTip.info('复制成功')
|
|
137
|
+
}else{
|
|
138
|
+
messageTip.error("消息框没有文字")
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const renderUserMessage = () => {
|
|
143
|
+
return (
|
|
144
|
+
<div style={user_message_style} className="msg_userMessageBox">
|
|
145
|
+
<div style={user_message_style} className="cl-user_message">
|
|
146
|
+
{message.message}
|
|
147
|
+
</div>
|
|
148
|
+
<div className="msg_messageImgBox">
|
|
149
|
+
{message.rawInfo?.files.map((item, index) => {
|
|
150
|
+
return (
|
|
151
|
+
<div key={item} className="msg_fileBox">
|
|
152
|
+
{parseFileName(item).isImg && (
|
|
153
|
+
<Image
|
|
154
|
+
height={40}
|
|
155
|
+
width={40}
|
|
156
|
+
className="msg_messageImg"
|
|
157
|
+
src={`${host_url}/api/v1/files/images/${item}`}
|
|
158
|
+
alt={item}
|
|
159
|
+
preview={{
|
|
160
|
+
mask: <span className="custom-mask"></span>,
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
)}
|
|
164
|
+
{getFileTypeByUrl(item) == 'pdf' && (
|
|
165
|
+
<img style={{ width: 40, height: 40 }} src={typePdfPng} />
|
|
166
|
+
)}
|
|
167
|
+
{getFileTypeByUrl(item) == 'excel' && (
|
|
168
|
+
<img style={{ width: 40, height: 40 }} src={typeExcelPng} />
|
|
169
|
+
)}
|
|
170
|
+
{getFileTypeByUrl(item) == 'markdown' && (
|
|
171
|
+
<img style={{ width: 40, height: 40 }} src={typeMarkdownPng} />
|
|
172
|
+
)}
|
|
173
|
+
{getFileTypeByUrl(item) == 'txt' && (
|
|
174
|
+
<img style={{ width: 40, height: 40 }} src={typeTextPng} />
|
|
175
|
+
)}
|
|
176
|
+
{getFileTypeByUrl(item) == 'word' && (
|
|
177
|
+
<img style={{ width: 40, height: 40 }} src={typeWordPng} />
|
|
178
|
+
)}
|
|
179
|
+
{getFileTypeByUrl(item) == 'mobi' && (
|
|
180
|
+
<img style={{ width: 40, height: 40 }} src={typeMobiPng} />
|
|
181
|
+
)}
|
|
182
|
+
{getFileTypeByUrl(item) == 'rpub' && (
|
|
183
|
+
<img style={{ width: 40, height: 40 }} src={typeRPubPng} />
|
|
184
|
+
)}
|
|
185
|
+
{getFileTypeByUrl(item) == 'file' && (
|
|
186
|
+
<img style={{ width: 40, height: 40 }} src={upFilePng} />
|
|
187
|
+
)}
|
|
188
|
+
<div className="msg_fileInfoBox">
|
|
189
|
+
<div className="msg_fileInfoFileName">{parseFileName(item).fileName}</div>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
})}
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const renderErrorMessage = () => {
|
|
200
|
+
return (
|
|
201
|
+
<div style={error_message_style} className={'cl-error_message'}>
|
|
202
|
+
{message.message}
|
|
203
|
+
</div>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
const renderLoading = (type:MessageType, height:number) => {
|
|
207
|
+
const skeletonContainerId = `skeleton-container-${Math.random().toString(36).substring(2, 9)}`;
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div
|
|
211
|
+
id={skeletonContainerId}
|
|
212
|
+
style={{minWidth: 500, width: '100%', height, display: 'flex', justifyContent: 'center', alignItems: 'center'}}
|
|
213
|
+
>
|
|
214
|
+
{
|
|
215
|
+
// 其他类型暂不处理
|
|
216
|
+
type == MessageType.echart && (
|
|
217
|
+
<Skeleton.Image active={true} style={{width: '100%', height: '100%'}}/>
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
<style jsx>{`
|
|
221
|
+
#${skeletonContainerId} .ant-skeleton.ant-skeleton-element {
|
|
222
|
+
width: 100% !important;
|
|
223
|
+
height: 100% !important;
|
|
224
|
+
}
|
|
225
|
+
`}</style>
|
|
226
|
+
</div>
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 自定义渲染器
|
|
231
|
+
const EchartRender = React.useMemo(() => ({
|
|
232
|
+
code({ node, inline, className, children, ...props }) {
|
|
233
|
+
// 检查是否是代码块,并且语言为 'echart'
|
|
234
|
+
if (className && className.includes('language-echart')) {
|
|
235
|
+
try {
|
|
236
|
+
// 解析代码块内容为 JSON 配置
|
|
237
|
+
const chartOptions = JSON.parse(children.toString().trim());
|
|
238
|
+
// 渲染 ECharts 组件
|
|
239
|
+
return <EChartsReact option={chartOptions} style={{minWidth: 500, width: '100%', height: 300, backgroundColor: '#fff' }} />;
|
|
240
|
+
} catch (error) {
|
|
241
|
+
return renderLoading(MessageType.echart, 300);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// 默认渲染其他代码块
|
|
245
|
+
return <code className={className} {...props}>{children}</code>;
|
|
246
|
+
},
|
|
247
|
+
}), []); // 空依赖数组,只创建一次
|
|
248
|
+
|
|
249
|
+
const renderBotTextMessage = () => {
|
|
250
|
+
return (
|
|
251
|
+
<div>
|
|
252
|
+
<div style={bot_message_style} className={'cl-bot_message'}>
|
|
253
|
+
<Markdown
|
|
254
|
+
className={'markdown-body prose flex flex-col word-break-break-word'}
|
|
255
|
+
remarkPlugins={[remarkGfm]}
|
|
256
|
+
rehypePlugins={[rehypeMathjax]}
|
|
257
|
+
components={EchartRender}
|
|
258
|
+
>
|
|
259
|
+
{message.message}
|
|
260
|
+
</Markdown>
|
|
261
|
+
</div>
|
|
262
|
+
<div className="msg_operateBox">
|
|
263
|
+
<img src={isPlay?playRunGif:playPng} onClick={()=>playVoice(message.message)} />
|
|
264
|
+
<img src={copyPng} onClick={()=>copyText(message.message)} />
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const renderBotFormMessage = () => {
|
|
271
|
+
const { form_config } = rawInfo;
|
|
272
|
+
|
|
273
|
+
// 处理表单提交
|
|
274
|
+
const handleSubmit = (values) => {
|
|
275
|
+
console.log('表单提交数据:', values);
|
|
276
|
+
if (handleSendMessage) {
|
|
277
|
+
setIsSubmittingForm(true);
|
|
278
|
+
// TODO 提交的数据需要多一些
|
|
279
|
+
handleSendMessage(JSON.stringify(values), () => {
|
|
280
|
+
messageTip.success('表单提交成功');
|
|
281
|
+
setIsSubmittingForm(false);
|
|
282
|
+
setIsShowFormBtns(false);
|
|
283
|
+
}, InputValueType.form);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// 处理表单取消
|
|
288
|
+
const handleCancel = () => {
|
|
289
|
+
if (formRef.current) {
|
|
290
|
+
formRef.current.resetFields();
|
|
291
|
+
}
|
|
292
|
+
if (handleSendMessage) {
|
|
293
|
+
setIsSubmittingForm(true);
|
|
294
|
+
handleSendMessage('USER CANCELED', () => {
|
|
295
|
+
messageTip.success('取消成功');
|
|
296
|
+
setIsSubmittingForm(false);
|
|
297
|
+
setIsShowFormBtns(false);
|
|
298
|
+
}, InputValueType.form);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<div className="form-container">
|
|
304
|
+
<div className="form-title">{form_config?.name || '表单'}</div>
|
|
305
|
+
<Form
|
|
306
|
+
ref={formRef}
|
|
307
|
+
layout="vertical"
|
|
308
|
+
onFinish={handleSubmit}
|
|
309
|
+
className="dynamic-form"
|
|
310
|
+
>
|
|
311
|
+
{form_config?.config?.map((item, index) => {
|
|
312
|
+
const { key, name, type, options } = item;
|
|
313
|
+
// 根据不同的表单项类型渲染不同的组件
|
|
314
|
+
switch (type) {
|
|
315
|
+
case 'text':
|
|
316
|
+
return (
|
|
317
|
+
<Form.Item
|
|
318
|
+
key={index}
|
|
319
|
+
label={name}
|
|
320
|
+
name={key}
|
|
321
|
+
rules={[{ required: true, message: `请输入${name}` }]}
|
|
322
|
+
>
|
|
323
|
+
<Input placeholder={`请输入${name}`} />
|
|
324
|
+
</Form.Item>
|
|
325
|
+
);
|
|
326
|
+
case 'date':
|
|
327
|
+
return (
|
|
328
|
+
<Form.Item
|
|
329
|
+
key={index}
|
|
330
|
+
label={name}
|
|
331
|
+
name={key}
|
|
332
|
+
rules={[{ required: true, message: `请选择${name}` }]}
|
|
333
|
+
>
|
|
334
|
+
<DatePicker style={{ width: '100%' }} placeholder={`请选择${name}`} />
|
|
335
|
+
</Form.Item>
|
|
336
|
+
);
|
|
337
|
+
case 'select':
|
|
338
|
+
return (
|
|
339
|
+
<Form.Item
|
|
340
|
+
key={index}
|
|
341
|
+
label={name}
|
|
342
|
+
name={key}
|
|
343
|
+
rules={[{ required: true, message: `请选择${name}` }]}
|
|
344
|
+
>
|
|
345
|
+
<Select
|
|
346
|
+
placeholder={`请选择${name}`}
|
|
347
|
+
style={{ width: '100%' }}
|
|
348
|
+
>
|
|
349
|
+
{options?.map((option, optIndex) => (
|
|
350
|
+
<Select.Option key={optIndex} value={option}>
|
|
351
|
+
{option}
|
|
352
|
+
</Select.Option>
|
|
353
|
+
))}
|
|
354
|
+
</Select>
|
|
355
|
+
</Form.Item>
|
|
356
|
+
);
|
|
357
|
+
default:
|
|
358
|
+
return (
|
|
359
|
+
<Form.Item
|
|
360
|
+
key={index}
|
|
361
|
+
label={name}
|
|
362
|
+
name={name}
|
|
363
|
+
>
|
|
364
|
+
<Input placeholder={`请输入${name}`} />
|
|
365
|
+
</Form.Item>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
})}
|
|
369
|
+
|
|
370
|
+
{
|
|
371
|
+
isShowFormBtns && (
|
|
372
|
+
<div className="form-buttons">
|
|
373
|
+
<Form.Item>
|
|
374
|
+
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: '12px' }}>
|
|
375
|
+
<Button
|
|
376
|
+
loading={isSubmittingForm}
|
|
377
|
+
onClick={handleCancel}
|
|
378
|
+
>
|
|
379
|
+
取消
|
|
380
|
+
</Button>
|
|
381
|
+
<Button
|
|
382
|
+
loading={isSubmittingForm}
|
|
383
|
+
type="primary"
|
|
384
|
+
htmlType="submit"
|
|
385
|
+
style={{ backgroundColor: '#8064f6' }}
|
|
386
|
+
>
|
|
387
|
+
提交
|
|
388
|
+
</Button>
|
|
389
|
+
</div>
|
|
390
|
+
</Form.Item>
|
|
391
|
+
</div>
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
</Form>
|
|
395
|
+
|
|
396
|
+
<style jsx>{`
|
|
397
|
+
.form-container {
|
|
398
|
+
width: 100%;
|
|
399
|
+
padding: 16px;
|
|
400
|
+
border-radius: 8px;
|
|
401
|
+
background-color:rgb(244, 244, 244);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.form-title {
|
|
405
|
+
font-size: 18px;
|
|
406
|
+
font-weight: bold;
|
|
407
|
+
margin-bottom: 16px;
|
|
408
|
+
color: #333;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.dynamic-form {
|
|
412
|
+
width: 100%;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.form-select {
|
|
416
|
+
width: 100%;
|
|
417
|
+
height: 32px;
|
|
418
|
+
border: 1px solid #d9d9d9;
|
|
419
|
+
border-radius: 4px;
|
|
420
|
+
padding: 4px 11px;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.form-buttons {
|
|
424
|
+
display: flex;
|
|
425
|
+
justify-content: flex-end;
|
|
426
|
+
margin-top: 20px;
|
|
427
|
+
gap: 12px;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.cancel-button {
|
|
431
|
+
padding: 6px 16px;
|
|
432
|
+
background-color: #f0f0f0;
|
|
433
|
+
border: 1px solid #d9d9d9;
|
|
434
|
+
border-radius: 4px;
|
|
435
|
+
cursor: pointer;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.submit-button {
|
|
439
|
+
padding: 6px 16px;
|
|
440
|
+
background-color: #8064f6;
|
|
441
|
+
color: white;
|
|
442
|
+
border: none;
|
|
443
|
+
border-radius: 4px;
|
|
444
|
+
cursor: pointer;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/* 移动端适配 */
|
|
448
|
+
@media (max-width: 768px) {
|
|
449
|
+
.form-container {
|
|
450
|
+
padding: 12px;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
.form-buttons {
|
|
454
|
+
flex-direction: column;
|
|
455
|
+
gap: 8px;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
.cancel-button,
|
|
459
|
+
.submit-button {
|
|
460
|
+
width: 100%;
|
|
461
|
+
padding: 8px 0;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
`}</style>
|
|
465
|
+
</div>
|
|
466
|
+
);
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const renderBotMessage = () => {
|
|
470
|
+
switch (type) {
|
|
471
|
+
case MessageType.form:
|
|
472
|
+
return renderBotFormMessage()
|
|
473
|
+
case MessageType.text:
|
|
474
|
+
default:
|
|
475
|
+
return renderBotTextMessage()
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const render = () => {
|
|
480
|
+
if (isSend){
|
|
481
|
+
return renderUserMessage()
|
|
482
|
+
}else {
|
|
483
|
+
if (error){
|
|
484
|
+
return renderErrorMessage()
|
|
485
|
+
}else{
|
|
486
|
+
return renderBotMessage()
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return (
|
|
492
|
+
<div className={'cl-chat-message ' + (isSend ? ' cl-justify-end' : ' cl-justify-start')}>
|
|
493
|
+
{
|
|
494
|
+
render()
|
|
495
|
+
}
|
|
496
|
+
</div>
|
|
497
|
+
);
|
|
498
|
+
}
|