bhd-components 0.10.31 → 0.10.33
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/es2017/customerService/function.d.ts +2 -1
- package/es2017/customerService/function.js +11 -1
- package/es2017/customerService/index.js +295 -53
- package/es2017/customerService/index.module.less +116 -1
- package/es2017/customerService/index2.module.less +77 -2
- package/es2017/customerService/viewMemaid.d.ts +3 -0
- package/es2017/customerService/viewMemaid.js +57 -0
- package/es2017/typings.d.ts +1 -1
- package/esm/customerService/function.d.ts +2 -1
- package/esm/customerService/function.js +11 -1
- package/esm/customerService/index.js +306 -62
- package/esm/customerService/index.module.less +116 -1
- package/esm/customerService/index2.module.less +77 -2
- package/esm/customerService/viewMemaid.d.ts +3 -0
- package/esm/customerService/viewMemaid.js +75 -0
- package/esm/typings.d.ts +1 -1
- package/package.json +4 -2
- package/dist/index.esm.es5.development.css +0 -14245
- package/dist/index.esm.es5.development.js +0 -16026
- package/dist/index.esm.es5.production.css +0 -10
- package/dist/index.esm.es5.production.js +0 -1
- package/dist/vendor.esm.es5.development.css +0 -119
- package/dist/vendor.esm.es5.development.js +0 -182666
- package/dist/vendor.esm.es5.production.css +0 -11
- package/dist/vendor.esm.es5.production.js +0 -493
|
@@ -21,4 +21,5 @@ declare const delegate: (element: any, eventType: string, selector: string, call
|
|
|
21
21
|
declare const getBase64Image: (src: any) => Promise<unknown>;
|
|
22
22
|
declare const formatDate: (dateStr: any) => any;
|
|
23
23
|
declare const urlToBase64: (url: string) => Promise<unknown>;
|
|
24
|
-
|
|
24
|
+
declare const toHashString: (str: string) => string;
|
|
25
|
+
export { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, getBase64Image, formatDate, urlToBase64, toHashString };
|
|
@@ -181,4 +181,14 @@ const urlToBase64 = (url)=>{
|
|
|
181
181
|
};
|
|
182
182
|
});
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
const toHashString = (str)=>{
|
|
185
|
+
let result = 0;
|
|
186
|
+
const length = str.length;
|
|
187
|
+
for(let i = 0; i < length; i++){
|
|
188
|
+
result = (result << 5) - result + str.charCodeAt(i);
|
|
189
|
+
result |= 0; // 转换为32位整数
|
|
190
|
+
}
|
|
191
|
+
// 转换为正数并格式化为8位十六进制
|
|
192
|
+
return (result >>> 0).toString(16).padStart(8, '0');
|
|
193
|
+
};
|
|
194
|
+
export { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, getBase64Image, formatDate, urlToBase64, toHashString };
|
|
@@ -24,13 +24,15 @@ import { parseDate } from "../utils/Date";
|
|
|
24
24
|
import { Remarkable } from "remarkable";
|
|
25
25
|
import hljs from "highlight.js";
|
|
26
26
|
import "highlight.js/styles/github.css";
|
|
27
|
+
import mermaid from "mermaid";
|
|
28
|
+
import ViewMemaid from "./viewMemaid";
|
|
27
29
|
import { render } from "react-dom";
|
|
28
30
|
import Provider from "../provider";
|
|
29
31
|
const { TextArea } = Input;
|
|
30
32
|
// import './html2canvas.test.js';
|
|
31
33
|
import knowledge_icon from "./images/knowledge_icon.png";
|
|
32
34
|
// import { useMediaRecorder } from "./useMediaRecorder"; //录音使用文件
|
|
33
|
-
import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64 } from "./function"; //一些方法
|
|
35
|
+
import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64, toHashString } from "./function"; //一些方法
|
|
34
36
|
// import html2canvas from "html2canvas";
|
|
35
37
|
// const screenShot = require('./screenShotPlugin.esm')
|
|
36
38
|
import ScreenShot from "./js-screen-shot/main";
|
|
@@ -53,6 +55,15 @@ function escapeHtml(str) {
|
|
|
53
55
|
}
|
|
54
56
|
return str;
|
|
55
57
|
}
|
|
58
|
+
mermaid.initialize({
|
|
59
|
+
startOnLoad: false,
|
|
60
|
+
theme: 'default',
|
|
61
|
+
securityLevel: 'loose',
|
|
62
|
+
flowchart: {
|
|
63
|
+
htmlLabels: true,
|
|
64
|
+
curve: 'basis'
|
|
65
|
+
}
|
|
66
|
+
});
|
|
56
67
|
const CustomerService = (props)=>{
|
|
57
68
|
let { userData, http, urllocation, onCancel, serverName, fetchEventSource, initShowType, onEvent, stepIds, stepId, screenshotAreaId, config } = props;
|
|
58
69
|
// const { bese64String, startRecord, stopRecord } = useMediaRecorder(); //语音转文字
|
|
@@ -117,9 +128,17 @@ const CustomerService = (props)=>{
|
|
|
117
128
|
const [firstItemIndex, setFirstItemIndex] = useState(0);
|
|
118
129
|
const [historyMessageListVirtuosoHeight, setHistoryMessageListVirtuosoHeight] = useState(null);
|
|
119
130
|
const msgStreamingCountRef = useRef(0);
|
|
131
|
+
const isWheelRef = useRef(false);
|
|
132
|
+
const getLisyFlagRef = useRef(0);
|
|
133
|
+
const [showMemaid, setShowMemaid] = useState(false); //是否显示mermaid弹窗
|
|
134
|
+
const [memaidContent, setMemaidContent] = useState(""); //mermaid内容
|
|
120
135
|
const remarkable = new Remarkable({
|
|
121
136
|
html: true,
|
|
122
137
|
highlight: function(str, lang) {
|
|
138
|
+
// 特殊处理 mermaid 代码块
|
|
139
|
+
if (lang === 'mermaid') {
|
|
140
|
+
return str; // 不高亮 mermaid 代码
|
|
141
|
+
}
|
|
123
142
|
if (lang && hljs.getLanguage(lang)) {
|
|
124
143
|
try {
|
|
125
144
|
return hljs.highlight(lang, str).value;
|
|
@@ -131,6 +150,18 @@ const CustomerService = (props)=>{
|
|
|
131
150
|
return ""; // use external default escaping
|
|
132
151
|
}
|
|
133
152
|
});
|
|
153
|
+
// 添加自定义规则来处理 mermaid 代码块
|
|
154
|
+
remarkable.renderer.rules.fence_custom = {
|
|
155
|
+
mermaid: function(tokens, idx) {
|
|
156
|
+
const token = tokens[idx];
|
|
157
|
+
const id = 'mermaid_' + toHashString(token.content);
|
|
158
|
+
return `<span class="${styles.maskZoomBox}"><pre class="${styles.mermaid}" id="${id}">${token.content}</pre><span class="${styles.zoomBox}" onclick="openViewMemaid('${id}')"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>`;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
remarkable.renderer.rules.image = (tokens, idx)=>{
|
|
162
|
+
const token = tokens[idx];
|
|
163
|
+
return `<span class="${styles.maskZoomBox}"><img src="${token.src}" alt="${token.alt}" title="${token.title}"/><span class="${styles.zoomBox}" onclick="openViewBase64('${token.src}')"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>`;
|
|
164
|
+
};
|
|
134
165
|
const remarkReplaceKey = (message, keyWordProblem)=>{
|
|
135
166
|
let newRemarkable = new Remarkable({
|
|
136
167
|
html: true,
|
|
@@ -150,6 +181,18 @@ const CustomerService = (props)=>{
|
|
|
150
181
|
let text = escapeHtml(tokens[idx].content);
|
|
151
182
|
return text.replace(keyWordProblem, `<span class="${styles.sign}">${keyWordProblem}</span>`);
|
|
152
183
|
};
|
|
184
|
+
// 添加自定义规则来处理 mermaid 代码块
|
|
185
|
+
newRemarkable.renderer.rules.fence_custom = {
|
|
186
|
+
mermaid: function(tokens, idx) {
|
|
187
|
+
const token = tokens[idx];
|
|
188
|
+
const id = 'mermaid_' + toHashString(token.content);
|
|
189
|
+
return `<span class="${styles.maskZoomBox}"><pre class="${styles.mermaid}" id="${id}">${token.content}</pre><span class="${styles.zoomBox}" onclick="openViewMemaid('${id}')"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>`;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
remarkable.renderer.rules.image = (tokens, idx)=>{
|
|
193
|
+
const token = tokens[idx];
|
|
194
|
+
return `<span class="${styles.maskZoomBox}"><img src="${token.src}" alt="${token.alt}" title="${token.title}"/><span class="${styles.zoomBox}"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>`;
|
|
195
|
+
};
|
|
153
196
|
return newRemarkable.render(message);
|
|
154
197
|
};
|
|
155
198
|
const [screenShotType, setScreenShotType] = useState(0); //1是 screenShotPlugin 2是html2canvas
|
|
@@ -302,7 +345,10 @@ const CustomerService = (props)=>{
|
|
|
302
345
|
}
|
|
303
346
|
if (showType != 1 && !firstLoad && pageCount > 0) {
|
|
304
347
|
setFirstLoad(true);
|
|
305
|
-
|
|
348
|
+
scrollToBottom();
|
|
349
|
+
setTimeout(()=>{
|
|
350
|
+
scrollToBottom();
|
|
351
|
+
}, 1000);
|
|
306
352
|
}
|
|
307
353
|
// function handleScroll() {
|
|
308
354
|
// const container = document.getElementById(
|
|
@@ -362,6 +408,46 @@ const CustomerService = (props)=>{
|
|
|
362
408
|
// if (content) {
|
|
363
409
|
// content.addEventListener("scroll", handleScroll);
|
|
364
410
|
// }
|
|
411
|
+
function openViewBase64(img) {
|
|
412
|
+
setViewBase64(img);
|
|
413
|
+
setVisible(true);
|
|
414
|
+
}
|
|
415
|
+
function openViewMemaid(id) {
|
|
416
|
+
var _document_querySelector, _svgDomClone;
|
|
417
|
+
console.log('openViewMemaid');
|
|
418
|
+
const svgDomClone = (_document_querySelector = document.querySelector(`#${id} svg`)) === null || _document_querySelector === void 0 ? void 0 : _document_querySelector.cloneNode(true);
|
|
419
|
+
if (!svgDomClone) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
svgDomClone.style.backgroundColor = '#fafafa';
|
|
423
|
+
svgDomClone.style.width = "auto";
|
|
424
|
+
svgDomClone.style.height = "auto";
|
|
425
|
+
const viewBox = svgDomClone.getAttribute('viewBox');
|
|
426
|
+
let [x, y, width, height] = viewBox ? viewBox.split(' ').map(Number) : [
|
|
427
|
+
0,
|
|
428
|
+
0,
|
|
429
|
+
0,
|
|
430
|
+
0
|
|
431
|
+
];
|
|
432
|
+
x -= 10;
|
|
433
|
+
y -= 10;
|
|
434
|
+
width += 20;
|
|
435
|
+
height += 20;
|
|
436
|
+
svgDomClone.setAttribute('viewBox', `${x} ${y} ${width} ${height}`);
|
|
437
|
+
const svgString = ((_svgDomClone = svgDomClone) === null || _svgDomClone === void 0 ? void 0 : _svgDomClone.outerHTML.toString()) || "";
|
|
438
|
+
const blob = new Blob([
|
|
439
|
+
svgString
|
|
440
|
+
], {
|
|
441
|
+
type: 'image/svg+xml;charset=utf-8'
|
|
442
|
+
});
|
|
443
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
444
|
+
setViewBase64(blobUrl);
|
|
445
|
+
setVisible(true);
|
|
446
|
+
// setMemaidContent(id);
|
|
447
|
+
// setShowMemaid(true);
|
|
448
|
+
}
|
|
449
|
+
window.openViewBase64 = openViewBase64;
|
|
450
|
+
window.openViewMemaid = openViewMemaid;
|
|
365
451
|
return ()=>{
|
|
366
452
|
// const content = document.getElementById(
|
|
367
453
|
// showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal"
|
|
@@ -371,6 +457,8 @@ const CustomerService = (props)=>{
|
|
|
371
457
|
// }
|
|
372
458
|
window.removeEventListener("resize", handlerHtml2canvas);
|
|
373
459
|
window.removeEventListener("resize", cancelScreenshot);
|
|
460
|
+
window.openViewBase64 = undefined;
|
|
461
|
+
window.openViewMemaid = undefined;
|
|
374
462
|
};
|
|
375
463
|
}, [
|
|
376
464
|
historyMessageList,
|
|
@@ -380,6 +468,13 @@ const CustomerService = (props)=>{
|
|
|
380
468
|
]);
|
|
381
469
|
useEffect(()=>{
|
|
382
470
|
historyMessageListRef.current = historyMessageList;
|
|
471
|
+
const timer = setTimeout(()=>{
|
|
472
|
+
mermaid.init({
|
|
473
|
+
querySelector: `.${styles.mermaid}:not([data-processed="true"])`,
|
|
474
|
+
suppressErrors: true
|
|
475
|
+
}, `.${styles.mermaid}:not([data-processed="true"])`);
|
|
476
|
+
clearTimeout(timer);
|
|
477
|
+
}, 500);
|
|
383
478
|
}, [
|
|
384
479
|
historyMessageList
|
|
385
480
|
]);
|
|
@@ -388,20 +483,12 @@ const CustomerService = (props)=>{
|
|
|
388
483
|
}, [
|
|
389
484
|
lastId
|
|
390
485
|
]);
|
|
391
|
-
useEffect(()=>{
|
|
392
|
-
console.log('isPositionState', isPositionState, isPosition.current);
|
|
393
|
-
}, [
|
|
394
|
-
isPositionState
|
|
395
|
-
]);
|
|
396
486
|
useEffect(()=>{
|
|
397
487
|
resettingBottomHei();
|
|
398
|
-
const timer = setTimeout(()=>{
|
|
399
|
-
scrollToBottom();
|
|
400
|
-
clearTimeout(timer);
|
|
401
|
-
}, 80);
|
|
402
488
|
let dom = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
|
|
403
489
|
if (dom) {
|
|
404
490
|
let hei = null;
|
|
491
|
+
console.log('buttomHei1', buttomHei);
|
|
405
492
|
if (showType == 1) {
|
|
406
493
|
hei = window.innerHeight - 60 - buttomHei;
|
|
407
494
|
dom.style.maxHeight = `${hei}px`;
|
|
@@ -414,10 +501,24 @@ const CustomerService = (props)=>{
|
|
|
414
501
|
}
|
|
415
502
|
setHistoryMessageListVirtuosoHeight(hei);
|
|
416
503
|
}
|
|
504
|
+
const timer = setTimeout(()=>{
|
|
505
|
+
console.log('showType', showType);
|
|
506
|
+
scrollToBottom();
|
|
507
|
+
clearTimeout(timer);
|
|
508
|
+
}, 100);
|
|
417
509
|
}, [
|
|
418
510
|
buttomHei,
|
|
419
511
|
showType
|
|
420
512
|
]);
|
|
513
|
+
useEffect(()=>{
|
|
514
|
+
const timer = setTimeout(()=>{
|
|
515
|
+
console.log('buttomHei2', historyMessageListRef.current.length);
|
|
516
|
+
scrollToBottom();
|
|
517
|
+
clearTimeout(timer);
|
|
518
|
+
}, 100);
|
|
519
|
+
}, [
|
|
520
|
+
historyMessageListVirtuosoHeight
|
|
521
|
+
]);
|
|
421
522
|
//创建聊天室并获取聊天室列表
|
|
422
523
|
useEffect(()=>{
|
|
423
524
|
createRooms("AI").then((res)=>{
|
|
@@ -436,7 +537,7 @@ const CustomerService = (props)=>{
|
|
|
436
537
|
}, []);
|
|
437
538
|
useEffect(()=>{
|
|
438
539
|
if (roomId != "") {
|
|
439
|
-
if (
|
|
540
|
+
if (lastIdRef.current == "") {
|
|
440
541
|
getHistoryMessage(pageNum, 2);
|
|
441
542
|
} else {
|
|
442
543
|
//查看历史记录,需要定位到当前记录
|
|
@@ -630,7 +731,10 @@ const CustomerService = (props)=>{
|
|
|
630
731
|
}));
|
|
631
732
|
return newHistoryMessageList;
|
|
632
733
|
});
|
|
633
|
-
|
|
734
|
+
const timer = setTimeout(()=>{
|
|
735
|
+
scrollToBottom();
|
|
736
|
+
clearTimeout(timer);
|
|
737
|
+
}, 100);
|
|
634
738
|
}
|
|
635
739
|
}
|
|
636
740
|
};
|
|
@@ -1349,6 +1453,13 @@ const CustomerService = (props)=>{
|
|
|
1349
1453
|
};
|
|
1350
1454
|
//获取历史消息 flag:1,历史记录点击定位,2,代表是上拉加载,3,存在新的消息-->老师回答等,4,下拉加载,滚动到底部时,主要用于查看历史记录
|
|
1351
1455
|
const getHistoryMessage = (pageNum, flag, id = "1", raw_data = [])=>{
|
|
1456
|
+
console.log('buttomHei4', {
|
|
1457
|
+
flag,
|
|
1458
|
+
pageNum,
|
|
1459
|
+
id,
|
|
1460
|
+
raw_data
|
|
1461
|
+
});
|
|
1462
|
+
getLisyFlagRef.current = flag;
|
|
1352
1463
|
clearTimeout(roomMessage.current);
|
|
1353
1464
|
// console.log(pageNum,flag,'dkfjvndfjvndfkvdf')
|
|
1354
1465
|
// flag == 1 时已经设置好了位置标记
|
|
@@ -1357,7 +1468,9 @@ const CustomerService = (props)=>{
|
|
|
1357
1468
|
last_id = historyMessageList[0].id;
|
|
1358
1469
|
}
|
|
1359
1470
|
if (flag != 1 && last_id != "") {
|
|
1471
|
+
lastIdRef.current = last_id;
|
|
1360
1472
|
setLastId(last_id);
|
|
1473
|
+
console.log('历史定位', last_id);
|
|
1361
1474
|
}
|
|
1362
1475
|
//取消搜索页码标记
|
|
1363
1476
|
if (flag == 4 && pageNum == 1) {
|
|
@@ -1381,13 +1494,32 @@ const CustomerService = (props)=>{
|
|
|
1381
1494
|
let total = res.data.total;
|
|
1382
1495
|
let maxPageSize = 30;
|
|
1383
1496
|
let dataList = res.data.messages.reverse();
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1497
|
+
// const mermaidChart = `\n\`\`\`mermaid\n%%\{init:\{'securityLevel':'loose','theme':'default','themeVariables': \{'useMaxWidth':false,'fontSize':'12px'\}\}\}%%
|
|
1498
|
+
// sequenceDiagram
|
|
1499
|
+
// actor 用户 as 用户
|
|
1500
|
+
// participant 前端 as Web/App前端
|
|
1501
|
+
// participant 后端 as 后端服务器
|
|
1502
|
+
// participant 数据库 as 数据库
|
|
1503
|
+
// 用户->>前端: 1. 输入用户名密码
|
|
1504
|
+
// 前端->>后端: 2. POST /api/login
|
|
1505
|
+
// 后端->>数据库: 3. 查询用户凭证
|
|
1506
|
+
// 数据库-->>后端: 4. 返回用户数据
|
|
1507
|
+
// alt 验证成功
|
|
1508
|
+
// 后端-->>前端: 5. 返回Token & 用户信息
|
|
1509
|
+
// 前端-->>用户: 6. 显示登录成功,跳转主页
|
|
1510
|
+
// else 验证失败
|
|
1511
|
+
// 后端-->>前端: 5. 返回错误信息
|
|
1512
|
+
// 前端-->>用户: 6. 提示“用户名或密码错误”
|
|
1513
|
+
// end\n\n\`\`\` `;
|
|
1514
|
+
// const imgTxt=`\n`
|
|
1515
|
+
// dataList[dataList.length - 1].message = mermaidChart+imgTxt;
|
|
1516
|
+
// //历史记录点击进来的,多加载一页,防止定位不准
|
|
1517
|
+
// if(flag == 1 && page > 1){
|
|
1518
|
+
// let markPage = page-1;
|
|
1519
|
+
// setPageNumHistory(markPage);
|
|
1520
|
+
// getHistoryMessage(page-1,5,'1',dataList);
|
|
1521
|
+
// return;
|
|
1522
|
+
// }
|
|
1391
1523
|
setPageCount(Math.ceil(total / maxPageSize));
|
|
1392
1524
|
setFirstItemIndex(total - maxPageSize * (page - 1));
|
|
1393
1525
|
let newHistoryMessageList = [];
|
|
@@ -1419,6 +1551,7 @@ const CustomerService = (props)=>{
|
|
|
1419
1551
|
totalNumber = newHistoryMessageList.length;
|
|
1420
1552
|
return newHistoryMessageList;
|
|
1421
1553
|
});
|
|
1554
|
+
historyMessageListRef.current = newHistoryMessageList;
|
|
1422
1555
|
// console.log(lastId,'lastIdlastId-------')
|
|
1423
1556
|
//如果在跟老师的聊天窗口,用于找到与老师的最新的聊天,并不在与老师对话的窗口中,并聊天窗口相同
|
|
1424
1557
|
try {
|
|
@@ -1465,6 +1598,9 @@ const CustomerService = (props)=>{
|
|
|
1465
1598
|
//&& pageNum == 1
|
|
1466
1599
|
getRoomidHistoryMessage(totalNumber, rid);
|
|
1467
1600
|
}
|
|
1601
|
+
setTimeout(()=>{
|
|
1602
|
+
getLisyFlagRef.current = 0;
|
|
1603
|
+
}, 100);
|
|
1468
1604
|
}).catch((res)=>{
|
|
1469
1605
|
setLoading(false);
|
|
1470
1606
|
});
|
|
@@ -1824,26 +1960,47 @@ const CustomerService = (props)=>{
|
|
|
1824
1960
|
if (!historyMessageListVirtuosoRef.current || !isPosition.current) {
|
|
1825
1961
|
return;
|
|
1826
1962
|
} else {
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1963
|
+
if (showType === 4) {
|
|
1964
|
+
const t = setTimeout(()=>{
|
|
1965
|
+
historyMessageListVirtuosoRef.current.scrollIntoView({
|
|
1966
|
+
index: "LAST",
|
|
1967
|
+
align: "end",
|
|
1968
|
+
behavior: "auto",
|
|
1969
|
+
offset: 144
|
|
1970
|
+
});
|
|
1971
|
+
clearTimeout(t);
|
|
1972
|
+
}, 100);
|
|
1973
|
+
} else {
|
|
1974
|
+
historyMessageListVirtuosoRef.current.scrollToIndex({
|
|
1975
|
+
index: "LAST",
|
|
1976
|
+
align: "end",
|
|
1977
|
+
behavior: "auto",
|
|
1978
|
+
offset: 58
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1832
1981
|
}
|
|
1833
1982
|
};
|
|
1834
1983
|
//滚动到指定位置
|
|
1835
1984
|
const scrollTo = (id)=>{
|
|
1985
|
+
console.log('scrollTo', {
|
|
1986
|
+
id
|
|
1987
|
+
});
|
|
1988
|
+
if (id == '123456_date') {
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1836
1991
|
const timer = setTimeout(()=>{
|
|
1837
1992
|
const index = historyMessageListRef.current.findIndex((x)=>x.id === id);
|
|
1838
|
-
|
|
1993
|
+
console.log("scrollTo", id, index, historyMessageListRef.current);
|
|
1839
1994
|
if (index > -1) {
|
|
1840
|
-
|
|
1995
|
+
var _historyMessageListVirtuosoRef_current;
|
|
1996
|
+
(_historyMessageListVirtuosoRef_current = historyMessageListVirtuosoRef.current) === null || _historyMessageListVirtuosoRef_current === void 0 ? void 0 : _historyMessageListVirtuosoRef_current.scrollToIndex({
|
|
1841
1997
|
index,
|
|
1842
|
-
align:
|
|
1998
|
+
align: 'start',
|
|
1843
1999
|
behavior: "auto"
|
|
1844
2000
|
});
|
|
1845
2001
|
}
|
|
1846
2002
|
setLoading(false);
|
|
2003
|
+
setBottomLoading(false);
|
|
1847
2004
|
clearTimeout(timer);
|
|
1848
2005
|
}, 10);
|
|
1849
2006
|
};
|
|
@@ -1857,7 +2014,10 @@ const CustomerService = (props)=>{
|
|
|
1857
2014
|
}
|
|
1858
2015
|
} else {
|
|
1859
2016
|
if (document.getElementById("Drawer_buttom_modal")) {
|
|
1860
|
-
|
|
2017
|
+
// newlabo 因为是会出现两个#BottomAssociationProblem_modal
|
|
2018
|
+
const len = document.querySelectorAll('#BottomAssociationProblem_modal').length;
|
|
2019
|
+
const dom = len > 1 ? document.querySelectorAll('#BottomAssociationProblem_modal')[1] : document.getElementById("BottomAssociationProblem_modal");
|
|
2020
|
+
let hei = document.getElementById("Drawer_buttom_modal").offsetHeight + dom.offsetHeight;
|
|
1861
2021
|
setButtomHei(hei);
|
|
1862
2022
|
}
|
|
1863
2023
|
}
|
|
@@ -2057,6 +2217,7 @@ const CustomerService = (props)=>{
|
|
|
2057
2217
|
const switchChatRoom = (id, type)=>{
|
|
2058
2218
|
if (type != "1") {
|
|
2059
2219
|
readMessage(id, urllocation, userData, http);
|
|
2220
|
+
lastIdRef.current = "";
|
|
2060
2221
|
setLastId("");
|
|
2061
2222
|
setPageNum(1);
|
|
2062
2223
|
setPageCount(0);
|
|
@@ -2093,6 +2254,9 @@ const CustomerService = (props)=>{
|
|
|
2093
2254
|
//渲染问答
|
|
2094
2255
|
const renderQuestion = ()=>{
|
|
2095
2256
|
function itemContent(index, item) {
|
|
2257
|
+
if (!item) {
|
|
2258
|
+
return null;
|
|
2259
|
+
}
|
|
2096
2260
|
var _historyMessageList_findIndex;
|
|
2097
2261
|
const i = (_historyMessageList_findIndex = historyMessageList.findIndex((x)=>x.id == item.id)) !== null && _historyMessageList_findIndex !== void 0 ? _historyMessageList_findIndex : index;
|
|
2098
2262
|
let timeObj = parseDate(item.createdAt);
|
|
@@ -2180,6 +2344,13 @@ const CustomerService = (props)=>{
|
|
|
2180
2344
|
</span><span class="copyCode">复制代码</span></p><pre`;
|
|
2181
2345
|
return text;
|
|
2182
2346
|
});
|
|
2347
|
+
// message = message.replaceAll(
|
|
2348
|
+
// new RegExp(`<img`, "ig"),
|
|
2349
|
+
// (i: any, index: any) => {
|
|
2350
|
+
// let text = `<div class='${styles.a}'><img`;
|
|
2351
|
+
// return text;
|
|
2352
|
+
// }
|
|
2353
|
+
// );
|
|
2183
2354
|
if (item.sender == mid) {
|
|
2184
2355
|
//只有引用和复制功能
|
|
2185
2356
|
li = /*#__PURE__*/ _jsxs(_Fragment, {
|
|
@@ -2374,10 +2545,8 @@ const CustomerService = (props)=>{
|
|
|
2374
2545
|
// onMouseEnter方法内:判断回答内容的气泡是否在可视区域内,动态判断点赞按钮显示的上下位置
|
|
2375
2546
|
const isSmall = showType == 1 || showType == 3;
|
|
2376
2547
|
const container = document.getElementById(isSmall ? "chat_content" : "chat_content_modal");
|
|
2377
|
-
console.log('onMouseEnter1', container);
|
|
2378
2548
|
if (container) {
|
|
2379
2549
|
const dom = container.querySelector(`[id="${item.id}"]`);
|
|
2380
|
-
console.log('onMouseEnter2', dom);
|
|
2381
2550
|
if (dom) {
|
|
2382
2551
|
// const con_h=document.getElementById('chat_content').clientHeight-24;//滚动区域的高度
|
|
2383
2552
|
const con_h = container.clientHeight - (isSmall ? 24 : 0); //滚动区域的高度;
|
|
@@ -2385,14 +2554,6 @@ const CustomerService = (props)=>{
|
|
|
2385
2554
|
const h = dom.clientHeight + (isSmall ? 24 : 0); //当前元素高度
|
|
2386
2555
|
const topDom = dom.getElementsByClassName(styles.operate_modal_showtop)[0];
|
|
2387
2556
|
const bottomDom = dom.getElementsByClassName(styles.operate_modal_showbottom)[0];
|
|
2388
|
-
console.log('onMouseEnter3', topDom, bottomDom);
|
|
2389
|
-
console.log('onMouseEnter4', {
|
|
2390
|
-
h,
|
|
2391
|
-
con_h,
|
|
2392
|
-
rectY,
|
|
2393
|
-
topDom,
|
|
2394
|
-
bottomDom
|
|
2395
|
-
});
|
|
2396
2557
|
if (topDom && bottomDom) {
|
|
2397
2558
|
if (rectY > 0) {
|
|
2398
2559
|
//显示上边
|
|
@@ -2576,6 +2737,18 @@ const CustomerService = (props)=>{
|
|
|
2576
2737
|
children: li
|
|
2577
2738
|
}, item.id);
|
|
2578
2739
|
}
|
|
2740
|
+
// return (
|
|
2741
|
+
// <pre className={`${styles.mermaid}`}>
|
|
2742
|
+
// {`graph TD
|
|
2743
|
+
// A[开始] --> B[步骤1]
|
|
2744
|
+
// B --> C{条件判断}
|
|
2745
|
+
// C -- 是 --> D[步骤2]
|
|
2746
|
+
// C -- 否 --> E[步骤3]
|
|
2747
|
+
// D --> F[结束]
|
|
2748
|
+
// E --> F
|
|
2749
|
+
// `}
|
|
2750
|
+
// </pre>
|
|
2751
|
+
// )
|
|
2579
2752
|
return /*#__PURE__*/ _jsx("ul", {
|
|
2580
2753
|
className: styles.message_con,
|
|
2581
2754
|
style: {
|
|
@@ -2587,47 +2760,103 @@ const CustomerService = (props)=>{
|
|
|
2587
2760
|
itemContent: itemContent,
|
|
2588
2761
|
totalCount: historyMessageList.length,
|
|
2589
2762
|
style: {
|
|
2590
|
-
height:
|
|
2763
|
+
height: '100%'
|
|
2591
2764
|
},
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2765
|
+
initialTopMostItemIndex: !finished && isPositionState ? undefined : {
|
|
2766
|
+
index: "LAST",
|
|
2767
|
+
align: "end",
|
|
2768
|
+
offset: showType === 3 ? 58 : showType === 4 ? 144 : 58
|
|
2769
|
+
},
|
|
2770
|
+
initialItemCount: 10,
|
|
2771
|
+
itemsRendered: ()=>{
|
|
2772
|
+
const t = setTimeout(()=>{
|
|
2773
|
+
mermaid.init({
|
|
2774
|
+
querySelector: `.${styles.mermaid}:not([data-processed="true"])`,
|
|
2775
|
+
suppressErrors: true
|
|
2776
|
+
}, `.${styles.mermaid}:not([data-processed="true"])`);
|
|
2777
|
+
clearTimeout(t);
|
|
2778
|
+
}, 100);
|
|
2779
|
+
},
|
|
2780
|
+
// startReached={(index) => {
|
|
2781
|
+
// console.log('atTopStateChange-startReached',index,lastIdRef.current)
|
|
2782
|
+
// if (pageCount > pageNum && pageCount > 0&& !loading&&lastIdRef.current=='') {
|
|
2783
|
+
// let number = pageNum + 1;
|
|
2784
|
+
// setPageNum((pageNum) => {
|
|
2785
|
+
// return pageNum + 1;
|
|
2786
|
+
// });
|
|
2787
|
+
// setLoading(true);
|
|
2788
|
+
// listTimer.current = setTimeout(() => {
|
|
2789
|
+
// getHistoryMessage(number, 2);
|
|
2790
|
+
// lastIdRef.current = "";
|
|
2791
|
+
// setLastId("");
|
|
2792
|
+
// }, 1000);
|
|
2793
|
+
// }
|
|
2794
|
+
// }}
|
|
2795
|
+
atTopStateChange: (atTop)=>{
|
|
2796
|
+
// 判断是否滚动到顶部
|
|
2797
|
+
console.log('StateChange-atTopStateChange', {
|
|
2798
|
+
pageCount,
|
|
2799
|
+
pageNum
|
|
2800
|
+
}, getLisyFlagRef.current);
|
|
2801
|
+
if (atTop && pageCount > pageNum && pageCount > 0 && getLisyFlagRef.current != 1 && getLisyFlagRef.current != 4) {
|
|
2595
2802
|
let number = pageNum + 1;
|
|
2596
2803
|
setPageNum((pageNum)=>{
|
|
2597
2804
|
return pageNum + 1;
|
|
2598
2805
|
});
|
|
2599
2806
|
setLoading(true);
|
|
2807
|
+
setBottomLoading(false);
|
|
2600
2808
|
listTimer.current = setTimeout(()=>{
|
|
2601
2809
|
getHistoryMessage(number, 2);
|
|
2602
|
-
},
|
|
2810
|
+
}, 100);
|
|
2603
2811
|
}
|
|
2604
2812
|
},
|
|
2605
|
-
endReached
|
|
2606
|
-
|
|
2813
|
+
// endReached={(index) => {
|
|
2814
|
+
// console.log('endReached',pageNumHistory,lastIdRef.current)
|
|
2815
|
+
// if (pageNumHistory > 1&&lastIdRef.current=='') {
|
|
2816
|
+
// let number = pageNumHistory - 1;
|
|
2817
|
+
// setPageNumHistory(number);
|
|
2818
|
+
// clearTimeout(listTimer.current);
|
|
2819
|
+
// listTimer.current = setTimeout(() => {
|
|
2820
|
+
// if (number > 0) {
|
|
2821
|
+
// setBottomLoading(true);
|
|
2822
|
+
// getHistoryMessage(number, 4);
|
|
2823
|
+
// lastIdRef.current = "";
|
|
2824
|
+
// setLastId("");
|
|
2825
|
+
// } else {
|
|
2826
|
+
// setPageNumHistory(0);
|
|
2827
|
+
// }
|
|
2828
|
+
// }, 1000);
|
|
2829
|
+
// }
|
|
2830
|
+
// }}
|
|
2831
|
+
atBottomStateChange: (atBottom)=>{
|
|
2832
|
+
console.log('StateChange-atBottomStateChange', pageNumHistory, getLisyFlagRef.current);
|
|
2833
|
+
if (atBottom && pageNumHistory > 1 && getLisyFlagRef.current != 1) {
|
|
2607
2834
|
let number = pageNumHistory - 1;
|
|
2608
2835
|
setPageNumHistory(number);
|
|
2609
2836
|
clearTimeout(listTimer.current);
|
|
2610
2837
|
listTimer.current = setTimeout(()=>{
|
|
2611
2838
|
if (number > 0) {
|
|
2612
2839
|
setBottomLoading(true);
|
|
2840
|
+
setLoading(false);
|
|
2613
2841
|
getHistoryMessage(number, 4);
|
|
2842
|
+
lastIdRef.current = "";
|
|
2614
2843
|
setLastId("");
|
|
2615
2844
|
} else {
|
|
2616
2845
|
setPageNumHistory(0);
|
|
2617
2846
|
}
|
|
2618
|
-
},
|
|
2847
|
+
}, 100);
|
|
2619
2848
|
}
|
|
2620
2849
|
},
|
|
2621
|
-
context
|
|
2622
|
-
loading
|
|
2623
|
-
},
|
|
2850
|
+
// context={{ loading }}
|
|
2624
2851
|
firstItemIndex: firstItemIndex,
|
|
2625
|
-
increaseViewportBy: 200,
|
|
2626
|
-
overscan: 10,
|
|
2627
2852
|
logLevel: 0,
|
|
2853
|
+
overscan: {
|
|
2854
|
+
main: 1000,
|
|
2855
|
+
reverse: 1000
|
|
2856
|
+
},
|
|
2628
2857
|
onScroll: (e)=>{
|
|
2629
2858
|
//生成答案过程中
|
|
2630
|
-
if (!finishedRef.current) {
|
|
2859
|
+
if (!finishedRef.current && isWheelRef.current) {
|
|
2631
2860
|
var _container, _container1, _container2;
|
|
2632
2861
|
const container = e.target;
|
|
2633
2862
|
var _container_scrollTop;
|
|
@@ -2646,6 +2875,7 @@ const CustomerService = (props)=>{
|
|
|
2646
2875
|
isPosition.current = true;
|
|
2647
2876
|
setIsPositionState(true);
|
|
2648
2877
|
}
|
|
2878
|
+
isWheelRef.current = false;
|
|
2649
2879
|
console.log("Scroll-onScroll", {
|
|
2650
2880
|
container,
|
|
2651
2881
|
scrollTop,
|
|
@@ -2654,6 +2884,11 @@ const CustomerService = (props)=>{
|
|
|
2654
2884
|
isPosition: isPosition.current
|
|
2655
2885
|
});
|
|
2656
2886
|
}
|
|
2887
|
+
},
|
|
2888
|
+
onWheel: ()=>{
|
|
2889
|
+
if (!finishedRef.current) {
|
|
2890
|
+
isWheelRef.current = true;
|
|
2891
|
+
}
|
|
2657
2892
|
}
|
|
2658
2893
|
})
|
|
2659
2894
|
});
|
|
@@ -3424,6 +3659,7 @@ const CustomerService = (props)=>{
|
|
|
3424
3659
|
if (page != 1) {
|
|
3425
3660
|
setPageNumHistory(page);
|
|
3426
3661
|
}
|
|
3662
|
+
lastIdRef.current = id;
|
|
3427
3663
|
setLastId(id); //用于定位
|
|
3428
3664
|
setPageNum(page);
|
|
3429
3665
|
//如果是当前聊天室
|
|
@@ -3996,6 +4232,12 @@ const CustomerService = (props)=>{
|
|
|
3996
4232
|
resolve(viewBase64);
|
|
3997
4233
|
});
|
|
3998
4234
|
}
|
|
4235
|
+
}),
|
|
4236
|
+
showMemaid && memaidContent && /*#__PURE__*/ _jsx(ViewMemaid, {
|
|
4237
|
+
visible: showMemaid,
|
|
4238
|
+
onCancel: ()=>setShowMemaid(false),
|
|
4239
|
+
className: "",
|
|
4240
|
+
content: memaidContent
|
|
3999
4241
|
})
|
|
4000
4242
|
]
|
|
4001
4243
|
});
|