bhd-components 0.5.6 → 0.5.8

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.
Files changed (115) hide show
  1. package/dist/5764783e.esm.es5.production.js +468 -0
  2. package/dist/f2b01b9c.esm.es5.development.js +167840 -0
  3. package/dist/index.esm.es5.development.css +8467 -0
  4. package/dist/index.esm.es5.development.js +5835 -0
  5. package/dist/index.esm.es5.production.css +1 -0
  6. package/dist/index.esm.es5.production.js +1 -0
  7. package/dist/vendor.esm.es5.development.esm.es5.development.css +117 -0
  8. package/dist/vendor.esm.es5.production.esm.es5.production.css +9 -0
  9. package/es2017/customerService/contactsList/index.d.ts +14 -0
  10. package/es2017/customerService/contactsList/index.js +316 -0
  11. package/es2017/customerService/contactsList/index.module.less +206 -0
  12. package/es2017/customerService/function.d.ts +17 -0
  13. package/es2017/customerService/function.js +72 -0
  14. package/es2017/customerService/historyFun/index.d.ts +14 -0
  15. package/es2017/customerService/historyFun/index.js +276 -0
  16. package/es2017/customerService/historyFun/index.module.less +223 -0
  17. package/es2017/customerService/images/knowledge_icon.png +0 -0
  18. package/es2017/customerService/images/voice_btn.gif +0 -0
  19. package/es2017/customerService/index.d.ts +16 -0
  20. package/es2017/customerService/index.js +2687 -0
  21. package/es2017/customerService/index.module.less +790 -0
  22. package/es2017/customerService/useMediaRecorder.d.ts +9 -0
  23. package/es2017/customerService/useMediaRecorder.js +78 -0
  24. package/es2017/customerService/voice_btn.gif +0 -0
  25. package/es2017/icons/components/custom-ai_icon.d.ts +4 -0
  26. package/es2017/icons/components/custom-ai_icon.js +58 -0
  27. package/es2017/icons/components/custom-contacts.d.ts +4 -0
  28. package/es2017/icons/components/custom-contacts.js +29 -0
  29. package/es2017/icons/components/custom-copy.d.ts +4 -0
  30. package/es2017/icons/components/custom-copy.js +36 -0
  31. package/es2017/icons/components/custom-dislike.d.ts +4 -0
  32. package/es2017/icons/components/custom-dislike.js +22 -0
  33. package/es2017/icons/components/custom-duihao.d.ts +4 -0
  34. package/es2017/icons/components/custom-duihao.js +22 -0
  35. package/es2017/icons/components/custom-exit_full_screen.d.ts +4 -0
  36. package/es2017/icons/components/custom-exit_full_screen.js +26 -0
  37. package/es2017/icons/components/custom-full_screen.d.ts +4 -0
  38. package/es2017/icons/components/custom-full_screen.js +22 -0
  39. package/es2017/icons/components/custom-like.d.ts +4 -0
  40. package/es2017/icons/components/custom-like.js +22 -0
  41. package/es2017/icons/components/custom-quote.d.ts +4 -0
  42. package/es2017/icons/components/custom-quote.js +31 -0
  43. package/es2017/icons/components/custom-record.d.ts +4 -0
  44. package/es2017/icons/components/custom-record.js +37 -0
  45. package/es2017/icons/components/custom-reloading.d.ts +4 -0
  46. package/es2017/icons/components/custom-reloading.js +26 -0
  47. package/es2017/icons/components/custom-retract.d.ts +4 -0
  48. package/es2017/icons/components/custom-retract.js +27 -0
  49. package/es2017/icons/components/custom-round_close.d.ts +4 -0
  50. package/es2017/icons/components/custom-round_close.js +24 -0
  51. package/es2017/icons/components/custom-sending.d.ts +4 -0
  52. package/es2017/icons/components/custom-sending.js +22 -0
  53. package/es2017/icons/components/custom-sound_recording.d.ts +4 -0
  54. package/es2017/icons/components/custom-sound_recording.js +22 -0
  55. package/es2017/icons/components/index.d.ts +15 -0
  56. package/es2017/icons/components/index.js +15 -0
  57. package/es2017/index.d.ts +1 -0
  58. package/es2017/index.js +1 -0
  59. package/esm/customerService/contactsList/index.d.ts +14 -0
  60. package/esm/customerService/contactsList/index.js +333 -0
  61. package/esm/customerService/contactsList/index.module.less +206 -0
  62. package/esm/customerService/function.d.ts +17 -0
  63. package/esm/customerService/function.js +74 -0
  64. package/esm/customerService/historyFun/index.d.ts +14 -0
  65. package/esm/customerService/historyFun/index.js +289 -0
  66. package/esm/customerService/historyFun/index.module.less +223 -0
  67. package/esm/customerService/images/knowledge_icon.png +0 -0
  68. package/esm/customerService/images/voice_btn.gif +0 -0
  69. package/esm/customerService/index.d.ts +16 -0
  70. package/esm/customerService/index.js +2793 -0
  71. package/esm/customerService/index.module.less +790 -0
  72. package/esm/customerService/useMediaRecorder.d.ts +9 -0
  73. package/esm/customerService/useMediaRecorder.js +121 -0
  74. package/esm/customerService/voice_btn.gif +0 -0
  75. package/esm/icons/components/custom-ai_icon.d.ts +4 -0
  76. package/esm/icons/components/custom-ai_icon.js +60 -0
  77. package/esm/icons/components/custom-contacts.d.ts +4 -0
  78. package/esm/icons/components/custom-contacts.js +31 -0
  79. package/esm/icons/components/custom-copy.d.ts +4 -0
  80. package/esm/icons/components/custom-copy.js +38 -0
  81. package/esm/icons/components/custom-dislike.d.ts +4 -0
  82. package/esm/icons/components/custom-dislike.js +24 -0
  83. package/esm/icons/components/custom-duihao.d.ts +4 -0
  84. package/esm/icons/components/custom-duihao.js +24 -0
  85. package/esm/icons/components/custom-exit_full_screen.d.ts +4 -0
  86. package/esm/icons/components/custom-exit_full_screen.js +28 -0
  87. package/esm/icons/components/custom-full_screen.d.ts +4 -0
  88. package/esm/icons/components/custom-full_screen.js +24 -0
  89. package/esm/icons/components/custom-like.d.ts +4 -0
  90. package/esm/icons/components/custom-like.js +24 -0
  91. package/esm/icons/components/custom-quote.d.ts +4 -0
  92. package/esm/icons/components/custom-quote.js +33 -0
  93. package/esm/icons/components/custom-record.d.ts +4 -0
  94. package/esm/icons/components/custom-record.js +39 -0
  95. package/esm/icons/components/custom-reloading.d.ts +4 -0
  96. package/esm/icons/components/custom-reloading.js +28 -0
  97. package/esm/icons/components/custom-retract.d.ts +4 -0
  98. package/esm/icons/components/custom-retract.js +29 -0
  99. package/esm/icons/components/custom-round_close.d.ts +4 -0
  100. package/esm/icons/components/custom-round_close.js +26 -0
  101. package/esm/icons/components/custom-sending.d.ts +4 -0
  102. package/esm/icons/components/custom-sending.js +24 -0
  103. package/esm/icons/components/custom-sound_recording.d.ts +4 -0
  104. package/esm/icons/components/custom-sound_recording.js +24 -0
  105. package/esm/icons/components/index.d.ts +15 -0
  106. package/esm/icons/components/index.js +15 -0
  107. package/esm/index.d.ts +1 -0
  108. package/esm/index.js +1 -0
  109. package/package.json +11 -2
  110. package/dist/1951bd5c.esm.es5.development.js +0 -45417
  111. package/dist/28cd83d3.esm.es5.production.js +0 -256
  112. package/dist/table.esm.es5.development.css +0 -772
  113. package/dist/table.esm.es5.development.js +0 -289
  114. package/dist/table.esm.es5.production.css +0 -1
  115. package/dist/table.esm.es5.production.js +0 -1
@@ -0,0 +1,2687 @@
1
+ /* eslint-disable import/first */ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@ice/jsx-runtime/jsx-runtime";
4
+ import React, { useEffect, useState, useRef } from "react";
5
+ import { Modal, Drawer, Input, Tooltip } from "antd";
6
+ import styles from "./index.module.less";
7
+ // const inOnline = process.env.NODE_TYPE === "online";
8
+ import { CustomAiIcon, CustomRecord, CustomFullScreen, CustomExitFullScreen, CustomReloading, CustomCopy, CustomLike, CustomDislike, CustomQuote, CustomSending, CustomContacts, CustomDuihao, CustomSoundRecording, CustomRoundClose } from "../icons/index";
9
+ import { CloseOutlined } from "@ant-design/icons";
10
+ import HistoryFun from "./historyFun/index";
11
+ import ContactsList from "./contactsList/index";
12
+ // import dayjs from 'dayjs';
13
+ import { Remarkable } from "remarkable";
14
+ import hljs from "highlight.js";
15
+ import "highlight.js/styles/default.css";
16
+ import { render } from "react-dom";
17
+ import Provider from "../provider";
18
+ const { TextArea } = Input;
19
+ import knowledge_icon from "./images/knowledge_icon.png";
20
+ import { useMediaRecorder } from "./useMediaRecorder"; //录音使用文件
21
+ import { readMessage, getByteLen, serverUrl, copyText, getDataTime } from "./function"; //一些方法
22
+ const CustomerService = (props)=>{
23
+ let { userData , http , urllocation , onCancel , serverName , fetchEventSource , initShowType , onEvent , stepIds , stepId } = props;
24
+ // urllocation = "/zhong";
25
+ const [mid, setmid] = useState(props.userData.mid); //当前用户id
26
+ const { bese64String , startRecord , stopRecord } = useMediaRecorder(); //语音转文字
27
+ const [voiceRecordingStatus, setVoiceRecordingStatus] = useState(3); //语音录制状态 3,语音识别完成 2,录制中, 1,录制结束
28
+ const [copyTextOBJ, setCopyTextObj] = useState([]); //复制的消息id
29
+ const [citationContent, setCitationContent] = useState({}); //引用内容
30
+ const [roomId, setRoomId] = useState(""); //聊天室id
31
+ const [historyMessageList, setHistoryMessageList] = useState([]); //历史消息
32
+ const [keyWord, setKeyWord] = useState(""); //搜索内容
33
+ const [questionsList, setQuestionsList] = useState([]); //问题列表
34
+ const [hotQuestionsList, setHotQuestionsList] = useState([]); //热门问题
35
+ const [greetingMessage, setGreetingMessage] = useState(false); //聊天记录列表是否请求完成
36
+ const [pageNum, setPageNum] = useState(1); //页码
37
+ const [pageNumHistory, setPageNumHistory] = useState(0); //用于搜索历史记录后的页码
38
+ const [pageCount, setPageCount] = useState(0); //总页数
39
+ const [loading, setLoading] = useState(false); //上拉显示加载图标
40
+ const [bottomLoading, setBottomLoading] = useState(false); //下拉显示加载图标
41
+ const [finished, setFinished] = useState(true); //是否结束生成
42
+ const [lastId, setLastId] = useState(""); //最后一条数据的id,可用于定位当前位置
43
+ const [chatWith, setChatWith] = useState({}); //聊天的老师id或ai
44
+ const [firstLoad, setFirstLoad] = useState(false); //第一次切换全屏时滚动到页面底部
45
+ const [buttomHei, setButtomHei] = useState(45); //底部输入框的高度
46
+ const [showHistory, setShowHistory] = useState(false); //是否显示历史记录
47
+ const [showContacts, setShowContacts] = useState(false); //是否显示关联老师
48
+ const [showType, setShowType] = useState(-1); //显示聊天框类型 1、侧边栏 2 modal 3 相应的div中 newlabo中使用
49
+ const [answerMode, setAnswerMode] = useState(-1); //设置回答模式。1,召唤老师回答
50
+ const [teacherList, setTeacherList] = useState([]); //老师列表
51
+ const [problem, setProblem] = useState({}); //召唤老师回答的问题
52
+ const [roomList, setRoomList] = useState([]); //聊天列表
53
+ const [chatObj, setChatObj] = useState([]); //聊天记录id保存,用来在实验报告中记录
54
+ const timer = useRef(null); //文本框输入时
55
+ let receiveMessageTimer = useRef(null); //接收ai发回的消息
56
+ let voiceCountdownTimer = useRef(null); //语音录制倒计时
57
+ let listTimer = useRef(null); // 请求列表倒计时
58
+ let roomMessage = useRef(null); //循环当前页面的新消息
59
+ const ctrl = useRef(); //停止生成ai回答时使用
60
+ let childRef = useRef(null); //获取子组件方法
61
+ const remarkable = new Remarkable({
62
+ highlight: function(str, lang) {
63
+ if (lang && hljs.getLanguage(lang)) {
64
+ try {
65
+ return hljs.highlight(lang, str).value;
66
+ } catch (err) {}
67
+ }
68
+ try {
69
+ return hljs.highlightAuto(str).value;
70
+ } catch (err) {}
71
+ return ""; // use external default escaping
72
+ }
73
+ });
74
+ useEffect(()=>{
75
+ return ()=>{
76
+ clearTimeout(receiveMessageTimer.current);
77
+ clearTimeout(voiceCountdownTimer.current);
78
+ clearTimeout(listTimer.current);
79
+ clearTimeout(timer.current);
80
+ clearTimeout(roomMessage.current);
81
+ };
82
+ }, []);
83
+ useEffect(()=>{
84
+ if (showType != 1 && !firstLoad && pageCount > 0) {
85
+ setFirstLoad(true);
86
+ setTimeout(()=>{
87
+ scrollToBottom();
88
+ }, 100);
89
+ }
90
+ function handleScroll() {
91
+ const container = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
92
+ const scrollTop = container.scrollTop;
93
+ // const scrollBottom = container.scroll;
94
+ // console.log(container,'sdcsdcsdcsdc');
95
+ container.onscroll = (e)=>{
96
+ //元素内部页面滚动到达底部
97
+ if (e.target.clientHeight + e.target.scrollTop >= e.target.scrollHeight) {
98
+ //console.log('元素内部页面滚动到达底部');
99
+ if (pageNumHistory > 1) {
100
+ console.log(pageNumHistory, 'pageNumpageNumpageNum');
101
+ let number = pageNumHistory - 1;
102
+ // setPageNum((pageNum) => {
103
+ // return pageNum - 1;
104
+ // });
105
+ setPageNumHistory(number);
106
+ clearTimeout(listTimer.current);
107
+ setBottomLoading(true);
108
+ listTimer.current = setTimeout(()=>{
109
+ console.log("加载下一页", number);
110
+ getHistoryMessage(number, 4);
111
+ }, 1000);
112
+ }
113
+ }
114
+ };
115
+ if (scrollTop == 0 && pageCount > pageNum && pageCount > 0) {
116
+ setLoading(true);
117
+ let number = pageNum + 1;
118
+ setPageNum((pageNum)=>{
119
+ return pageNum + 1;
120
+ });
121
+ clearTimeout(listTimer.current);
122
+ listTimer.current = setTimeout(()=>{
123
+ console.log("下拉加载下一页", number);
124
+ getHistoryMessage(number, 2);
125
+ }, 1000);
126
+ }
127
+ }
128
+ const content = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
129
+ if (content) {
130
+ content.addEventListener("scroll", handleScroll);
131
+ }
132
+ return ()=>{
133
+ const content = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
134
+ if (content) {
135
+ content.removeEventListener("scroll", handleScroll);
136
+ }
137
+ };
138
+ }, [
139
+ historyMessageList,
140
+ showType,
141
+ pageCount
142
+ ]);
143
+ useEffect(()=>{
144
+ resettingBottomHei();
145
+ let dom = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
146
+ if (dom) {
147
+ if (showType == 1) {
148
+ dom.style.maxHeight = `${window.innerHeight - 60 - buttomHei}px`;
149
+ } else if (showType == 3) {
150
+ dom.style.maxHeight = `${window.innerHeight - 114 - buttomHei}px`;
151
+ } else {
152
+ dom.style.maxHeight = `${window.innerHeight - 160 - 62 - buttomHei}px`;
153
+ }
154
+ }
155
+ }, [
156
+ buttomHei,
157
+ showType
158
+ ]);
159
+ useEffect(()=>{
160
+ // console.log(props,'lsdkcmsdlcksd')
161
+ getQuestiionsList("", 1);
162
+ scrollToBottom();
163
+ // less.modifyVars({ "@color-border-Tr": "#f4523b" });
164
+ setShowType(initShowType);
165
+ }, [
166
+ initShowType
167
+ ]);
168
+ useEffect(()=>{
169
+ // console.log(roomId,1111111)
170
+ if (roomId != '') {
171
+ if (lastId == '') {
172
+ getHistoryMessage(pageNum, 2);
173
+ } else {
174
+ //查看历史记录,需要定位到当前记录
175
+ getHistoryMessage(pageNum, 1);
176
+ }
177
+ }
178
+ }, [
179
+ roomId
180
+ ]);
181
+ useEffect(()=>{
182
+ if (roomList.length == 0) {
183
+ createRooms("AI").then((res)=>{
184
+ setRoomId(res.data.id);
185
+ setRoomList([
186
+ {
187
+ roomId: res.data.id,
188
+ unreadCount: 0,
189
+ uid: mid,
190
+ sender: 'AI'
191
+ }
192
+ ]);
193
+ });
194
+ } else {
195
+ setRoomList(roomList);
196
+ }
197
+ // recordRef.current.roomList=JSON.parse(JSON.stringify(roomList))
198
+ }, [
199
+ roomList
200
+ ]);
201
+ //进入页面,发送打招呼信息
202
+ useEffect(()=>{
203
+ // console.log(historyMessageList, "dkjvndfkjvd33333f");
204
+ //老师的聊天窗口不发送打招呼信息
205
+ if (!(roomList.length > 0 && roomList[0].roomId != roomId)) {
206
+ //是否发送打招呼信息
207
+ if (greetingMessage && historyMessageList.length == 0) {
208
+ sendGreetingMessage(1);
209
+ } else {
210
+ try {
211
+ if (historyMessageList[historyMessageList.length - 1].extraInfo == null) {
212
+ sendGreetingMessage(1);
213
+ } else if (JSON.parse(historyMessageList[historyMessageList.length - 1].extraInfo).length > 0 && (JSON.parse(historyMessageList[historyMessageList.length - 1].extraInfo)[0].key == "questionId" || JSON.parse(historyMessageList[historyMessageList.length - 1].extraInfo)[0].value == "knowledgebase")) {
214
+ // console.log(
215
+ // JSON.parse(
216
+ // historyMessageList[historyMessageList.length - 1].extraInfo,
217
+ // "sdklsdksd"
218
+ // )
219
+ // );
220
+ sendGreetingMessage(1);
221
+ }
222
+ } catch (error) {}
223
+ }
224
+ }
225
+ scrollToBottom();
226
+ }, [
227
+ greetingMessage,
228
+ hotQuestionsList
229
+ ]);
230
+ //语音转文字
231
+ useEffect(()=>{
232
+ if (bese64String != "") {
233
+ speechToText();
234
+ }
235
+ //发送给后端语音brse64
236
+ }, [
237
+ bese64String
238
+ ]);
239
+ //AI窗口,type:1发送打招呼信息 2点赞消息 3踩消息 4没有AI客服权限,5,发送超过10万字消息 6, 没有AI客服权限,发送最热的问题
240
+ const sendGreetingMessage = (type)=>{
241
+ let questionsList = [];
242
+ let obj = {};
243
+ if (type == 1) {
244
+ questionsList = hotQuestionsList.map((item, index)=>{
245
+ if (index < 3) {
246
+ return {
247
+ key: "messageSource",
248
+ value: item.id,
249
+ question: item.question,
250
+ answer: item.answer
251
+ };
252
+ } else {
253
+ return null;
254
+ }
255
+ });
256
+ questionsList = questionsList.filter((i)=>i != null);
257
+ obj = {
258
+ roomId: roomId,
259
+ sender: "AI",
260
+ recevier: mid,
261
+ message: `Hi!我是有问必答的实训云智能客服,请问您遇到了什么问题?`,
262
+ extraInfos: questionsList
263
+ };
264
+ } else if (type == 2) {
265
+ obj = {
266
+ roomId: roomId,
267
+ sender: "AI",
268
+ recevier: mid,
269
+ message: `您的点赞是我最大的鼓励!`,
270
+ createdAt: getDataTime(-1),
271
+ extraInfos: [
272
+ {
273
+ key: "messageSource",
274
+ value: "knowledgebase"
275
+ }
276
+ ]
277
+ };
278
+ } else if (type == 3) {
279
+ obj = {
280
+ roomId: roomId,
281
+ sender: "AI",
282
+ recevier: mid,
283
+ message: `谢谢您的反馈,我会努力改进的!`,
284
+ createdAt: getDataTime(-1),
285
+ extraInfos: [
286
+ {
287
+ key: "messageSource",
288
+ value: "knowledgebase"
289
+ }
290
+ ]
291
+ };
292
+ } else if (type == 4) {
293
+ obj = {
294
+ roomId: roomId,
295
+ sender: mid,
296
+ recevier: "AI",
297
+ message: keyWord,
298
+ createdAt: getDataTime(-1),
299
+ quotedMessage: citationContent.content,
300
+ extraInfos: [
301
+ {
302
+ key: "messageSource",
303
+ value: "knowledgebase"
304
+ }
305
+ ]
306
+ };
307
+ } else if (type == 5) {
308
+ obj = {
309
+ roomId: roomId,
310
+ sender: "AI",
311
+ recevier: mid,
312
+ message: "抱歉!您今日的提问量已经达到最大限额,请您明日再来提问。",
313
+ createdAt: getDataTime(-1),
314
+ quotedMessage: citationContent.content,
315
+ extraInfos: [
316
+ {
317
+ key: "messageSource",
318
+ value: "knowledgebase"
319
+ }
320
+ ]
321
+ };
322
+ } else if (type == 6) {
323
+ questionsList = hotQuestionsList.map((item)=>{
324
+ return {
325
+ key: "messageSource",
326
+ value: item.id,
327
+ question: item.question,
328
+ answer: item.answer
329
+ };
330
+ });
331
+ obj = {
332
+ roomId: roomId,
333
+ sender: "AI",
334
+ recevier: mid,
335
+ message: `猜你想问:`,
336
+ extraInfos: questionsList
337
+ };
338
+ }
339
+ setKeyWord("");
340
+ setQuestionsList([]);
341
+ setCitationContent({});
342
+ http.post(`${urllocation}/chat-service/public/v1.0/history-messages`, obj, {
343
+ headers: {
344
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
345
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
346
+ }
347
+ }).then((res)=>{
348
+ if (res.data.id) {
349
+ setHistoryMessageList((historyMessageList)=>{
350
+ let newHistoryMessageList = historyMessageList.concat(_object_spread_props(_object_spread({}, obj), {
351
+ id: res.data.id,
352
+ upvoted: false,
353
+ downvoted: false,
354
+ quotedMessage: "",
355
+ createdAt: getDataTime(-1),
356
+ extraInfo: JSON.stringify(obj.extraInfos)
357
+ }));
358
+ return newHistoryMessageList;
359
+ });
360
+ scrollToBottom();
361
+ if (type == 4) {
362
+ sendGreetingMessage(6);
363
+ }
364
+ }
365
+ }).catch((err)=>{
366
+ console.log(err);
367
+ });
368
+ };
369
+ //消息发送给老师type == 1,召唤老师时发送,type == 2,在老师聊天窗口聊天
370
+ const sendToTeacher = (type)=>{
371
+ console.log("消息发送给老师111");
372
+ let obj = {};
373
+ if (type == 1) {
374
+ obj = {
375
+ roomId: roomId,
376
+ sender: mid,
377
+ recevier: chatWith.uid,
378
+ message: problem.question
379
+ };
380
+ setProblem({});
381
+ } else if (type == 2) {
382
+ let list = roomList.filter((item)=>item.roomId == roomId);
383
+ let recevier = '';
384
+ if (list.length > 0) {
385
+ recevier = list[0].sender;
386
+ }
387
+ obj = {
388
+ roomId: roomId,
389
+ sender: mid,
390
+ recevier: recevier,
391
+ message: keyWord,
392
+ quotedMessage: citationContent.content || ""
393
+ };
394
+ }
395
+ http.post(`${urllocation}/chat-service/public/v1.0/chat-with-user/messages`, obj, {
396
+ headers: {
397
+ "x-module-id": userData.modules.find((ele)=>ele.short == "TeacherAnswer").id,
398
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
399
+ }
400
+ }).then((res)=>{
401
+ if (res.data.id) {
402
+ setHistoryMessageList((historyMessageList)=>{
403
+ let newHistoryMessageList = historyMessageList.concat(_object_spread_props(_object_spread({}, obj), {
404
+ id: res.data.id,
405
+ upvoted: false,
406
+ downvoted: false,
407
+ createdAt: getDataTime(-1)
408
+ }));
409
+ return newHistoryMessageList;
410
+ });
411
+ scrollToBottom();
412
+ //记录一个问题id,用于记录老师和学生之间的聊天保存到实验报告中
413
+ // if(stepIds != undefined && stepIds != '' && (showType == 3 || showType == 4)){
414
+ // setChatObj({'roomId':roomId,'id':res.data.id});
415
+ //判断当前窗口是否是
416
+ if (type == 1) {
417
+ let roomList = [
418
+ {
419
+ 'roomId': roomId,
420
+ 'id': res.data.id
421
+ }
422
+ ];
423
+ setChatObj((list)=>{
424
+ let list2 = list.filter((item)=>item.id != roomList[0].id);
425
+ return list2.concat(roomList);
426
+ });
427
+ }
428
+ // }
429
+ }
430
+ }).catch((err)=>{
431
+ console.log(err);
432
+ });
433
+ };
434
+ //发送知识库问题 item,flag == 1 是获取问候信息的答案,flag == 2 是普通消息
435
+ const sendMessage = (item, flag)=>{
436
+ let questions = [];
437
+ if (item && flag) {
438
+ questions = [
439
+ item
440
+ ];
441
+ }
442
+ //点击知识库的问题,或者是点击问候消息
443
+ if (questions.length > 0) {
444
+ questions = questions[0];
445
+ //向知识库发送问题 type 1,发送问题 2 发送答案 obj 需要的参数
446
+ let obj = {
447
+ roomId: roomId,
448
+ sender: mid,
449
+ recevier: "AI",
450
+ message: questions.question,
451
+ extraInfos: [
452
+ {
453
+ key: "questionId",
454
+ value: flag == 1 ? questions.value : questions.id
455
+ }
456
+ ]
457
+ };
458
+ //发送问题 1 类型,发送问题需要的参数,问题的答案id等
459
+ sendingExistingIssues(1, obj, {
460
+ key: "questionId",
461
+ value: flag == 1 ? questions.value : questions.id,
462
+ answer: questions.answer
463
+ });
464
+ setKeyWord("");
465
+ setQuestionsList([]);
466
+ setCitationContent({});
467
+ } else if (userData.modules.some((item)=>item.short == "AIservice")) {
468
+ setHistoryMessageList((historyMessageList)=>{
469
+ let newHistoryMessageList = historyMessageList.concat({
470
+ roomId: roomId,
471
+ sender: mid,
472
+ recevier: "AI",
473
+ message: keyWord,
474
+ quotedMessage: citationContent.content,
475
+ id: "654321",
476
+ upvoted: false,
477
+ downvoted: false,
478
+ createdAt: getDataTime(-1),
479
+ extraInfo: JSON.stringify([])
480
+ });
481
+ return newHistoryMessageList;
482
+ });
483
+ setFinished(false);
484
+ aiSendQuestions(3, {
485
+ //相关数据
486
+ roomId: roomId,
487
+ message: keyWord,
488
+ quotedMessage: citationContent.content || "",
489
+ regenerate: citationContent.content != "" ? false : true,
490
+ generateUpvoteOrDownvoteMessage: false
491
+ }, 1);
492
+ //存在AI客服
493
+ } else {
494
+ //不存在AI客服
495
+ sendGreetingMessage(4);
496
+ }
497
+ };
498
+ //向知识库发送问题 或答案 type:1 发送问题 2 接受答案
499
+ const sendingExistingIssues = (type, obj, questions)=>{
500
+ setHistoryMessageList((historyMessageList)=>{
501
+ let newHistoryMessageList = historyMessageList.concat(_object_spread_props(_object_spread({}, obj), {
502
+ id: null,
503
+ upvoted: false,
504
+ downvoted: false,
505
+ createdAt: getDataTime(-1),
506
+ extraInfo: JSON.stringify(obj.extraInfos)
507
+ }));
508
+ return newHistoryMessageList;
509
+ });
510
+ scrollToBottom();
511
+ http.post(`${urllocation}/chat-service/public/v1.0/history-messages`, obj, {
512
+ headers: {
513
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
514
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
515
+ }
516
+ }).then((res)=>{
517
+ if (res.data.id) {
518
+ //更新聊天记录id
519
+ setHistoryMessageList((historyMessageList)=>{
520
+ let newHistoryMessageList = historyMessageList.map((item)=>{
521
+ if (item.id == null) {
522
+ return _object_spread_props(_object_spread({}, item), {
523
+ id: res.data.id
524
+ });
525
+ } else {
526
+ return item;
527
+ }
528
+ });
529
+ return newHistoryMessageList;
530
+ });
531
+ }
532
+ if (type == 1) {
533
+ //发送答案,调用自动回答
534
+ let dataObj = {
535
+ roomId: roomId,
536
+ sender: "AI",
537
+ recevier: mid,
538
+ message: questions.answer,
539
+ extraInfos: [
540
+ {
541
+ key: "questionId",
542
+ value: questions.value
543
+ }
544
+ ]
545
+ };
546
+ sendingExistingIssues(2, dataObj, '');
547
+ testLabQuestion(obj.message, questions.answer, '');
548
+ }
549
+ }).then((res)=>{
550
+ console.log(res);
551
+ });
552
+ };
553
+ //向AI发送问题 type == 1 发送点赞或踩消息,type == 2 发送重新生成消息,type == 3 正常发送消息
554
+ let content = ''; //用于实验报告的问题记录
555
+ const aiSendQuestions = (type, obj, id)=>{
556
+ content = '';
557
+ // if (type == 3) {
558
+ // try {
559
+ // if (ctrl && ctrl.current) {
560
+ // ctrl.current.abort();
561
+ // }
562
+ // } catch (error) {}
563
+ // clearTimeout(receiveMessageTimer.current);
564
+ // setHistoryMessageList((historyMessageList) => {
565
+ // return historyMessageList.filter((item) => item.id != "123456");
566
+ // });
567
+ // setFinished(true);
568
+ // return;
569
+ // }
570
+ ctrl.current = new AbortController();
571
+ clearTimeout(receiveMessageTimer.current);
572
+ receiveMessageTimer.current = setTimeout(()=>{
573
+ // console.log('超时终止1111')
574
+ setHistoryMessageList((historyMessageList)=>{
575
+ return historyMessageList.filter((item)=>item.id != "123456" && item.id != "654321");
576
+ });
577
+ setFinished(true);
578
+ ctrl.current.abort();
579
+ setHistoryMessageList((historyMessageList)=>{
580
+ return historyMessageList.concat({
581
+ roomId: roomId,
582
+ sender: "AI",
583
+ recevier: mid,
584
+ message: "网络异常,请稍后重试!",
585
+ id: "123456",
586
+ createdAt: getDataTime(-1),
587
+ extraInfo: null
588
+ });
589
+ });
590
+ }, 60 * 1000);
591
+ let data = JSON.stringify(obj);
592
+ // if (type == 1 || type == 2) {
593
+ // data = JSON.stringify(obj);
594
+ // } else if(type == 3){
595
+ // data = JSON.stringify({
596
+ // //相关数据
597
+ // roomId: roomId,
598
+ // message: keyWord,
599
+ // quotedMessage: citationContent.content || "",
600
+ // regenerate: citationContent.content != "" ? false : true,
601
+ // generateUpvoteOrDownvoteMessage: false,
602
+ // });
603
+ // }
604
+ setKeyWord("");
605
+ setQuestionsList([]);
606
+ setTimeout(()=>{
607
+ setQuestionsList([]);
608
+ }, 2000);
609
+ //占位信息
610
+ setHistoryMessageList((historyMessageList)=>{
611
+ if (type == 2) {
612
+ return historyMessageList.map((item)=>{
613
+ if (item.id == id) {
614
+ return {
615
+ roomId: roomId,
616
+ sender: "AI",
617
+ recevier: mid,
618
+ message: "正在输入...",
619
+ id: "123456",
620
+ createdAt: getDataTime(-1),
621
+ extraInfo: null
622
+ };
623
+ } else {
624
+ return item;
625
+ }
626
+ });
627
+ } else {
628
+ return historyMessageList.concat({
629
+ roomId: roomId,
630
+ sender: "AI",
631
+ recevier: mid,
632
+ message: "正在输入...",
633
+ id: "123456",
634
+ createdAt: getDataTime(-1),
635
+ extraInfo: null
636
+ });
637
+ }
638
+ });
639
+ setTimeout(()=>{
640
+ scrollToBottom();
641
+ }, 10);
642
+ //使用fetchEventSource接收数据
643
+ const eventSource = fetchEventSource(`${urllocation}/chat-service/public/v1.0/chat-with-ai/messages`, {
644
+ method: "POST",
645
+ headers: {
646
+ "Content-Type": "application/json",
647
+ Accept: "text/event-stream,application/json",
648
+ "X-Auth-Jwt": window.localStorage.getItem("usertoken") || "",
649
+ "Auth-Token": userData.token,
650
+ "X-Module-Id": userData.modules.find((ele)=>ele.short == "AIservice").id
651
+ },
652
+ body: data,
653
+ signal: ctrl.current.signal,
654
+ openWhenHidden: true,
655
+ onopen (res) {
656
+ console.info("eventSource open: ", res);
657
+ clearTimeout(receiveMessageTimer.current);
658
+ if (res.status >= 300) {
659
+ console.log("sdckjsdncskdcjsdc", res.status);
660
+ setFinished(true);
661
+ setHistoryMessageList((historyMessageList)=>{
662
+ return historyMessageList.filter((item)=>item.id != "123456" && item.id != "654321");
663
+ });
664
+ ctrl.current.abort();
665
+ }
666
+ if (res.status == 200) {
667
+ setFinished(false);
668
+ }
669
+ if (res.status == 401) {
670
+ //身份认证未通过,从新请求新的token后再次发送请求
671
+ verifyJWT(urllocation).then(()=>{
672
+ console.log("重新请求");
673
+ setHistoryMessageList((historyMessageList)=>{
674
+ return historyMessageList.filter((item)=>item.id != "123456" && item.id != "654321");
675
+ });
676
+ aiSendQuestions(type, obj, id);
677
+ });
678
+ }
679
+ if (res.status == 403) {
680
+ //暂无权限
681
+ console.log("暂无权限");
682
+ setHistoryMessageList((historyMessageList)=>{
683
+ return historyMessageList.concat({
684
+ roomId: roomId,
685
+ sender: "AI",
686
+ recevier: mid,
687
+ message: "暂无权限",
688
+ id: "123456",
689
+ createdAt: "",
690
+ extraInfo: null
691
+ });
692
+ });
693
+ }
694
+ if (res.status == 429) {
695
+ //同一时间只允许进行一个对话。
696
+ }
697
+ if (res.status == 429) {
698
+ //每天问答的 Token 数必须小于等于 10 万。
699
+ sendGreetingMessage(5);
700
+ }
701
+ if (res.status == 500) {
702
+ // 系统错误,请稍后再试。
703
+ setHistoryMessageList((historyMessageList)=>{
704
+ return historyMessageList.concat({
705
+ roomId: roomId,
706
+ sender: "AI",
707
+ recevier: mid,
708
+ message: "系统出错了,请稍后重试!",
709
+ id: "123456",
710
+ createdAt: "",
711
+ extraInfo: null
712
+ });
713
+ });
714
+ }
715
+ },
716
+ onerror (err) {
717
+ console.log(err, "dflkvdmfvlkdfv");
718
+ let state = err.response;
719
+ setHistoryMessageList((historyMessageList)=>{
720
+ return historyMessageList.concat({
721
+ roomId: roomId,
722
+ sender: "AI",
723
+ recevier: mid,
724
+ message: "系统出错了,请稍后重试!",
725
+ id: "123456",
726
+ createdAt: "",
727
+ extraInfo: null
728
+ });
729
+ });
730
+ },
731
+ onmessage (event) {
732
+ //识别的内容
733
+ // console.log("eventSource msg: ", event.data);
734
+ let msg = JSON.parse(event.data);
735
+ if (msg.message) {
736
+ content = content + msg.message;
737
+ renderAiAnswer(msg, id, type);
738
+ }
739
+ if (msg.finished) {
740
+ setFinished(true); //发送结束
741
+ testLabQuestion(JSON.parse(data).message, content, '');
742
+ }
743
+ },
744
+ onclose () {
745
+ setFinished(true); //发送结束
746
+ setHistoryMessageList((historyMessageList)=>{
747
+ return historyMessageList.filter((item)=>item.id != "123456");
748
+ });
749
+ }
750
+ });
751
+ };
752
+ //渲染AI回答
753
+ const renderAiAnswer = (msg, message_id, type)=>{
754
+ // console.log(aiSendQuestions().abort(),'slkdsdsdsd')
755
+ let obj = msg;
756
+ let id = msg.messageId;
757
+ setHistoryMessageList((historyMessageList)=>{
758
+ let list1 = historyMessageList;
759
+ //删除临时数据
760
+ list1 = list1.filter((item)=>{
761
+ return item.id != "123456";
762
+ });
763
+ //重新生成答案时,使用原来的消息
764
+ if (message_id != undefined) {
765
+ list1 = list1.filter((item)=>{
766
+ return item.id != message_id;
767
+ });
768
+ }
769
+ let list = historyMessageList.filter((item)=>{
770
+ return item.id == id;
771
+ });
772
+ let message = "";
773
+ if (list.length == 0) {
774
+ message = obj.message;
775
+ let newHistoryMessageList = list1.concat({
776
+ roomId: roomId,
777
+ sender: "AI",
778
+ recevier: mid,
779
+ message: message,
780
+ id: id,
781
+ upvoted: false,
782
+ downvoted: false,
783
+ createdAt: getDataTime(-1),
784
+ extraInfo: type == 1 ? JSON.stringify([
785
+ {
786
+ key: "isVoteMessage",
787
+ value: true
788
+ }
789
+ ]) : null
790
+ });
791
+ return newHistoryMessageList;
792
+ } else {
793
+ let newHistoryMessageList2 = list1.map((item)=>{
794
+ message = item.message + obj.message;
795
+ if (item.id == id) {
796
+ return _object_spread_props(_object_spread({}, item), {
797
+ message: message
798
+ });
799
+ } else {
800
+ return item;
801
+ }
802
+ });
803
+ return newHistoryMessageList2;
804
+ }
805
+ });
806
+ setTimeout(()=>{
807
+ scrollToBottom();
808
+ }, 10);
809
+ };
810
+ //问题记录到实验报告中
811
+ const testLabQuestion = (title, content, teachId)=>{
812
+ // console.log(title,content,'记录到实验报告中')
813
+ if (stepIds != undefined && stepIds != '' && (showType == 3 || showType == 4)) {
814
+ http.post(`${urllocation}/sandboxes/public/v1.0/labquestion`, {
815
+ title: title,
816
+ content: content,
817
+ teachId: teachId != undefined ? teachId : chatWith.uid | mid,
818
+ stepId: stepId,
819
+ stepIds: stepIds
820
+ }, {
821
+ headers: {
822
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
823
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
824
+ }
825
+ }).then(()=>{
826
+ console.log(roomId, chatObj, 'roomIdroomIdroomIdroomId');
827
+ setChatObj((list1)=>{
828
+ let list = list1.filter((e)=>e.roomId != roomId);
829
+ return list;
830
+ });
831
+ });
832
+ }
833
+ };
834
+ //语音转文字
835
+ const speechToText = ()=>{
836
+ http.post(`${urllocation}/chat-service/public/v1.0/speech:recognize`, {
837
+ audio: bese64String
838
+ }, {
839
+ headers: {
840
+ "x-module-id": userData.modules.find((ele)=>ele.short == "AIservice").id,
841
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
842
+ }
843
+ }).then((res)=>{
844
+ setVoiceRecordingStatus(3);
845
+ if (res.data) {
846
+ setKeyWord(res.data.text);
847
+ resettingBottomHei();
848
+ }
849
+ }).catch((err)=>{
850
+ setKeyWord("");
851
+ setVoiceRecordingStatus(3);
852
+ });
853
+ };
854
+ //创建聊天室
855
+ const createRooms = (uid)=>{
856
+ return http.post(`${urllocation}/chat-service/public/v1.0/rooms`, {
857
+ chatWith: uid
858
+ }, {
859
+ headers: {
860
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
861
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
862
+ }
863
+ });
864
+ };
865
+ //获取历史消息 flag:1,历史记录点击定位,2,代表是上拉加载,3,存在新的消息-->老师回答等,4,下拉加载,滚动到底部时,主要用于查看历史记录
866
+ const getHistoryMessage = (pageNum, flag, id = "1")=>{
867
+ clearTimeout(roomMessage.current);
868
+ // flag == 1 时已经设置好了位置标记
869
+ let last_id = "";
870
+ if (flag == 2 && historyMessageList.length > 0) {
871
+ last_id = historyMessageList[0].id;
872
+ }
873
+ if (flag != 1 && last_id != "") {
874
+ setLastId(last_id);
875
+ }
876
+ //取消搜索页码标记
877
+ if (flag == 4 && pageNum == 1) {
878
+ setPageNumHistory(0);
879
+ }
880
+ let rid = flag == 3 ? id : roomId;
881
+ if (rid == "") return;
882
+ return http.get(`${urllocation}/chat-service/public/v1.0/history-messages`, {
883
+ params: {
884
+ roomId: rid,
885
+ page: pageNum ? pageNum : 1,
886
+ maxPageSize: 30,
887
+ direction: "desc"
888
+ },
889
+ headers: {
890
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
891
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
892
+ }
893
+ }).then((res)=>{
894
+ let totalNumber = 0;
895
+ let roomList = [];
896
+ setRoomList((list)=>{
897
+ roomList = list;
898
+ return list;
899
+ });
900
+ if (res.data.messages.length > 0) {
901
+ clearTimeout(listTimer.current);
902
+ let total = res.data.total;
903
+ let maxPageSize = 30;
904
+ let dataList = res.data.messages.reverse();
905
+ setPageCount(Math.ceil(total / maxPageSize));
906
+ let newHistoryMessageList = [];
907
+ setHistoryMessageList((historyMessageList)=>{
908
+ //获取历史消息 flag:1,历史记录点击定位,2,代表是下拉加载,3,存在新的消息-->老师回答等
909
+ newHistoryMessageList = [];
910
+ if (flag == 1) {
911
+ newHistoryMessageList = dataList;
912
+ }
913
+ if (flag == 4) {
914
+ newHistoryMessageList = historyMessageList.concat(dataList); //下拉加载,向后追加内容
915
+ }
916
+ if (flag == 2) {
917
+ if (pageNum == 1) {
918
+ newHistoryMessageList = dataList;
919
+ } else {
920
+ newHistoryMessageList = dataList.concat(historyMessageList);
921
+ }
922
+ }
923
+ if (flag == 3) {
924
+ newHistoryMessageList = dataList;
925
+ }
926
+ //去重
927
+ let res = new Map();
928
+ newHistoryMessageList = newHistoryMessageList.filter((a)=>!res.has(a.id) && res.set(a.id, 1));
929
+ totalNumber = newHistoryMessageList.length;
930
+ return newHistoryMessageList;
931
+ });
932
+ //如果在跟老师的聊天窗口,用于找到与老师的最新的聊天,并不在与老师对话的窗口中,并聊天窗口相同
933
+ try {
934
+ if (stepIds != undefined && stepIds != '' && (showType == 3 || showType == 4)) {
935
+ fildChatRecords(newHistoryMessageList);
936
+ }
937
+ } catch (error) {}
938
+ if (flag != 4) {
939
+ if (pageNum == 1 && (flag == 2 || flag == 3)) {
940
+ scrollToBottom();
941
+ } else {
942
+ scrollTo("li_flag");
943
+ }
944
+ }
945
+ setBottomLoading(false);
946
+ setLoading(false);
947
+ setGreetingMessage(true);
948
+ //召唤老师回答
949
+ if (problem != undefined && problem.user != undefined && problem.question != undefined) {
950
+ sendToTeacher(1);
951
+ }
952
+ } else {
953
+ setPageCount(0);
954
+ setGreetingMessage(true);
955
+ setBottomLoading(false);
956
+ setLoading(false);
957
+ setHistoryMessageList([]);
958
+ //召唤老师回答
959
+ if (problem != undefined && problem.user != undefined && problem.question != undefined) {
960
+ sendToTeacher(1);
961
+ }
962
+ }
963
+ // console.log(roomList,rid,roomId,555555);
964
+ //不是ai窗口循环查询消息
965
+ let chatWindow = roomList.filter((item)=>item.roomId == rid);
966
+ let isAiChatWindow = chatWindow.length > 0 && chatWindow[0].sender != undefined && chatWindow[0].sender == 'AI' ? true : false;
967
+ if (!isAiChatWindow && roomList.length > 0) {
968
+ getRoomidHistoryMessage(totalNumber, rid);
969
+ }
970
+ }).catch((res)=>{
971
+ setLoading(false);
972
+ });
973
+ };
974
+ //用于循环新消息
975
+ const getRoomidHistoryMessage = (totalNumber, rid)=>{
976
+ clearTimeout(roomMessage.current);
977
+ roomMessage.current = setTimeout(()=>{
978
+ getRoomidHistoryMessage(totalNumber, rid);
979
+ }, 5000);
980
+ if (rid == '') return;
981
+ // console.log(roomList,2222222);
982
+ return http.get(`${urllocation}/chat-service/public/v1.0/history-messages`, {
983
+ params: {
984
+ roomId: rid,
985
+ page: 1,
986
+ maxPageSize: totalNumber < 30 ? 30 : totalNumber + 10,
987
+ direction: "desc"
988
+ },
989
+ headers: {
990
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
991
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
992
+ }
993
+ }).then((res)=>{
994
+ let newHistoryMessageList = [];
995
+ if (res.data.messages.length > 0) {
996
+ let dataList = res.data.messages.reverse();
997
+ setHistoryMessageList((historyMessageList)=>{
998
+ newHistoryMessageList = dataList;
999
+ //去重
1000
+ let res = new Map();
1001
+ newHistoryMessageList = newHistoryMessageList.filter((a)=>!res.has(a.id) && res.set(a.id, 1));
1002
+ return newHistoryMessageList;
1003
+ });
1004
+ if (dataList.length > totalNumber) {
1005
+ scrollToBottom();
1006
+ }
1007
+ }
1008
+ try {
1009
+ if (stepIds != undefined && stepIds != '' && (showType == 3 || showType == 4)) {
1010
+ fildChatRecords(newHistoryMessageList);
1011
+ }
1012
+ } catch (error) {}
1013
+ });
1014
+ };
1015
+ //在聊天对话框中查找需要记录的问题及答案
1016
+ const fildChatRecords = (newHistoryMessageList)=>{
1017
+ //1、找到对应的聊天室
1018
+ //2、找到与老师对话的新聊天
1019
+ //3、保存聊天到实验报告
1020
+ // console.log('查找聊天111',chatObj,newHistoryMessageList);
1021
+ try {
1022
+ let chatObj = [];
1023
+ setChatObj((item)=>{
1024
+ chatObj = item;
1025
+ return item;
1026
+ });
1027
+ // console.log(chatObj,555555);
1028
+ let room = chatObj.filter((item)=>item.roomId == roomId);
1029
+ if (room.length > 0) {
1030
+ // console.log(room,'dfvdfvdfvdfv')
1031
+ let chatID = room[0].id;
1032
+ console.log(chatID, 'chatIDchatIDchatID');
1033
+ let index = -1;
1034
+ newHistoryMessageList.forEach((item, i)=>{
1035
+ // console.log(item,item.id,'lskdcmsldksdcsdc')
1036
+ if (item.id == chatID) {
1037
+ index = i;
1038
+ return false;
1039
+ }
1040
+ });
1041
+ //有新的消息
1042
+ if (index != -1) {
1043
+ let newMessage = newHistoryMessageList.slice(index);
1044
+ console.log(newMessage, 'newMessagenewMessage');
1045
+ let result = [];
1046
+ newMessage.forEach((item, index)=>{
1047
+ let isQuestion = item.receiver !== mid //是否为问题
1048
+ ;
1049
+ if (isQuestion) {
1050
+ //问题
1051
+ if (newMessage[index + 1] && newMessage[index + 1].receiver === mid) {
1052
+ result.push({
1053
+ question: item.message,
1054
+ id: item.receiver,
1055
+ answer: newMessage[index + 1].message
1056
+ });
1057
+ return;
1058
+ }
1059
+ }
1060
+ });
1061
+ console.log(result, '存储的消息');
1062
+ result.map((item)=>{
1063
+ testLabQuestion(item.question, item.answer, item.id);
1064
+ });
1065
+ }
1066
+ }
1067
+ } catch (error) {}
1068
+ };
1069
+ //点赞消息
1070
+ const likeMessage = (id, state)=>{
1071
+ let url = "";
1072
+ //点赞状态
1073
+ if (!state) {
1074
+ url = `${urllocation}/chat-service/public/v1.0/history-messages:upvote`;
1075
+ } else {
1076
+ url = `${urllocation}/chat-service/public/v1.0/history-messages:cancelUpvote`;
1077
+ }
1078
+ http.post(url, {
1079
+ messageId: id
1080
+ }, {
1081
+ headers: {
1082
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
1083
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
1084
+ }
1085
+ }).then((res)=>{
1086
+ setHistoryMessageList((historyMessageList)=>{
1087
+ let list = historyMessageList;
1088
+ list = list.map((item)=>{
1089
+ return _object_spread_props(_object_spread({}, item), {
1090
+ upvoted: item.id == id ? !state : item.upvoted,
1091
+ downvoted: item.id == id && !state ? state : item.downvoted
1092
+ });
1093
+ });
1094
+ return list;
1095
+ });
1096
+ });
1097
+ };
1098
+ //踩
1099
+ const disagreeMessage = (id, state)=>{
1100
+ let url = "";
1101
+ //点赞状态
1102
+ if (!state) {
1103
+ url = `${urllocation}/chat-service/public/v1.0/history-messages:downvote`;
1104
+ } else {
1105
+ url = `${urllocation}/chat-service/public/v1.0/history-messages:cancelDownvote`;
1106
+ }
1107
+ http.post(url, {
1108
+ messageId: id
1109
+ }, {
1110
+ headers: {
1111
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
1112
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
1113
+ }
1114
+ }).then((res)=>{
1115
+ setHistoryMessageList((historyMessageList)=>{
1116
+ let list = historyMessageList;
1117
+ list = list.map((item)=>{
1118
+ return _object_spread_props(_object_spread({}, item), {
1119
+ downvoted: item.id == id ? !state : item.downvoted,
1120
+ upvoted: item.id == id && !state ? state : item.upvoted
1121
+ });
1122
+ });
1123
+ return list;
1124
+ });
1125
+ });
1126
+ };
1127
+ //获取问题列表flag ==1 是问候消息 2,搜索列表 展示相关问题
1128
+ const getQuestiionsList = (value, flag)=>{
1129
+ let data = {};
1130
+ if (flag == 1) {
1131
+ data = {
1132
+ page: 1,
1133
+ maxPageSize: 5
1134
+ };
1135
+ } else {
1136
+ data = {
1137
+ page: 1,
1138
+ maxPageSize: 4,
1139
+ question: value
1140
+ };
1141
+ }
1142
+ http.get(`${urllocation}/chat-service/public/v1.0/knowledge-base/questions`, {
1143
+ params: data,
1144
+ headers: {
1145
+ "x-module-id": userData.modules.find((ele)=>ele.short == "IntelligentCustomerService").id,
1146
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
1147
+ }
1148
+ }).then((res)=>{
1149
+ if (res.data.questions) {
1150
+ if (flag == 1) {
1151
+ setHotQuestionsList(res.data.questions);
1152
+ } else {
1153
+ setQuestionsList(res.data.questions);
1154
+ }
1155
+ }
1156
+ });
1157
+ };
1158
+ //获取老师列表
1159
+ const getTeacherList = (keyWord)=>{
1160
+ http.get(`${urllocation}/chat-service/public/v1.0/teachers`, {
1161
+ params: {
1162
+ name: keyWord
1163
+ },
1164
+ headers: {
1165
+ "x-module-id": userData.modules.find((ele)=>ele.short == "TeacherAnswer").id,
1166
+ "x-auth-jwt": window.localStorage.getItem("usertoken") || ""
1167
+ }
1168
+ }).then((res)=>{
1169
+ console.log(res);
1170
+ if (res.data) {
1171
+ setTeacherList(res.data.teachers);
1172
+ }
1173
+ });
1174
+ };
1175
+ //设置滚动条滚动到底部
1176
+ const scrollToBottom = ()=>{
1177
+ const container = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
1178
+ if (container) {
1179
+ container.scrollTop = container.scrollHeight;
1180
+ }
1181
+ };
1182
+ const scrollTo = (id)=>{
1183
+ const container = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
1184
+ const container2 = document.getElementById(id);
1185
+ if (container && container2) {
1186
+ container.scrollTop = 60;
1187
+ try {
1188
+ setTimeout(()=>{
1189
+ let top = showType == 1 || showType == 3 ? $("#li_flag").offset().top - 20 : $("#chat_content_modal #li_flag").offset().top - $("#chat_content_modal").offset().top + 24;
1190
+ $(`#${showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal"}`).animate({
1191
+ scrollTop: top
1192
+ }, 0);
1193
+ }, 10);
1194
+ } catch (error) {}
1195
+ setLoading(false);
1196
+ }
1197
+ };
1198
+ // 获取新的JWT
1199
+ const verifyJWT = (url)=>{
1200
+ return new Promise((resolve)=>{
1201
+ http.get(`${url}/regusers/login/Refreshtoken`).then((res)=>{
1202
+ if (res.data.code == 200) {
1203
+ window.localStorage.setItem("usertoken", res.data.data);
1204
+ resolve(res.data.data);
1205
+ } else {
1206
+ throw new Error(res.data.code);
1207
+ }
1208
+ }).catch((err)=>{
1209
+ resolve(err);
1210
+ });
1211
+ });
1212
+ };
1213
+ //渲染头部
1214
+ const renderHeader = ()=>{
1215
+ let list = roomList.filter((e)=>e.roomId == roomId);
1216
+ let title = '智能回答';
1217
+ if (list.length > 0 && list[0].name) {
1218
+ title = list[0].name;
1219
+ }
1220
+ let count = 0;
1221
+ roomList.map((item)=>{
1222
+ count = count + item.unreadCount;
1223
+ });
1224
+ if (showType == 4) {
1225
+ return /*#__PURE__*/ _jsxs("div", {
1226
+ className: styles.top,
1227
+ children: [
1228
+ /*#__PURE__*/ _jsx("div", {
1229
+ className: styles.user,
1230
+ children: /*#__PURE__*/ _jsx("p", {
1231
+ children: title
1232
+ })
1233
+ }),
1234
+ /*#__PURE__*/ _jsxs("div", {
1235
+ className: styles.operate,
1236
+ children: [
1237
+ /*#__PURE__*/ _jsx("i", {
1238
+ onClick: ()=>{
1239
+ setShowHistory(true);
1240
+ },
1241
+ children: /*#__PURE__*/ _jsx(CustomRecord, {})
1242
+ }),
1243
+ /*#__PURE__*/ _jsx("span", {
1244
+ className: styles.line
1245
+ }),
1246
+ /*#__PURE__*/ _jsx("i", {
1247
+ onClick: ()=>{
1248
+ onEvent(serverName + serverUrl(), "click_智能问答_退出全屏", "提交");
1249
+ setFirstLoad(false); //重启滚动条在最上方
1250
+ setShowType(3);
1251
+ },
1252
+ children: /*#__PURE__*/ _jsx(CustomExitFullScreen, {})
1253
+ }),
1254
+ /*#__PURE__*/ _jsx("i", {
1255
+ onClick: ()=>{
1256
+ onEvent(serverName + serverUrl(), "click_智能问答_退出全屏", "提交");
1257
+ setShowType(3);
1258
+ setFirstLoad(false); //重启滚动条在最上方
1259
+ },
1260
+ children: /*#__PURE__*/ _jsx(CloseOutlined, {})
1261
+ })
1262
+ ]
1263
+ })
1264
+ ]
1265
+ });
1266
+ } else {
1267
+ return /*#__PURE__*/ _jsxs("div", {
1268
+ className: styles.top,
1269
+ children: [
1270
+ /*#__PURE__*/ _jsx("div", {
1271
+ className: styles.user,
1272
+ children: /*#__PURE__*/ _jsxs("p", {
1273
+ children: [
1274
+ showType == 1 && /*#__PURE__*/ _jsxs("i", {
1275
+ className: "lianxiren21",
1276
+ onClick: ()=>{
1277
+ setShowContacts(true);
1278
+ },
1279
+ children: [
1280
+ /*#__PURE__*/ _jsx(CustomContacts, {}),
1281
+ count > 0 ? /*#__PURE__*/ _jsx("span", {
1282
+ className: styles.count,
1283
+ children: count > 99 ? '99+' : count
1284
+ }) : ''
1285
+ ]
1286
+ }),
1287
+ title
1288
+ ]
1289
+ })
1290
+ }),
1291
+ /*#__PURE__*/ _jsxs("div", {
1292
+ className: styles.operate,
1293
+ children: [
1294
+ /*#__PURE__*/ _jsx("i", {
1295
+ className: "_lishixiao22",
1296
+ onClick: ()=>{
1297
+ setShowHistory(true);
1298
+ },
1299
+ children: /*#__PURE__*/ _jsx(CustomRecord, {})
1300
+ }),
1301
+ /*#__PURE__*/ _jsx("span", {
1302
+ className: styles.line
1303
+ }),
1304
+ showType == 1 ? /*#__PURE__*/ _jsx("i", {
1305
+ onClick: ()=>{
1306
+ onEvent(serverName + serverUrl(), "click_智能问答_全屏", "提交");
1307
+ // switchDialogBox(3, true);
1308
+ setShowType(2);
1309
+ childRef.current.roomsListTimer();
1310
+ },
1311
+ children: /*#__PURE__*/ _jsx(CustomFullScreen, {})
1312
+ }) : /*#__PURE__*/ _jsx("i", {
1313
+ onClick: ()=>{
1314
+ onEvent(serverName + serverUrl(), "click_智能问答_退出全屏", "提交");
1315
+ // switchDialogBox(1, true);
1316
+ setShowType(1);
1317
+ },
1318
+ children: /*#__PURE__*/ _jsx(CustomExitFullScreen, {})
1319
+ }),
1320
+ /*#__PURE__*/ _jsx("i", {
1321
+ onClick: onCancel,
1322
+ children: /*#__PURE__*/ _jsx(CloseOutlined, {})
1323
+ })
1324
+ ]
1325
+ })
1326
+ ]
1327
+ });
1328
+ }
1329
+ };
1330
+ //重置底部输入框高度
1331
+ const resettingBottomHei = ()=>{
1332
+ setTimeout(()=>{
1333
+ if (showType == 1 || showType == 3) {
1334
+ if (document.getElementById("Drawer_buttom_modal")) {
1335
+ let hei = document.getElementById("Drawer_buttom").offsetHeight;
1336
+ setButtomHei(hei);
1337
+ }
1338
+ } else {
1339
+ if (document.getElementById("Drawer_buttom_modal")) {
1340
+ let hei = document.getElementById("Drawer_buttom_modal").offsetHeight;
1341
+ setButtomHei(hei);
1342
+ }
1343
+ }
1344
+ }, 50);
1345
+ };
1346
+ //切换聊天室 type == renew ,存在新消息
1347
+ const switchChatRoom = (id, type)=>{
1348
+ setLastId("");
1349
+ setPageNum(1);
1350
+ setPageCount(0);
1351
+ setRoomId(id);
1352
+ //
1353
+ // if (type == "renew") {
1354
+ // getHistoryMessage(1, 3,id);
1355
+ // }else{
1356
+ // setRoomId(id);
1357
+ // }
1358
+ readMessage(id, urllocation, userData, http);
1359
+ };
1360
+ const saveContactsList = (list)=>{
1361
+ if (list != undefined) {
1362
+ setRoomList(list);
1363
+ }
1364
+ };
1365
+ //渲染问答
1366
+ const renderQuestion = ()=>{
1367
+ // console.log(lastId,'lastIdlastIdlastId')
1368
+ // console.log(mid, historyMessageList, "ddkfdscksdcs");
1369
+ if (historyMessageList.length > 0) {
1370
+ return /*#__PURE__*/ _jsx("ul", {
1371
+ className: styles.message_con,
1372
+ children: historyMessageList.map((item, i)=>{
1373
+ // console.log(item.message);
1374
+ let message = item.message;
1375
+ let li;
1376
+ // 是否需要显示日期
1377
+ let itemIndex = historyMessageList.findIndex((ite)=>ite.id === item.id);
1378
+ let time = "";
1379
+ // if(historyMessageList[i+1] != undefined && historyMessageList[i+1].createdAt != undefined && item.createdAt != undefined && item.createdAt != historyMessageList[i+1].createdAt){
1380
+ // time = getDataTime(item.createdAt);
1381
+ // }else{
1382
+ // time = getDataTime(item.createdAt);
1383
+ // }
1384
+ // let time1;
1385
+ // if(item.createdAt != undefined){
1386
+ // time1 = Date.parse(item.createdAt);
1387
+ // }
1388
+ // let time2 = Date.parse(historyMessageList[i+1]);
1389
+ // if (itemIndex <= 0) {
1390
+ // //第一项
1391
+ // time = dayjs(item.createdAt).format("YYYY-MM-DD HH:mm");
1392
+ // } else {
1393
+ // //非第一项 与上一项进行对比
1394
+ // let beforeTime = historyMessageList[itemIndex - 1].createdAt;
1395
+ // //判断与上一条数据 是否跨天
1396
+ // if (
1397
+ // dayjs(beforeTime).format("YYYY-MM-DD") !==
1398
+ // dayjs(item.createdAt).format("YYYY-MM-DD")
1399
+ // ) {
1400
+ // time = dayjs(item.createdAt).format("YYYY-MM-DD HH:mm");
1401
+ // } else {
1402
+ // //没有跨天 判断是否相隔超过10分钟
1403
+ // if (
1404
+ // dayjs(item.createdAt).valueOf() -
1405
+ // dayjs(beforeTime).valueOf() >
1406
+ // 10 * 60 * 1000
1407
+ // ) {
1408
+ // time = dayjs(item.createdAt).format("HH:mm");
1409
+ // }
1410
+ // }
1411
+ // }
1412
+ let dataTime = time;
1413
+ if (item.sender == mid) {
1414
+ //只有引用和复制功能
1415
+ li = /*#__PURE__*/ _jsxs(_Fragment, {
1416
+ children: [
1417
+ dataTime ? /*#__PURE__*/ _jsx("li", {
1418
+ className: styles.time,
1419
+ children: dataTime
1420
+ }) : "",
1421
+ /*#__PURE__*/ _jsxs("li", {
1422
+ className: styles.left,
1423
+ id: lastId == item.id ? "li_flag" : "",
1424
+ children: [
1425
+ /*#__PURE__*/ _jsx("div", {
1426
+ className: styles.main,
1427
+ children: /*#__PURE__*/ _jsxs("div", {
1428
+ className: styles.main_content,
1429
+ children: [
1430
+ /*#__PURE__*/ _jsx("div", {
1431
+ className: styles.operate_modal,
1432
+ children: /*#__PURE__*/ _jsxs("p", {
1433
+ className: styles.operate,
1434
+ children: [
1435
+ /*#__PURE__*/ _jsx("i", {
1436
+ className: "yinyong_quote1",
1437
+ onClick: ()=>{
1438
+ setCitationContent({
1439
+ content: item.message,
1440
+ id: item.id
1441
+ });
1442
+ resettingBottomHei();
1443
+ onEvent(serverName + serverUrl(), "click_智能问答_引用", "提交");
1444
+ },
1445
+ children: /*#__PURE__*/ _jsx(CustomQuote, {})
1446
+ }),
1447
+ copyTextOBJ.length > 0 && copyTextOBJ.some((list)=>list == item.id) ? /*#__PURE__*/ _jsx("i", {
1448
+ className: `tongyong-xuanzhongdui`,
1449
+ children: /*#__PURE__*/ _jsx(CustomDuihao, {})
1450
+ }) : /*#__PURE__*/ _jsx("i", {
1451
+ className: "fuzhi21",
1452
+ onClick: ()=>{
1453
+ let bol = copyText(item.message);
1454
+ if (bol) {
1455
+ let obj = copyTextOBJ;
1456
+ obj = obj.filter((list)=>list != item.id);
1457
+ obj.push(item.id);
1458
+ setCopyTextObj(obj);
1459
+ }
1460
+ setTimeout(()=>{
1461
+ let obj = copyTextOBJ;
1462
+ obj = obj.filter((list)=>list != item.id);
1463
+ setCopyTextObj(obj);
1464
+ }, 3000);
1465
+ onEvent(serverName + serverUrl(), "click_智能问答_复制", "提交");
1466
+ },
1467
+ children: /*#__PURE__*/ _jsx(CustomCopy, {})
1468
+ })
1469
+ ]
1470
+ })
1471
+ }),
1472
+ /*#__PURE__*/ _jsx("div", {
1473
+ className: styles.content,
1474
+ children: /*#__PURE__*/ _jsx("p", {
1475
+ dangerouslySetInnerHTML: {
1476
+ __html: remarkable.render(message)
1477
+ },
1478
+ className: styles.content_child
1479
+ })
1480
+ }),
1481
+ //引用消息
1482
+ item.quotedMessage && /*#__PURE__*/ _jsx("div", {
1483
+ className: styles.citation_content,
1484
+ children: getByteLen(item.quotedMessage) > 120 ? /*#__PURE__*/ _jsx(Tooltip, {
1485
+ overlayClassName: styles.popover_main_content,
1486
+ title: item.quotedMessage,
1487
+ placement: "leftTop",
1488
+ children: /*#__PURE__*/ _jsxs("p", {
1489
+ children: [
1490
+ item.quotedMessage,
1491
+ ">"
1492
+ ]
1493
+ })
1494
+ }) : /*#__PURE__*/ _jsx("p", {
1495
+ children: item.quotedMessage
1496
+ })
1497
+ })
1498
+ ]
1499
+ })
1500
+ }),
1501
+ showType == 2 || showType == 4 ? /*#__PURE__*/ _jsx("div", {
1502
+ className: styles.head_sculpture,
1503
+ style: {
1504
+ marginLeft: "12px"
1505
+ },
1506
+ children: /*#__PURE__*/ _jsx("img", {
1507
+ src: userData.avatar
1508
+ })
1509
+ }) : ""
1510
+ ]
1511
+ }, item.id)
1512
+ ]
1513
+ });
1514
+ } else {
1515
+ //获取用户头像
1516
+ let headImg = '';
1517
+ let chatWindow = roomList.filter((item)=>item.roomId == roomId);
1518
+ if (chatWindow.length > 0 && chatWindow[0].headImg != '') {
1519
+ headImg = chatWindow[0].headImg;
1520
+ }
1521
+ //是否在智能客服窗口
1522
+ let isAiChatWindow = chatWindow.length > 0 && chatWindow[0].sender != undefined && chatWindow[0].sender == 'AI' ? true : false;
1523
+ let header = 2; //代表是ai头像
1524
+ if (isAiChatWindow && item.extraInfo != undefined && JSON.parse(item.extraInfo).length > 0 && JSON.parse(item.extraInfo)[0].key == "isVoteMessage") {
1525
+ //使用AI头像
1526
+ header = 1;
1527
+ }
1528
+ li = /*#__PURE__*/ _jsxs(_Fragment, {
1529
+ children: [
1530
+ dataTime ? /*#__PURE__*/ _jsx("li", {
1531
+ className: styles.time,
1532
+ children: dataTime
1533
+ }) : "",
1534
+ /*#__PURE__*/ _jsxs("li", {
1535
+ className: styles.right,
1536
+ id: lastId == item.id ? "li_flag" : "",
1537
+ children: [
1538
+ (showType == 2 || showType == 4) && /*#__PURE__*/ _jsx("div", {
1539
+ className: styles.head_sculpture,
1540
+ style: {
1541
+ marginRight: "12px"
1542
+ },
1543
+ children: isAiChatWindow ? item.extraInfo == null || header == 1 ? /*#__PURE__*/ _jsx(CustomAiIcon, {}) : /*#__PURE__*/ _jsx("img", {
1544
+ src: knowledge_icon
1545
+ }) : /*#__PURE__*/ _jsx("img", {
1546
+ src: headImg
1547
+ })
1548
+ }),
1549
+ /*#__PURE__*/ _jsx("div", {
1550
+ className: styles.main,
1551
+ children: /*#__PURE__*/ _jsxs("div", {
1552
+ className: styles.main_content,
1553
+ children: [
1554
+ /*#__PURE__*/ _jsx("div", {
1555
+ className: styles.operate_modal,
1556
+ children: // 不是最后一行,
1557
+ historyMessageList.length - 1 != i && renderOperateBtn(item, isAiChatWindow, i)
1558
+ }),
1559
+ /*#__PURE__*/ _jsxs("div", {
1560
+ className: styles.content,
1561
+ children: [
1562
+ /*#__PURE__*/ _jsx("p", {
1563
+ dangerouslySetInnerHTML: {
1564
+ __html: remarkable.render(message)
1565
+ },
1566
+ className: styles.content_child
1567
+ }),
1568
+ item.extraInfo != undefined && JSON.parse(item.extraInfo).length > 0 && JSON.parse(item.extraInfo)[0].key == "messageSource" && JSON.parse(item.extraInfo)[0].value != "knowledgebase" && /*#__PURE__*/ _jsx("ul", {
1569
+ className: styles.association_problem,
1570
+ children: JSON.parse(item.extraInfo).map((list, index)=>{
1571
+ return /*#__PURE__*/ _jsxs("li", {
1572
+ onClick: ()=>{
1573
+ sendMessage(list, 1);
1574
+ },
1575
+ children: [
1576
+ index + 1,
1577
+ ".",
1578
+ list.question
1579
+ ]
1580
+ }, i + "_" + index + "_" + list.value);
1581
+ })
1582
+ })
1583
+ ]
1584
+ }),
1585
+ //引用消息
1586
+ item.quotedMessage && /*#__PURE__*/ _jsx("div", {
1587
+ className: styles.citation_content,
1588
+ children: getByteLen(item.quotedMessage) > 120 ? /*#__PURE__*/ _jsx(Tooltip, {
1589
+ overlayClassName: styles.popover_main_content,
1590
+ title: item.quotedMessage,
1591
+ placement: "leftTop",
1592
+ children: /*#__PURE__*/ _jsxs("p", {
1593
+ children: [
1594
+ item.quotedMessage,
1595
+ ">"
1596
+ ]
1597
+ })
1598
+ }) : /*#__PURE__*/ _jsx("p", {
1599
+ children: item.quotedMessage
1600
+ })
1601
+ }),
1602
+ //findTeacher//是否在召唤老师过程中,是否是最后一条消息
1603
+ !item.findTeacher && historyMessageList.length - 1 == i && item.id != "123456" && renderLastOperateBtn(item, isAiChatWindow, i),
1604
+ //召唤老师回答按钮
1605
+ isAiChatWindow && item.findTeacher && userData.modules.some((item)=>item.short == "TeacherAnswer") ? /*#__PURE__*/ _jsx("div", {
1606
+ className: `${styles.operate_modal_bottom}`,
1607
+ children: /*#__PURE__*/ _jsx("p", {
1608
+ className: styles.stop_findTeacher,
1609
+ children: /*#__PURE__*/ _jsx("span", {
1610
+ onClick: ()=>{
1611
+ setAnswerMode(-1);
1612
+ setTeacherList([]);
1613
+ setHistoryMessageList((historyMessageList)=>{
1614
+ return historyMessageList.filter((item)=>item.id != "-1");
1615
+ });
1616
+ },
1617
+ children: "停止召唤老师"
1618
+ })
1619
+ })
1620
+ }) : ''
1621
+ ]
1622
+ })
1623
+ })
1624
+ ]
1625
+ }, item.id)
1626
+ ]
1627
+ });
1628
+ }
1629
+ return li;
1630
+ })
1631
+ });
1632
+ } else {
1633
+ return "";
1634
+ }
1635
+ };
1636
+ //渲染相关操作按钮
1637
+ const renderOperateBtn = (item, isAiChatWindow, i)=>{
1638
+ //问候语及点赞下面不需要展示相关按钮
1639
+ let extraInfo = item.extraInfo;
1640
+ //JSON.parse(extraInfo)[0].key == 'questionId' 是联想问题
1641
+ if (extraInfo != undefined && JSON.parse(extraInfo).length > 0 && JSON.parse(extraInfo)[0].key == 'messageSource' || extraInfo != undefined && JSON.parse(extraInfo).length > 0 && JSON.parse(extraInfo)[0].key == 'isVoteMessage') {
1642
+ return '';
1643
+ }
1644
+ return /*#__PURE__*/ _jsxs("p", {
1645
+ className: styles.operate,
1646
+ children: [
1647
+ // 不在智能客服窗口,并已经点击了召唤老师,并有召唤老师权限
1648
+ isAiChatWindow && answerMode != 1 && userData.modules.some((item)=>item.short == "TeacherAnswer") && /*#__PURE__*/ _jsx("span", {
1649
+ className: styles.ask_question,
1650
+ onClick: ()=>{
1651
+ setAnswerMode(1);
1652
+ setProblem({
1653
+ question: historyMessageList[i - 1].message,
1654
+ user: problem.user
1655
+ });
1656
+ setHistoryMessageList((historyMessageList)=>{
1657
+ let newHistoryMessageList = historyMessageList.concat({
1658
+ id: -1,
1659
+ roomId: roomId,
1660
+ sender: "AI",
1661
+ recevier: mid,
1662
+ message: "请告诉我您要召唤的老师名字",
1663
+ createdAt: getDataTime(-1),
1664
+ findTeacher: true
1665
+ });
1666
+ return newHistoryMessageList;
1667
+ });
1668
+ setTimeout(()=>{
1669
+ scrollToBottom();
1670
+ }, 200);
1671
+ },
1672
+ children: "召唤老师回答"
1673
+ }),
1674
+ /*#__PURE__*/ _jsx("i", {
1675
+ className: "yinyong_quote1",
1676
+ onClick: ()=>{
1677
+ setCitationContent({
1678
+ content: item.message,
1679
+ id: item.id
1680
+ });
1681
+ resettingBottomHei();
1682
+ onEvent(serverName + serverUrl(), "click_智能问答_引用", "提交");
1683
+ console.log("引用222222");
1684
+ },
1685
+ children: /*#__PURE__*/ _jsx(CustomQuote, {})
1686
+ }),
1687
+ copyTextOBJ.length > 0 && copyTextOBJ.some((list)=>list == item.id) ? /*#__PURE__*/ _jsx("i", {
1688
+ className: `tongyong-xuanzhongdui`,
1689
+ children: /*#__PURE__*/ _jsx(CustomDuihao, {})
1690
+ }) : /*#__PURE__*/ _jsx("i", {
1691
+ className: "fuzhi21",
1692
+ onClick: ()=>{
1693
+ let bol = copyText(item.message);
1694
+ if (bol) {
1695
+ let obj = copyTextOBJ;
1696
+ obj = obj.filter((list)=>list != item.id);
1697
+ obj.push(item.id);
1698
+ setCopyTextObj(obj);
1699
+ }
1700
+ setTimeout(()=>{
1701
+ let obj = copyTextOBJ;
1702
+ obj = obj.filter((list)=>list != item.id);
1703
+ setCopyTextObj(obj);
1704
+ }, 3000);
1705
+ onEvent(serverName + serverUrl(), "click_智能问答_复制", "提交");
1706
+ },
1707
+ children: /*#__PURE__*/ _jsx(CustomCopy, {})
1708
+ }),
1709
+ /*#__PURE__*/ _jsx("span", {
1710
+ children: "|"
1711
+ }),
1712
+ /*#__PURE__*/ _jsx("i", {
1713
+ className: `Frame427319094 ${item.upvoted ? styles.active : ""}`,
1714
+ onClick: ()=>{
1715
+ likeMessage(item.id, item.upvoted);
1716
+ //老师的聊天窗口中不需要点赞和踩消息
1717
+ if (!isAiChatWindow) return;
1718
+ //只有最后一条回答,支持发送点赞或踩
1719
+ if (!item.upvoted && (historyMessageList.length == i + 1 || historyMessageList.length - 2 == i)) {
1720
+ console.log("判断是AI还是智能回答", item);
1721
+ if (!item.extraInfo && item.sender == "AI") {
1722
+ aiSendQuestions(1, {
1723
+ roomId: roomId,
1724
+ message: "你给出的答案我非常满意,赞!",
1725
+ quotedMessage: "",
1726
+ regenerate: false,
1727
+ generateUpvoteOrDownvoteMessage: true
1728
+ }, 1);
1729
+ } else {
1730
+ console.log("AI回答2255555");
1731
+ sendGreetingMessage(2);
1732
+ }
1733
+ }
1734
+ },
1735
+ children: /*#__PURE__*/ _jsx(CustomLike, {})
1736
+ }),
1737
+ /*#__PURE__*/ _jsx("i", {
1738
+ className: `Frame427319095 ${item.downvoted ? styles.active : ""}`,
1739
+ onClick: ()=>{
1740
+ disagreeMessage(item.id, item.downvoted);
1741
+ //老师的聊天窗口中不需要点赞和踩消息
1742
+ if (!isAiChatWindow) return;
1743
+ //只有最后一条回答,支持发送点赞或踩
1744
+ if (!item.downvoted && (historyMessageList.length == i + 1 || historyMessageList.length - 2 == i)) {
1745
+ if (!item.extraInfo && item.sender == "AI") {
1746
+ aiSendQuestions(1, {
1747
+ roomId: roomId,
1748
+ message: "你给出的答案很糟糕,我不满意,踩!",
1749
+ quotedMessage: "",
1750
+ regenerate: false,
1751
+ generateUpvoteOrDownvoteMessage: true
1752
+ }, 1);
1753
+ } else {
1754
+ sendGreetingMessage(3);
1755
+ }
1756
+ }
1757
+ },
1758
+ children: /*#__PURE__*/ _jsx(CustomDislike, {})
1759
+ })
1760
+ ]
1761
+ });
1762
+ };
1763
+ //渲染最后一条的操作按钮
1764
+ const renderLastOperateBtn = (item, isAiChatWindow, i)=>{
1765
+ {}
1766
+ //问候语及点赞下面不需要展示相关按钮
1767
+ let extraInfo = item.extraInfo;
1768
+ //JSON.parse(extraInfo)[0].key == 'questionId' 是联想问题
1769
+ if (extraInfo != undefined && JSON.parse(extraInfo).length > 0 && JSON.parse(extraInfo)[0].key == 'messageSource' || extraInfo != undefined && JSON.parse(extraInfo).length > 0 && JSON.parse(extraInfo)[0].key == 'isVoteMessage') {
1770
+ return '';
1771
+ }
1772
+ //1、是否显示停止生成按钮 finished 是否生产完成
1773
+ let showStopBtn = false;
1774
+ if (!finished && item.sender == 'AI' && item.extraInfo == null) {
1775
+ showStopBtn = true;
1776
+ }
1777
+ //2、是否展示重新生成按钮
1778
+ let regenerationBtn = false;
1779
+ if (finished && item.sender == 'AI' && item.extraInfo == null) {
1780
+ regenerationBtn = true;
1781
+ }
1782
+ //3、是否显示召唤老师回答按钮
1783
+ let findTeacherBtn = false;
1784
+ if (!showStopBtn && isAiChatWindow && (extraInfo != undefined && JSON.parse(extraInfo).length > 0 && JSON.parse(extraInfo)[0].key == 'questionId' || extraInfo == null)) {
1785
+ findTeacherBtn = true;
1786
+ }
1787
+ return /*#__PURE__*/ _jsxs("div", {
1788
+ className: `${styles.operate_modal_bottom}`,
1789
+ children: [
1790
+ /*#__PURE__*/ _jsxs("p", {
1791
+ className: styles.stop_generate,
1792
+ children: [
1793
+ showStopBtn && /*#__PURE__*/ _jsxs(_Fragment, {
1794
+ children: [
1795
+ /*#__PURE__*/ _jsx("span", {
1796
+ className: styles.icon,
1797
+ onClick: ()=>{
1798
+ try {
1799
+ if (ctrl && ctrl.current) {
1800
+ ctrl.current.abort();
1801
+ }
1802
+ } catch (error) {}
1803
+ clearTimeout(receiveMessageTimer.current);
1804
+ setHistoryMessageList((historyMessageList)=>{
1805
+ return historyMessageList.filter((item)=>item.id != "123456");
1806
+ });
1807
+ setFinished(true);
1808
+ onEvent(serverName + serverUrl(), "click_智能问答_停止生成", "提交");
1809
+ }
1810
+ }),
1811
+ /*#__PURE__*/ _jsx("i", {
1812
+ onClick: ()=>{
1813
+ // aiSendQuestions(3,{},1);
1814
+ try {
1815
+ if (ctrl && ctrl.current) {
1816
+ ctrl.current.abort();
1817
+ }
1818
+ } catch (error) {}
1819
+ clearTimeout(receiveMessageTimer.current);
1820
+ setHistoryMessageList((historyMessageList)=>{
1821
+ return historyMessageList.filter((item)=>item.id != "123456");
1822
+ });
1823
+ setFinished(true);
1824
+ onEvent(serverName + serverUrl(), "click_智能问答_停止生成", "提交");
1825
+ },
1826
+ children: "停止生成"
1827
+ })
1828
+ ]
1829
+ }),
1830
+ //在ai窗口并ai已经生成完答案
1831
+ findTeacherBtn && /*#__PURE__*/ _jsx("span", {
1832
+ className: styles.find_teacher,
1833
+ onClick: ()=>{
1834
+ setAnswerMode(1);
1835
+ setProblem({
1836
+ question: historyMessageList[i - 1].message,
1837
+ user: problem.user
1838
+ });
1839
+ setHistoryMessageList((historyMessageList)=>{
1840
+ let newHistoryMessageList = historyMessageList.concat({
1841
+ id: -1,
1842
+ roomId: roomId,
1843
+ sender: "AI",
1844
+ recevier: mid,
1845
+ message: "请告诉我您要召唤的老师名字",
1846
+ createdAt: getDataTime(-1),
1847
+ findTeacher: true
1848
+ });
1849
+ return newHistoryMessageList;
1850
+ });
1851
+ setTimeout(()=>{
1852
+ scrollToBottom();
1853
+ }, 200);
1854
+ },
1855
+ children: "召唤老师回答"
1856
+ })
1857
+ ]
1858
+ }),
1859
+ /*#__PURE__*/ _jsxs("p", {
1860
+ className: `${styles.operate}`,
1861
+ children: [
1862
+ regenerationBtn && /*#__PURE__*/ _jsx("i", {
1863
+ onClick: ()=>{
1864
+ setFinished(false);
1865
+ aiSendQuestions(2, {
1866
+ roomId: roomId,
1867
+ message: historyMessageList[i - 1].message,
1868
+ quotedMessage: citationContent.content || "",
1869
+ regenerate: true,
1870
+ generateUpvoteOrDownvoteMessage: false
1871
+ }, item.id);
1872
+ onEvent(serverName + serverUrl(), "click_智能问答_重新生成", "提交");
1873
+ },
1874
+ children: /*#__PURE__*/ _jsx(CustomReloading, {})
1875
+ }),
1876
+ /*#__PURE__*/ _jsx("i", {
1877
+ className: "yinyong_quote1",
1878
+ onClick: ()=>{
1879
+ setCitationContent({
1880
+ content: item.message,
1881
+ id: item.id
1882
+ });
1883
+ resettingBottomHei();
1884
+ onEvent(serverName + serverUrl(), "click_智能问答_引用", "提交");
1885
+ },
1886
+ children: /*#__PURE__*/ _jsx(CustomQuote, {})
1887
+ }),
1888
+ copyTextOBJ.length > 0 && copyTextOBJ.some((list)=>list == item.id) ? /*#__PURE__*/ _jsx("i", {
1889
+ className: `tongyong-xuanzhongdui`,
1890
+ children: /*#__PURE__*/ _jsx(CustomDuihao, {})
1891
+ }) : /*#__PURE__*/ _jsx("i", {
1892
+ className: "fuzhi21",
1893
+ onClick: ()=>{
1894
+ let bol = copyText(item.message);
1895
+ if (bol) {
1896
+ let obj = copyTextOBJ;
1897
+ obj = obj.filter((list)=>list != item.id);
1898
+ obj.push(item.id);
1899
+ setCopyTextObj(obj);
1900
+ }
1901
+ setTimeout(()=>{
1902
+ let obj = copyTextOBJ;
1903
+ obj = obj.filter((list)=>list != item.id);
1904
+ setCopyTextObj(obj);
1905
+ }, 3000);
1906
+ onEvent(serverName + serverUrl(), "click_智能问答_复制", "提交");
1907
+ },
1908
+ children: /*#__PURE__*/ _jsx(CustomCopy, {})
1909
+ }),
1910
+ /*#__PURE__*/ _jsx("span", {
1911
+ children: "|"
1912
+ }),
1913
+ /*#__PURE__*/ _jsx("i", {
1914
+ className: `Frame427319094 ${item.upvoted ? styles.active : ""}`,
1915
+ onClick: ()=>{
1916
+ likeMessage(item.id, item.upvoted);
1917
+ //老师的聊天窗口中不需要点赞和踩消息
1918
+ if (!isAiChatWindow) return;
1919
+ //只有最后一条回答,支持发送点赞或踩
1920
+ if (!item.upvoted && (historyMessageList.length == i + 1 || historyMessageList.length - 2 == i)) {
1921
+ console.log("判断是AI还是智能回答", item);
1922
+ if (!item.extraInfo && item.sender == "AI") {
1923
+ aiSendQuestions(1, {
1924
+ roomId: roomId,
1925
+ message: "你给出的答案我非常满意,赞!",
1926
+ quotedMessage: "",
1927
+ regenerate: false,
1928
+ generateUpvoteOrDownvoteMessage: true
1929
+ }, 1);
1930
+ } else {
1931
+ console.log("AI回答2255555");
1932
+ sendGreetingMessage(2);
1933
+ }
1934
+ }
1935
+ },
1936
+ children: /*#__PURE__*/ _jsx(CustomLike, {})
1937
+ }),
1938
+ /*#__PURE__*/ _jsx("i", {
1939
+ className: `Frame427319095 ${item.downvoted ? styles.active : ""}`,
1940
+ onClick: ()=>{
1941
+ disagreeMessage(item.id, item.downvoted);
1942
+ //老师的聊天窗口中不需要点赞和踩消息
1943
+ if (!isAiChatWindow) return;
1944
+ //只有最后一条回答,支持发送点赞或踩
1945
+ console.log(item, "dlfkvmdflkv");
1946
+ if (!item.downvoted && (historyMessageList.length == i + 1 || historyMessageList.length - 2 == i)) {
1947
+ if (!item.extraInfo && item.sender == "AI") {
1948
+ console.log("AI回答2222");
1949
+ //AI回答
1950
+ aiSendQuestions(1, {
1951
+ roomId: roomId,
1952
+ message: "你给出的答案很糟糕,我不满意,踩!",
1953
+ quotedMessage: "",
1954
+ regenerate: false,
1955
+ generateUpvoteOrDownvoteMessage: true
1956
+ }, 1);
1957
+ } else {
1958
+ sendGreetingMessage(3);
1959
+ }
1960
+ }
1961
+ },
1962
+ children: /*#__PURE__*/ _jsx(CustomDislike, {})
1963
+ })
1964
+ ]
1965
+ })
1966
+ ]
1967
+ });
1968
+ };
1969
+ //渲染底部按钮
1970
+ const renderBottomAnt = ()=>{
1971
+ let placeholder = "";
1972
+ let disabled = false;
1973
+ if (voiceRecordingStatus == 2) {
1974
+ placeholder = "录制中...";
1975
+ } else if (voiceRecordingStatus == 1) {
1976
+ placeholder = "正在语音识别文字,请稍后...";
1977
+ } else if (!finished) {
1978
+ placeholder = "答案生成中,请稍后再发送...";
1979
+ } else {
1980
+ placeholder = "请输入问题,按Enter发送,Shift+Enter换行";
1981
+ disabled = true;
1982
+ }
1983
+ return /*#__PURE__*/ _jsxs(_Fragment, {
1984
+ children: [
1985
+ /*#__PURE__*/ _jsxs("div", {
1986
+ className: styles.input_wrap,
1987
+ onChange: ()=>{
1988
+ resettingBottomHei();
1989
+ },
1990
+ children: [
1991
+ /*#__PURE__*/ _jsxs("div", {
1992
+ className: `${styles.input} ${userData.modules.some((item)=>item.short == "AIservice") ? "" : styles.no_AI}`,
1993
+ children: [
1994
+ /*#__PURE__*/ _jsx(TextArea, {
1995
+ placeholder: placeholder,
1996
+ autoSize: {
1997
+ minRows: 1,
1998
+ maxRows: 6
1999
+ },
2000
+ value: keyWord,
2001
+ onChange: (e)=>{
2002
+ setKeyWord(e.target.value);
2003
+ if (e.target.value == "") {
2004
+ setQuestionsList([]);
2005
+ setTeacherList([]);
2006
+ clearTimeout(timer.current);
2007
+ } else {
2008
+ clearTimeout(timer.current);
2009
+ timer.current = setTimeout(()=>{
2010
+ if (answerMode == 1) {
2011
+ getTeacherList(String(e.target.value));
2012
+ } else {
2013
+ if (roomList.length > 0 && roomList[0].roomId != roomId) return;
2014
+ getQuestiionsList(String(e.target.value), 2);
2015
+ }
2016
+ }, 1000);
2017
+ }
2018
+ },
2019
+ onPressEnter: (e)=>{
2020
+ // console.log('发送内容22222',props)
2021
+ // console.log(roomList,roomId,'发送内容22222wewewewewewewe');
2022
+ if (!e.shiftKey && !e.altKey && !e.ctrlKey && keyWord.trim() != "") {
2023
+ e.stopPropagation();
2024
+ e.preventDefault();
2025
+ clearTimeout(timer.current);
2026
+ setKeyWord('');
2027
+ setCitationContent({});
2028
+ //跟老师对话
2029
+ if (roomList.length > 0 && roomList[0].roomId != roomId) {
2030
+ sendToTeacher(2);
2031
+ } else {
2032
+ sendMessage();
2033
+ }
2034
+ setButtomHei(45);
2035
+ } else {
2036
+ console.log("回车事件");
2037
+ resettingBottomHei();
2038
+ }
2039
+ },
2040
+ onFocus: ()=>{
2041
+ onEvent(serverName + serverUrl(), "click_智能问答_输入框", "提交");
2042
+ },
2043
+ disabled: !disabled,
2044
+ maxLength: 1000
2045
+ }),
2046
+ citationContent.content != undefined && citationContent.content != "" ? /*#__PURE__*/ _jsxs("div", {
2047
+ className: styles.content_main,
2048
+ children: [
2049
+ /*#__PURE__*/ _jsx("div", {
2050
+ className: styles.content_con,
2051
+ children: /*#__PURE__*/ _jsx("p", {
2052
+ children: citationContent.content
2053
+ })
2054
+ }),
2055
+ /*#__PURE__*/ _jsx("i", {
2056
+ className: styles.delete_quote,
2057
+ onClick: ()=>{
2058
+ setCitationContent({});
2059
+ resettingBottomHei();
2060
+ },
2061
+ children: /*#__PURE__*/ _jsx(CustomRoundClose, {})
2062
+ })
2063
+ ]
2064
+ }) : ""
2065
+ ]
2066
+ }),
2067
+ userData.modules.some((item)=>item.short == "AIservice") ? /*#__PURE__*/ _jsxs("p", {
2068
+ className: styles.voice,
2069
+ children: [
2070
+ voiceRecordingStatus == 1 || voiceRecordingStatus == 3 ? /*#__PURE__*/ _jsx("i", {
2071
+ className: `${!disabled ? styles.disabled : ''}`,
2072
+ onClick: ()=>{
2073
+ //开始录音
2074
+ if (!disabled) return;
2075
+ startRecord();
2076
+ setVoiceRecordingStatus(2);
2077
+ setKeyWord("");
2078
+ voiceCountdownTimer.current = setTimeout(()=>{
2079
+ stopRecord();
2080
+ setVoiceRecordingStatus(1);
2081
+ }, 120000);
2082
+ onEvent(serverName + serverUrl(), "click_智能问答_ 麦克风", "提交");
2083
+ },
2084
+ children: /*#__PURE__*/ _jsx(CustomSoundRecording, {})
2085
+ }) : "",
2086
+ voiceRecordingStatus == 2 ? /*#__PURE__*/ _jsx("img", {
2087
+ // src={Voice_btn}
2088
+ src: "/new_yun/images/aiService/voice_btn.gif",
2089
+ className: styles.voice_btn,
2090
+ onClick: ()=>{
2091
+ //结束录音
2092
+ // console.log(mediaRecorder,'3333333');
2093
+ // mediaRecorder.stop();
2094
+ stopRecord();
2095
+ setVoiceRecordingStatus(1);
2096
+ clearTimeout(voiceCountdownTimer.current);
2097
+ }
2098
+ }) : ""
2099
+ ]
2100
+ }) : ""
2101
+ ]
2102
+ }),
2103
+ /*#__PURE__*/ _jsx("p", {
2104
+ className: `${styles.sending}`,
2105
+ children: /*#__PURE__*/ _jsx("i", {
2106
+ className: `${!disabled || keyWord.trim() == '' ? styles.disabled : ''}`,
2107
+ onClick: ()=>{
2108
+ if (!disabled) return;
2109
+ setCitationContent({});
2110
+ setButtomHei(45);
2111
+ if (keyWord.trim() != "") {
2112
+ setKeyWord('');
2113
+ //跟老师对话
2114
+ if (roomList.length > 0 && roomList[0].roomId != roomId) {
2115
+ sendToTeacher(2);
2116
+ } else {
2117
+ sendMessage();
2118
+ }
2119
+ onEvent(serverName + serverUrl(), "click_智能问答_ Enter", "提交");
2120
+ }
2121
+ },
2122
+ children: /*#__PURE__*/ _jsx(CustomSending, {})
2123
+ })
2124
+ })
2125
+ ]
2126
+ });
2127
+ };
2128
+ //渲染联想问题及联想的老师名称
2129
+ const renderAssociationProblem = ()=>{
2130
+ if (answerMode == 1) {
2131
+ return /*#__PURE__*/ _jsx("div", {
2132
+ className: `${styles.issues_list} ${styles.issues_list_teacherList}`,
2133
+ style: {
2134
+ bottom: `${buttomHei + 6}px`
2135
+ },
2136
+ children: teacherList.map((item)=>{
2137
+ let span = item.name.replaceAll(keyWord, ()=>{
2138
+ return `<span class=${styles.sign}>${keyWord}</span>`;
2139
+ });
2140
+ return /*#__PURE__*/ _jsx("p", {
2141
+ className: styles.item,
2142
+ children: /*#__PURE__*/ _jsx("span", {
2143
+ onClick: ()=>{
2144
+ setTeacherList([]);
2145
+ //提问的问题
2146
+ setProblem({
2147
+ question: problem.question,
2148
+ user: item.uid
2149
+ });
2150
+ setKeyWord("");
2151
+ //setUpdateRecords(true);
2152
+ setAnswerMode(-1);
2153
+ setChatWith(item);
2154
+ let list = roomList.filter((e)=>e.sender == item.uid);
2155
+ if (list.length > 0) {
2156
+ setRoomId(list[0].roomId); //已有聊天室
2157
+ } else {
2158
+ createRooms(item.uid).then((res)=>{
2159
+ childRef.current.roomsListTimer();
2160
+ let id = res.data.id;
2161
+ setRoomId(id); //新的聊天室id
2162
+ });
2163
+ }
2164
+ },
2165
+ dangerouslySetInnerHTML: {
2166
+ __html: span
2167
+ }
2168
+ })
2169
+ });
2170
+ })
2171
+ });
2172
+ } else {
2173
+ return /*#__PURE__*/ _jsx("div", {
2174
+ className: styles.issues_list,
2175
+ style: {
2176
+ bottom: `${buttomHei + 6}px`
2177
+ },
2178
+ children: questionsList.map((item)=>{
2179
+ let span = item.question.replaceAll(keyWord, ()=>{
2180
+ return `<span class=${styles.sign}>${keyWord}</span>`;
2181
+ });
2182
+ return /*#__PURE__*/ _jsx("p", {
2183
+ className: styles.item,
2184
+ children: /*#__PURE__*/ _jsx("span", {
2185
+ onClick: ()=>{
2186
+ sendMessage(item, 2);
2187
+ setKeyWord("");
2188
+ onEvent(serverName + serverUrl(), "click_智能问答_ 发送", "提交");
2189
+ },
2190
+ dangerouslySetInnerHTML: {
2191
+ __html: span
2192
+ }
2193
+ })
2194
+ });
2195
+ })
2196
+ });
2197
+ }
2198
+ };
2199
+ //加载指定数据,点击历史记录
2200
+ const loadSpecifiedData = (renewRoomId, page, id, receiver)=>{
2201
+ if (page != 1) {
2202
+ setPageNumHistory(page);
2203
+ }
2204
+ createRooms(receiver);
2205
+ if (childRef.current) {
2206
+ childRef.current.roomsListTimer();
2207
+ }
2208
+ setPageNum(page);
2209
+ setLastId(id); //用于定位
2210
+ //如果是当前聊天室
2211
+ if (renewRoomId == roomId) {
2212
+ getHistoryMessage(page, 1);
2213
+ } else {
2214
+ setRoomId(renewRoomId);
2215
+ }
2216
+ };
2217
+ return /*#__PURE__*/ _jsxs(_Fragment, {
2218
+ children: [
2219
+ /*#__PURE__*/ _jsxs(Drawer, {
2220
+ title: "智能回答",
2221
+ width: 560,
2222
+ onClose: ()=>{
2223
+ onCancel();
2224
+ onEvent(serverName + serverUrl(), "click_智能问答_收起侧边栏", "提交");
2225
+ },
2226
+ open: showType == 1 ? true : false,
2227
+ className: styles.ChatWindow_Drawer,
2228
+ mask: false,
2229
+ // maskClosable={false}
2230
+ rootClassName: styles.service_ChatWindow_Drawer,
2231
+ children: [
2232
+ showType == 1 && /*#__PURE__*/ _jsx("div", {
2233
+ style: {
2234
+ display: `${showContacts && roomId != "" ? "block" : "none"}`
2235
+ },
2236
+ children: /*#__PURE__*/ _jsx(ContactsList, {
2237
+ type: 1,
2238
+ roomId: roomId,
2239
+ userData: userData,
2240
+ http: http,
2241
+ urllocation: urllocation,
2242
+ onClose: ()=>{
2243
+ setShowContacts(false);
2244
+ },
2245
+ // roomIdAi={roomIdAi}
2246
+ switchChatRoom: switchChatRoom,
2247
+ saveContactsList: saveContactsList,
2248
+ ref: childRef
2249
+ })
2250
+ }),
2251
+ /*#__PURE__*/ _jsx("div", {
2252
+ className: styles.header_wrap,
2253
+ children: renderHeader()
2254
+ }),
2255
+ /*#__PURE__*/ _jsxs("div", {
2256
+ className: `${styles.Drawer_main}`,
2257
+ id: "chat_content",
2258
+ style: {
2259
+ maxHeight: `calc(100vh-${buttomHei + 48}px)`
2260
+ },
2261
+ children: [
2262
+ loading ? /*#__PURE__*/ _jsx("div", {
2263
+ className: styles.loading,
2264
+ children: /*#__PURE__*/ _jsx("img", {
2265
+ src: "/new_yun/images/loading_d.gif",
2266
+ alt: ""
2267
+ })
2268
+ }) : "",
2269
+ renderQuestion(),
2270
+ bottomLoading ? /*#__PURE__*/ _jsx("div", {
2271
+ className: styles.loading,
2272
+ children: /*#__PURE__*/ _jsx("img", {
2273
+ src: "/new_yun/images/loading_d.gif",
2274
+ alt: ""
2275
+ })
2276
+ }) : ""
2277
+ ]
2278
+ }),
2279
+ /*#__PURE__*/ _jsxs("div", {
2280
+ className: styles.Drawer_buttom_Issues_List,
2281
+ children: [
2282
+ renderAssociationProblem(),
2283
+ /*#__PURE__*/ _jsx("div", {
2284
+ className: styles.Drawer_buttom,
2285
+ id: "Drawer_buttom",
2286
+ children: renderBottomAnt()
2287
+ })
2288
+ ]
2289
+ }),
2290
+ showType == 1 && showHistory && /*#__PURE__*/ _jsx(HistoryFun, {
2291
+ type: 1,
2292
+ roomId: roomId,
2293
+ userData: userData,
2294
+ http: http,
2295
+ urllocation: urllocation,
2296
+ onClose: ()=>{
2297
+ setShowHistory(false);
2298
+ },
2299
+ loadSpecifiedData: loadSpecifiedData,
2300
+ roomList: roomList
2301
+ })
2302
+ ]
2303
+ }),
2304
+ /*#__PURE__*/ _jsxs(Modal, {
2305
+ title: "智能回答",
2306
+ open: showType == 2 ? true : false,
2307
+ onCancel: ()=>{
2308
+ onCancel();
2309
+ onEvent(serverName + serverUrl(), "click_智能问答_收起侧边栏", "提交");
2310
+ },
2311
+ centered: true,
2312
+ width: window.innerWidth - 252 > 1214 ? window.innerWidth - 252 : 1214,
2313
+ height: window.innerHeight - 160,
2314
+ wrapClassName: styles.ChatWindow_Modal,
2315
+ footer: false,
2316
+ maskClosable: false,
2317
+ closeIcon: null,
2318
+ children: [
2319
+ /*#__PURE__*/ _jsx("div", {
2320
+ className: styles.header_wrap,
2321
+ children: renderHeader()
2322
+ }),
2323
+ /*#__PURE__*/ _jsxs("div", {
2324
+ className: `${styles.Drawer_wrap_main}`,
2325
+ children: [
2326
+ /*#__PURE__*/ _jsxs("div", {
2327
+ className: `${styles.Drawer_main} ChatWindow_Modal_history_list`,
2328
+ id: "chat_content_modal",
2329
+ style: {
2330
+ maxHeight: `${window.innerHeight - 148 - buttomHei}px`
2331
+ },
2332
+ children: [
2333
+ /*#__PURE__*/ _jsx(ContactsList, {
2334
+ type: 2,
2335
+ roomId: roomId,
2336
+ userData: userData,
2337
+ http: http,
2338
+ urllocation: urllocation,
2339
+ onClose: ()=>{
2340
+ setShowContacts(false);
2341
+ },
2342
+ switchChatRoom: switchChatRoom,
2343
+ saveContactsList: saveContactsList,
2344
+ ref: childRef
2345
+ }),
2346
+ /*#__PURE__*/ _jsxs("div", {
2347
+ className: styles.chat_content,
2348
+ children: [
2349
+ loading ? /*#__PURE__*/ _jsx("div", {
2350
+ className: styles.loading,
2351
+ children: /*#__PURE__*/ _jsx("img", {
2352
+ src: "/new_yun/images/loading_d.gif",
2353
+ alt: ""
2354
+ })
2355
+ }) : "",
2356
+ renderQuestion()
2357
+ ]
2358
+ })
2359
+ ]
2360
+ }),
2361
+ /*#__PURE__*/ _jsxs("div", {
2362
+ className: styles.Drawer_buttom_Issues_List,
2363
+ children: [
2364
+ renderAssociationProblem(),
2365
+ /*#__PURE__*/ _jsx("div", {
2366
+ className: styles.Drawer_buttom,
2367
+ id: "Drawer_buttom_modal",
2368
+ children: renderBottomAnt()
2369
+ })
2370
+ ]
2371
+ }),
2372
+ showType == 2 && showHistory && /*#__PURE__*/ _jsx(HistoryFun, {
2373
+ type: 2,
2374
+ roomId: roomId,
2375
+ userData: userData,
2376
+ http: http,
2377
+ urllocation: urllocation,
2378
+ onClose: ()=>{
2379
+ setShowHistory(false);
2380
+ },
2381
+ loadSpecifiedData: loadSpecifiedData,
2382
+ roomList: roomList
2383
+ })
2384
+ ]
2385
+ })
2386
+ ]
2387
+ }),
2388
+ showType == 3 ? /*#__PURE__*/ _jsxs("div", {
2389
+ className: `${styles.ChatWindow_Drawer}`,
2390
+ id: "",
2391
+ children: [
2392
+ /*#__PURE__*/ _jsx("div", {
2393
+ className: `${styles.header_wrap} ${styles.header_wrap_newlabo}`,
2394
+ children: /*#__PURE__*/ _jsxs("div", {
2395
+ className: styles.top,
2396
+ children: [
2397
+ /*#__PURE__*/ _jsx("div", {
2398
+ className: styles.user,
2399
+ children: /*#__PURE__*/ _jsx("p", {
2400
+ children: roomList.filter((e)=>e.roomId == roomId).length > 0 && roomList.filter((e)=>e.roomId == roomId)[0].name != undefined ? roomList.filter((e)=>e.roomId == roomId)[0].name : '智能回答'
2401
+ })
2402
+ }),
2403
+ /*#__PURE__*/ _jsxs("div", {
2404
+ className: styles.operate,
2405
+ children: [
2406
+ /*#__PURE__*/ _jsx("i", {
2407
+ onClick: ()=>{
2408
+ setShowHistory(true);
2409
+ },
2410
+ children: /*#__PURE__*/ _jsx(CustomRecord, {})
2411
+ }),
2412
+ /*#__PURE__*/ _jsx("span", {
2413
+ className: styles.line
2414
+ }),
2415
+ /*#__PURE__*/ _jsx("i", {
2416
+ onClick: ()=>{
2417
+ onEvent(serverName + serverUrl(), "click_智能问答_全屏", "提交");
2418
+ setFirstLoad(false);
2419
+ setShowType(4);
2420
+ childRef.current.roomsListTimer();
2421
+ },
2422
+ children: /*#__PURE__*/ _jsx(CustomFullScreen, {})
2423
+ }),
2424
+ /*#__PURE__*/ _jsx("i", {
2425
+ className: "lianxiren21",
2426
+ onClick: ()=>{
2427
+ setShowContacts(true);
2428
+ },
2429
+ children: /*#__PURE__*/ _jsx(CustomContacts, {})
2430
+ })
2431
+ ]
2432
+ })
2433
+ ]
2434
+ })
2435
+ }),
2436
+ /*#__PURE__*/ _jsxs("div", {
2437
+ className: `${styles.Drawer_main} ${styles.Drawer_main_newlabo}`,
2438
+ id: "chat_content",
2439
+ style: {
2440
+ maxHeight: `${window.innerHeight - 110 - buttomHei}px)`
2441
+ },
2442
+ children: [
2443
+ loading ? /*#__PURE__*/ _jsx("div", {
2444
+ className: styles.loading,
2445
+ children: /*#__PURE__*/ _jsx("img", {
2446
+ src: "/new_yun/images/loading_d.gif",
2447
+ alt: ""
2448
+ })
2449
+ }) : "",
2450
+ renderQuestion()
2451
+ ]
2452
+ }),
2453
+ /*#__PURE__*/ _jsxs("div", {
2454
+ className: `${styles.Drawer_buttom_Issues_List} ${styles.Drawer_buttom_Issues_List_newlabo}`,
2455
+ children: [
2456
+ renderAssociationProblem(),
2457
+ /*#__PURE__*/ _jsx("div", {
2458
+ className: styles.Drawer_buttom,
2459
+ id: "Drawer_buttom",
2460
+ children: renderBottomAnt()
2461
+ })
2462
+ ]
2463
+ }),
2464
+ showType == 3 && showHistory && /*#__PURE__*/ _jsx(HistoryFun, {
2465
+ type: 3,
2466
+ roomId: roomId,
2467
+ userData: userData,
2468
+ http: http,
2469
+ urllocation: urllocation,
2470
+ onClose: ()=>{
2471
+ setShowHistory(false);
2472
+ },
2473
+ loadSpecifiedData: loadSpecifiedData,
2474
+ roomList: roomList
2475
+ }),
2476
+ showType == 3 && /*#__PURE__*/ _jsx("div", {
2477
+ style: {
2478
+ display: `${showType == 3 && showContacts && roomId != "" ? "block" : "none"}`
2479
+ },
2480
+ children: /*#__PURE__*/ _jsx(ContactsList, {
2481
+ type: 3,
2482
+ roomId: roomId,
2483
+ userData: userData,
2484
+ http: http,
2485
+ urllocation: urllocation,
2486
+ onClose: ()=>{
2487
+ setShowContacts(false);
2488
+ },
2489
+ switchChatRoom: switchChatRoom,
2490
+ saveContactsList: saveContactsList,
2491
+ ref: childRef
2492
+ })
2493
+ })
2494
+ ]
2495
+ }) : '',
2496
+ showType == 4 && /*#__PURE__*/ _jsxs(_Fragment, {
2497
+ children: [
2498
+ /*#__PURE__*/ _jsxs(Modal, {
2499
+ title: "智能回答",
2500
+ open: true,
2501
+ onCancel: ()=>{
2502
+ onCancel();
2503
+ onEvent(serverName + serverUrl(), "click_智能问答_收起侧边栏", "提交");
2504
+ },
2505
+ centered: true,
2506
+ width: window.innerWidth - 252 > 1214 ? window.innerWidth - 252 : 1214,
2507
+ height: window.innerHeight - 160,
2508
+ wrapClassName: `${styles.ChatWindow_Modal}`,
2509
+ footer: false,
2510
+ maskClosable: false,
2511
+ closeIcon: null,
2512
+ children: [
2513
+ /*#__PURE__*/ _jsx("div", {
2514
+ className: styles.header_wrap,
2515
+ children: renderHeader()
2516
+ }),
2517
+ /*#__PURE__*/ _jsxs("div", {
2518
+ className: `${styles.Drawer_wrap_main}`,
2519
+ children: [
2520
+ /*#__PURE__*/ _jsxs("div", {
2521
+ className: `${styles.Drawer_main} ${styles.Drawer_main_newlabo}`,
2522
+ id: "chat_content_modal",
2523
+ style: {
2524
+ maxHeight: `${window.innerHeight - 148 - buttomHei}px`
2525
+ },
2526
+ children: [
2527
+ /*#__PURE__*/ _jsx(ContactsList, {
2528
+ type: 4,
2529
+ roomId: roomId,
2530
+ userData: userData,
2531
+ http: http,
2532
+ urllocation: urllocation,
2533
+ onClose: ()=>{
2534
+ setShowContacts(false);
2535
+ },
2536
+ switchChatRoom: switchChatRoom,
2537
+ saveContactsList: saveContactsList,
2538
+ ref: childRef
2539
+ }),
2540
+ /*#__PURE__*/ _jsxs("div", {
2541
+ className: styles.chat_content,
2542
+ children: [
2543
+ loading ? /*#__PURE__*/ _jsx("div", {
2544
+ className: styles.loading,
2545
+ children: /*#__PURE__*/ _jsx("img", {
2546
+ src: "/new_yun/images/loading_d.gif",
2547
+ alt: ""
2548
+ })
2549
+ }) : "",
2550
+ renderQuestion()
2551
+ ]
2552
+ })
2553
+ ]
2554
+ }),
2555
+ /*#__PURE__*/ _jsxs("div", {
2556
+ className: styles.Drawer_buttom_Issues_List,
2557
+ children: [
2558
+ renderAssociationProblem(),
2559
+ /*#__PURE__*/ _jsx("div", {
2560
+ className: styles.Drawer_buttom,
2561
+ id: "Drawer_buttom_modal",
2562
+ children: renderBottomAnt()
2563
+ })
2564
+ ]
2565
+ }),
2566
+ showHistory && /*#__PURE__*/ _jsx(HistoryFun, {
2567
+ type: 2,
2568
+ roomId: roomId,
2569
+ userData: userData,
2570
+ http: http,
2571
+ urllocation: urllocation,
2572
+ onClose: ()=>{
2573
+ setShowHistory(false);
2574
+ },
2575
+ loadSpecifiedData: loadSpecifiedData,
2576
+ roomList: roomList
2577
+ })
2578
+ ]
2579
+ })
2580
+ ]
2581
+ }),
2582
+ /*#__PURE__*/ _jsxs("div", {
2583
+ className: `${styles.ChatWindow_Drawer}`,
2584
+ id: "",
2585
+ children: [
2586
+ /*#__PURE__*/ _jsx("div", {
2587
+ className: `${styles.header_wrap} ${styles.header_wrap_newlabo}`,
2588
+ children: /*#__PURE__*/ _jsxs("div", {
2589
+ className: styles.top,
2590
+ children: [
2591
+ /*#__PURE__*/ _jsx("div", {
2592
+ className: styles.user,
2593
+ children: /*#__PURE__*/ _jsx("p", {
2594
+ children: roomList.filter((e)=>e.roomId == roomId).length > 0 && !roomList.filter((e)=>e.roomId == roomId)[0].name ? roomList.filter((e)=>e.roomId == roomId)[0].name : '智能回答'
2595
+ })
2596
+ }),
2597
+ /*#__PURE__*/ _jsxs("div", {
2598
+ className: styles.operate,
2599
+ children: [
2600
+ /*#__PURE__*/ _jsx("i", {
2601
+ onClick: ()=>{
2602
+ setShowHistory(true);
2603
+ },
2604
+ children: /*#__PURE__*/ _jsx(CustomRecord, {})
2605
+ }),
2606
+ /*#__PURE__*/ _jsx("span", {
2607
+ className: styles.line
2608
+ }),
2609
+ /*#__PURE__*/ _jsx("i", {
2610
+ onClick: ()=>{
2611
+ onEvent(serverName + serverUrl(), "click_智能问答_全屏", "提交");
2612
+ setShowType(4);
2613
+ childRef.current.roomsListTimer();
2614
+ },
2615
+ children: /*#__PURE__*/ _jsx(CustomFullScreen, {})
2616
+ }),
2617
+ /*#__PURE__*/ _jsx("i", {
2618
+ className: "lianxiren21",
2619
+ onClick: ()=>{
2620
+ setShowContacts(true);
2621
+ },
2622
+ children: /*#__PURE__*/ _jsx(CustomContacts, {})
2623
+ })
2624
+ ]
2625
+ })
2626
+ ]
2627
+ })
2628
+ }),
2629
+ /*#__PURE__*/ _jsxs("div", {
2630
+ className: `${styles.Drawer_main} ${styles.Drawer_main_newlabo} ${styles.Drawer_main_newlabo_no_pic}`,
2631
+ id: "",
2632
+ style: {
2633
+ maxHeight: `${window.innerHeight - 100 - buttomHei}px)`
2634
+ },
2635
+ children: [
2636
+ loading ? /*#__PURE__*/ _jsx("div", {
2637
+ className: styles.loading,
2638
+ children: /*#__PURE__*/ _jsx("img", {
2639
+ src: "/new_yun/images/loading_d.gif",
2640
+ alt: ""
2641
+ })
2642
+ }) : "",
2643
+ renderQuestion()
2644
+ ]
2645
+ }),
2646
+ /*#__PURE__*/ _jsxs("div", {
2647
+ className: `${styles.Drawer_buttom_Issues_List} ${styles.Drawer_buttom_Issues_List_newlabo}`,
2648
+ children: [
2649
+ renderAssociationProblem(),
2650
+ /*#__PURE__*/ _jsx("div", {
2651
+ className: styles.Drawer_buttom,
2652
+ id: "Drawer_buttom",
2653
+ children: renderBottomAnt()
2654
+ })
2655
+ ]
2656
+ }),
2657
+ /*#__PURE__*/ _jsx("div", {
2658
+ style: {
2659
+ display: `${showContacts && roomId != "" ? "block" : "none"}`
2660
+ },
2661
+ children: /*#__PURE__*/ _jsx(ContactsList, {
2662
+ type: 3,
2663
+ roomId: roomId,
2664
+ userData: userData,
2665
+ http: http,
2666
+ urllocation: urllocation,
2667
+ onClose: ()=>{
2668
+ setShowContacts(false);
2669
+ },
2670
+ switchChatRoom: switchChatRoom,
2671
+ saveContactsList: saveContactsList,
2672
+ ref: childRef
2673
+ })
2674
+ })
2675
+ ]
2676
+ })
2677
+ ]
2678
+ })
2679
+ ]
2680
+ });
2681
+ };
2682
+ window.appendDom = (root, props)=>{
2683
+ render(/*#__PURE__*/ _jsx(Provider.Component, {
2684
+ children: /*#__PURE__*/ _jsx(CustomerService, _object_spread({}, props))
2685
+ }), root);
2686
+ };
2687
+ export default CustomerService;