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.
@@ -28,13 +28,15 @@ import { parseDate } from "../utils/Date";
28
28
  import { Remarkable } from "remarkable";
29
29
  import hljs from "highlight.js";
30
30
  import "highlight.js/styles/github.css";
31
+ import mermaid from "mermaid";
32
+ import ViewMemaid from "./viewMemaid";
31
33
  import { render } from "react-dom";
32
34
  import Provider from "../provider";
33
35
  var TextArea = Input.TextArea;
34
36
  // import './html2canvas.test.js';
35
37
  import knowledge_icon from "./images/knowledge_icon.png";
36
38
  // import { useMediaRecorder } from "./useMediaRecorder"; //录音使用文件
37
- import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64 } from "./function"; //一些方法
39
+ import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64, toHashString } from "./function"; //一些方法
38
40
  // import html2canvas from "html2canvas";
39
41
  // const screenShot = require('./screenShotPlugin.esm')
40
42
  import ScreenShot from "./js-screen-shot/main";
@@ -57,6 +59,15 @@ function escapeHtml(str) {
57
59
  }
58
60
  return str;
59
61
  }
62
+ mermaid.initialize({
63
+ startOnLoad: false,
64
+ theme: "default",
65
+ securityLevel: "loose",
66
+ flowchart: {
67
+ htmlLabels: true,
68
+ curve: "basis"
69
+ }
70
+ });
60
71
  var CustomerService = function(props) {
61
72
  var userData = props.userData, http = props.http, urllocation = props.urllocation, onCancel = props.onCancel, serverName = props.serverName, fetchEventSource = props.fetchEventSource, initShowType = props.initShowType, onEvent = props.onEvent, stepIds = props.stepIds, stepId = props.stepId, screenshotAreaId = props.screenshotAreaId, config = props.config;
62
73
  // const { bese64String, startRecord, stopRecord } = useMediaRecorder(); //语音转文字
@@ -121,9 +132,17 @@ var CustomerService = function(props) {
121
132
  var _useState34 = _sliced_to_array(useState(0), 2), firstItemIndex = _useState34[0], setFirstItemIndex = _useState34[1];
122
133
  var _useState35 = _sliced_to_array(useState(null), 2), historyMessageListVirtuosoHeight = _useState35[0], setHistoryMessageListVirtuosoHeight = _useState35[1];
123
134
  var msgStreamingCountRef = useRef(0);
135
+ var isWheelRef = useRef(false);
136
+ var getLisyFlagRef = useRef(0);
137
+ var _useState36 = _sliced_to_array(useState(false), 2), showMemaid = _useState36[0], setShowMemaid = _useState36[1]; //是否显示mermaid弹窗
138
+ var _useState37 = _sliced_to_array(useState(""), 2), memaidContent = _useState37[0], setMemaidContent = _useState37[1]; //mermaid内容
124
139
  var remarkable = new Remarkable({
125
140
  html: true,
126
141
  highlight: function highlight(str, lang) {
142
+ // 特殊处理 mermaid 代码块
143
+ if (lang === "mermaid") {
144
+ return str; // 不高亮 mermaid 代码
145
+ }
127
146
  if (lang && hljs.getLanguage(lang)) {
128
147
  try {
129
148
  return hljs.highlight(lang, str).value;
@@ -135,6 +154,18 @@ var CustomerService = function(props) {
135
154
  return ""; // use external default escaping
136
155
  }
137
156
  });
157
+ // 添加自定义规则来处理 mermaid 代码块
158
+ remarkable.renderer.rules.fence_custom = {
159
+ mermaid: function mermaid(tokens, idx) {
160
+ var token = tokens[idx];
161
+ var id = "mermaid_" + toHashString(token.content);
162
+ return '<span class="'.concat(styles.maskZoomBox, '"><pre class="').concat(styles.mermaid, '" id="').concat(id, '">').concat(token.content, '</pre><span class="').concat(styles.zoomBox, '" onclick="openViewMemaid(\'').concat(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>');
163
+ }
164
+ };
165
+ remarkable.renderer.rules.image = function(tokens, idx) {
166
+ var token = tokens[idx];
167
+ return '<span class="'.concat(styles.maskZoomBox, '"><img src="').concat(token.src, '" alt="').concat(token.alt, '" title="').concat(token.title, '"/><span class="').concat(styles.zoomBox, '" onclick="openViewBase64(\'').concat(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>');
168
+ };
138
169
  var remarkReplaceKey = function(message, keyWordProblem) {
139
170
  var newRemarkable = new Remarkable({
140
171
  html: true,
@@ -154,9 +185,21 @@ var CustomerService = function(props) {
154
185
  var text = escapeHtml(tokens[idx].content);
155
186
  return text.replace(keyWordProblem, '<span class="'.concat(styles.sign, '">').concat(keyWordProblem, "</span>"));
156
187
  };
188
+ // 添加自定义规则来处理 mermaid 代码块
189
+ newRemarkable.renderer.rules.fence_custom = {
190
+ mermaid: function mermaid(tokens, idx) {
191
+ var token = tokens[idx];
192
+ var id = "mermaid_" + toHashString(token.content);
193
+ return '<span class="'.concat(styles.maskZoomBox, '"><pre class="').concat(styles.mermaid, '" id="').concat(id, '">').concat(token.content, '</pre><span class="').concat(styles.zoomBox, '" onclick="openViewMemaid(\'').concat(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>');
194
+ }
195
+ };
196
+ remarkable.renderer.rules.image = function(tokens, idx) {
197
+ var token = tokens[idx];
198
+ return '<span class="'.concat(styles.maskZoomBox, '"><img src="').concat(token.src, '" alt="').concat(token.alt, '" title="').concat(token.title, '"/><span class="').concat(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>');
199
+ };
157
200
  return newRemarkable.render(message);
158
201
  };
159
- var _useState36 = _sliced_to_array(useState(0), 2), screenShotType = _useState36[0], setScreenShotType = _useState36[1]; //1是 screenShotPlugin 2是html2canvas
202
+ var _useState38 = _sliced_to_array(useState(0), 2), screenShotType = _useState38[0], setScreenShotType = _useState38[1]; //1是 screenShotPlugin 2是html2canvas
160
203
  var screenShotPlugin = useRef();
161
204
  useEffect(function() {
162
205
  // if(config && config.type == 'video'){
@@ -299,17 +342,7 @@ var CustomerService = function(props) {
299
342
  screenShotPlugin.current.destroyComponents();
300
343
  }
301
344
  };
302
- //|| showScreenshot
303
- if (showType == 5 || showScreenshot) {
304
- // console.log("bbbbbbbbbbbbbb");
305
- handlerHtml2canvas();
306
- // window.addEventListener('resize',handlerHtml2canvas)
307
- }
308
- if (showType != 1 && !firstLoad && pageCount > 0) {
309
- setFirstLoad(true);
310
- // scrollToBottom();
311
- }
312
- // function handleScroll() {
345
+ var openViewBase64 = // function handleScroll() {
313
346
  // const container = document.getElementById(
314
347
  // showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal"
315
348
  // );
@@ -367,6 +400,59 @@ var CustomerService = function(props) {
367
400
  // if (content) {
368
401
  // content.addEventListener("scroll", handleScroll);
369
402
  // }
403
+ function openViewBase64(img) {
404
+ setViewBase64(img);
405
+ setVisible(true);
406
+ };
407
+ var openViewMemaid = function openViewMemaid(id) {
408
+ var _document_querySelector, _svgDomClone;
409
+ console.log("openViewMemaid");
410
+ var svgDomClone = (_document_querySelector = document.querySelector("#".concat(id, " svg"))) === null || _document_querySelector === void 0 ? void 0 : _document_querySelector.cloneNode(true);
411
+ if (!svgDomClone) {
412
+ return;
413
+ }
414
+ svgDomClone.style.backgroundColor = "#fafafa";
415
+ svgDomClone.style.width = "auto";
416
+ svgDomClone.style.height = "auto";
417
+ var viewBox = svgDomClone.getAttribute("viewBox");
418
+ var _ref = _sliced_to_array(viewBox ? viewBox.split(" ").map(Number) : [
419
+ 0,
420
+ 0,
421
+ 0,
422
+ 0
423
+ ], 4), x = _ref[0], y = _ref[1], width = _ref[2], height = _ref[3];
424
+ x -= 10;
425
+ y -= 10;
426
+ width += 20;
427
+ height += 20;
428
+ svgDomClone.setAttribute("viewBox", "".concat(x, " ").concat(y, " ").concat(width, " ").concat(height));
429
+ var svgString = ((_svgDomClone = svgDomClone) === null || _svgDomClone === void 0 ? void 0 : _svgDomClone.outerHTML.toString()) || "";
430
+ var blob = new Blob([
431
+ svgString
432
+ ], {
433
+ type: "image/svg+xml;charset=utf-8"
434
+ });
435
+ var blobUrl = URL.createObjectURL(blob);
436
+ setViewBase64(blobUrl);
437
+ setVisible(true);
438
+ // setMemaidContent(id);
439
+ // setShowMemaid(true);
440
+ };
441
+ //|| showScreenshot
442
+ if (showType == 5 || showScreenshot) {
443
+ // console.log("bbbbbbbbbbbbbb");
444
+ handlerHtml2canvas();
445
+ // window.addEventListener('resize',handlerHtml2canvas)
446
+ }
447
+ if (showType != 1 && !firstLoad && pageCount > 0) {
448
+ setFirstLoad(true);
449
+ scrollToBottom();
450
+ setTimeout(function() {
451
+ scrollToBottom();
452
+ }, 1000);
453
+ }
454
+ window.openViewBase64 = openViewBase64;
455
+ window.openViewMemaid = openViewMemaid;
370
456
  return function() {
371
457
  // const content = document.getElementById(
372
458
  // showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal"
@@ -376,6 +462,8 @@ var CustomerService = function(props) {
376
462
  // }
377
463
  window.removeEventListener("resize", handlerHtml2canvas);
378
464
  window.removeEventListener("resize", cancelScreenshot);
465
+ window.openViewBase64 = undefined;
466
+ window.openViewMemaid = undefined;
379
467
  };
380
468
  }, [
381
469
  historyMessageList,
@@ -385,6 +473,13 @@ var CustomerService = function(props) {
385
473
  ]);
386
474
  useEffect(function() {
387
475
  historyMessageListRef.current = historyMessageList;
476
+ var timer = setTimeout(function() {
477
+ mermaid.init({
478
+ querySelector: ".".concat(styles.mermaid, ':not([data-processed="true"])'),
479
+ suppressErrors: true
480
+ }, ".".concat(styles.mermaid, ':not([data-processed="true"])'));
481
+ clearTimeout(timer);
482
+ }, 500);
388
483
  }, [
389
484
  historyMessageList
390
485
  ]);
@@ -393,20 +488,12 @@ var CustomerService = function(props) {
393
488
  }, [
394
489
  lastId
395
490
  ]);
396
- useEffect(function() {
397
- console.log("isPositionState", isPositionState, isPosition.current);
398
- }, [
399
- isPositionState
400
- ]);
401
491
  useEffect(function() {
402
492
  resettingBottomHei();
403
- var timer = setTimeout(function() {
404
- scrollToBottom();
405
- clearTimeout(timer);
406
- }, 80);
407
493
  var dom = document.getElementById(showType == 1 || showType == 3 ? "chat_content" : "chat_content_modal");
408
494
  if (dom) {
409
495
  var hei = null;
496
+ console.log("buttomHei1", buttomHei);
410
497
  if (showType == 1) {
411
498
  hei = window.innerHeight - 60 - buttomHei;
412
499
  dom.style.maxHeight = "".concat(hei, "px");
@@ -419,10 +506,24 @@ var CustomerService = function(props) {
419
506
  }
420
507
  setHistoryMessageListVirtuosoHeight(hei);
421
508
  }
509
+ var timer = setTimeout(function() {
510
+ console.log("showType", showType);
511
+ scrollToBottom();
512
+ clearTimeout(timer);
513
+ }, 100);
422
514
  }, [
423
515
  buttomHei,
424
516
  showType
425
517
  ]);
518
+ useEffect(function() {
519
+ var timer = setTimeout(function() {
520
+ console.log("buttomHei2", historyMessageListRef.current.length);
521
+ scrollToBottom();
522
+ clearTimeout(timer);
523
+ }, 100);
524
+ }, [
525
+ historyMessageListVirtuosoHeight
526
+ ]);
426
527
  //创建聊天室并获取聊天室列表
427
528
  useEffect(function() {
428
529
  createRooms("AI").then(function(res) {
@@ -441,7 +542,7 @@ var CustomerService = function(props) {
441
542
  }, []);
442
543
  useEffect(function() {
443
544
  if (roomId != "") {
444
- if (lastId == "") {
545
+ if (lastIdRef.current == "") {
445
546
  getHistoryMessage(pageNum, 2);
446
547
  } else {
447
548
  //查看历史记录,需要定位到当前记录
@@ -645,7 +746,10 @@ var CustomerService = function(props) {
645
746
  }));
646
747
  return newHistoryMessageList;
647
748
  });
648
- scrollToBottom();
749
+ var timer = setTimeout(function() {
750
+ scrollToBottom();
751
+ clearTimeout(timer);
752
+ }, 100);
649
753
  }
650
754
  }
651
755
  };
@@ -1442,6 +1546,13 @@ var CustomerService = function(props) {
1442
1546
  //获取历史消息 flag:1,历史记录点击定位,2,代表是上拉加载,3,存在新的消息-->老师回答等,4,下拉加载,滚动到底部时,主要用于查看历史记录
1443
1547
  var getHistoryMessage = function(pageNum, flag) {
1444
1548
  var id = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "1", raw_data = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : [];
1549
+ console.log("buttomHei4", {
1550
+ flag: flag,
1551
+ pageNum: pageNum,
1552
+ id: id,
1553
+ raw_data: raw_data
1554
+ });
1555
+ getLisyFlagRef.current = flag;
1445
1556
  clearTimeout(roomMessage.current);
1446
1557
  // console.log(pageNum,flag,'dkfjvndfjvndfkvdf')
1447
1558
  // flag == 1 时已经设置好了位置标记
@@ -1450,7 +1561,9 @@ var CustomerService = function(props) {
1450
1561
  last_id = historyMessageList[0].id;
1451
1562
  }
1452
1563
  if (flag != 1 && last_id != "") {
1564
+ lastIdRef.current = last_id;
1453
1565
  setLastId(last_id);
1566
+ console.log("历史定位", last_id);
1454
1567
  }
1455
1568
  //取消搜索页码标记
1456
1569
  if (flag == 4 && pageNum == 1) {
@@ -1474,13 +1587,32 @@ var CustomerService = function(props) {
1474
1587
  var total = res.data.total;
1475
1588
  var maxPageSize = 30;
1476
1589
  var dataList = res.data.messages.reverse();
1477
- //历史记录点击进来的,多加载一页,防止定位不准
1478
- if (flag == 1 && page > 1) {
1479
- var markPage = page - 1;
1480
- setPageNumHistory(markPage);
1481
- getHistoryMessage(page - 1, 5, "1", dataList);
1482
- return;
1483
- }
1590
+ // const mermaidChart = `\n\`\`\`mermaid\n%%\{init:\{'securityLevel':'loose','theme':'default','themeVariables': \{'useMaxWidth':false,'fontSize':'12px'\}\}\}%%
1591
+ // sequenceDiagram
1592
+ // actor 用户 as 用户
1593
+ // participant 前端 as Web/App前端
1594
+ // participant 后端 as 后端服务器
1595
+ // participant 数据库 as 数据库
1596
+ // 用户->>前端: 1. 输入用户名密码
1597
+ // 前端->>后端: 2. POST /api/login
1598
+ // 后端->>数据库: 3. 查询用户凭证
1599
+ // 数据库-->>后端: 4. 返回用户数据
1600
+ // alt 验证成功
1601
+ // 后端-->>前端: 5. 返回Token & 用户信息
1602
+ // 前端-->>用户: 6. 显示登录成功,跳转主页
1603
+ // else 验证失败
1604
+ // 后端-->>前端: 5. 返回错误信息
1605
+ // 前端-->>用户: 6. 提示“用户名或密码错误”
1606
+ // end\n\n\`\`\` `;
1607
+ // const imgTxt=`\n![公司图片](https://www.xiaoqiqiao.com/university/newImg/newHome/smartEdu/img1.png)`
1608
+ // dataList[dataList.length - 1].message = mermaidChart+imgTxt;
1609
+ // //历史记录点击进来的,多加载一页,防止定位不准
1610
+ // if(flag == 1 && page > 1){
1611
+ // let markPage = page-1;
1612
+ // setPageNumHistory(markPage);
1613
+ // getHistoryMessage(page-1,5,'1',dataList);
1614
+ // return;
1615
+ // }
1484
1616
  setPageCount(Math.ceil(total / maxPageSize));
1485
1617
  setFirstItemIndex(total - maxPageSize * (page - 1));
1486
1618
  var newHistoryMessageList = [];
@@ -1514,6 +1646,7 @@ var CustomerService = function(props) {
1514
1646
  totalNumber = newHistoryMessageList.length;
1515
1647
  return newHistoryMessageList;
1516
1648
  });
1649
+ historyMessageListRef.current = newHistoryMessageList;
1517
1650
  // console.log(lastId,'lastIdlastId-------')
1518
1651
  //如果在跟老师的聊天窗口,用于找到与老师的最新的聊天,并不在与老师对话的窗口中,并聊天窗口相同
1519
1652
  try {
@@ -1562,6 +1695,9 @@ var CustomerService = function(props) {
1562
1695
  //&& pageNum == 1
1563
1696
  getRoomidHistoryMessage(totalNumber, rid);
1564
1697
  }
1698
+ setTimeout(function() {
1699
+ getLisyFlagRef.current = 0;
1700
+ }, 100);
1565
1701
  }).catch(function(res) {
1566
1702
  setLoading(false);
1567
1703
  });
@@ -1932,28 +2068,49 @@ var CustomerService = function(props) {
1932
2068
  if (!historyMessageListVirtuosoRef.current || !isPosition.current) {
1933
2069
  return;
1934
2070
  } else {
1935
- historyMessageListVirtuosoRef.current.scrollToIndex({
1936
- index: "LAST",
1937
- align: "end",
1938
- behavior: "auto"
1939
- });
2071
+ if (showType === 4) {
2072
+ var t = setTimeout(function() {
2073
+ historyMessageListVirtuosoRef.current.scrollIntoView({
2074
+ index: "LAST",
2075
+ align: "end",
2076
+ behavior: "auto",
2077
+ offset: 144
2078
+ });
2079
+ clearTimeout(t);
2080
+ }, 100);
2081
+ } else {
2082
+ historyMessageListVirtuosoRef.current.scrollToIndex({
2083
+ index: "LAST",
2084
+ align: "end",
2085
+ behavior: "auto",
2086
+ offset: 58
2087
+ });
2088
+ }
1940
2089
  }
1941
2090
  };
1942
2091
  //滚动到指定位置
1943
2092
  var scrollTo = function(id) {
2093
+ console.log("scrollTo", {
2094
+ id: id
2095
+ });
2096
+ if (id == "123456_date") {
2097
+ return;
2098
+ }
1944
2099
  var timer = setTimeout(function() {
1945
2100
  var index = historyMessageListRef.current.findIndex(function(x) {
1946
2101
  return x.id === id;
1947
2102
  });
1948
- // console.log("scrollTo", id, index, historyMessageListRef.current);
2103
+ console.log("scrollTo", id, index, historyMessageListRef.current);
1949
2104
  if (index > -1) {
1950
- historyMessageListVirtuosoRef.current.scrollToIndex({
2105
+ var _historyMessageListVirtuosoRef_current;
2106
+ (_historyMessageListVirtuosoRef_current = historyMessageListVirtuosoRef.current) === null || _historyMessageListVirtuosoRef_current === void 0 ? void 0 : _historyMessageListVirtuosoRef_current.scrollToIndex({
1951
2107
  index: index,
1952
2108
  align: "start",
1953
2109
  behavior: "auto"
1954
2110
  });
1955
2111
  }
1956
2112
  setLoading(false);
2113
+ setBottomLoading(false);
1957
2114
  clearTimeout(timer);
1958
2115
  }, 10);
1959
2116
  };
@@ -1967,7 +2124,10 @@ var CustomerService = function(props) {
1967
2124
  }
1968
2125
  } else {
1969
2126
  if (document.getElementById("Drawer_buttom_modal")) {
1970
- var hei1 = document.getElementById("Drawer_buttom_modal").offsetHeight + document.getElementById("BottomAssociationProblem_modal").offsetHeight;
2127
+ // newlabo 因为是会出现两个#BottomAssociationProblem_modal
2128
+ var len = document.querySelectorAll("#BottomAssociationProblem_modal").length;
2129
+ var dom = len > 1 ? document.querySelectorAll("#BottomAssociationProblem_modal")[1] : document.getElementById("BottomAssociationProblem_modal");
2130
+ var hei1 = document.getElementById("Drawer_buttom_modal").offsetHeight + dom.offsetHeight;
1971
2131
  setButtomHei(hei1);
1972
2132
  }
1973
2133
  }
@@ -2171,6 +2331,7 @@ var CustomerService = function(props) {
2171
2331
  var switchChatRoom = function(id, type) {
2172
2332
  if (type != "1") {
2173
2333
  readMessage(id, urllocation, userData, http);
2334
+ lastIdRef.current = "";
2174
2335
  setLastId("");
2175
2336
  setPageNum(1);
2176
2337
  setPageCount(0);
@@ -2209,6 +2370,9 @@ var CustomerService = function(props) {
2209
2370
  //渲染问答
2210
2371
  var renderQuestion = function() {
2211
2372
  var itemContent = function itemContent(index, item) {
2373
+ if (!item) {
2374
+ return null;
2375
+ }
2212
2376
  var _historyMessageList_findIndex;
2213
2377
  var i = (_historyMessageList_findIndex = historyMessageList.findIndex(function(x) {
2214
2378
  return x.id == item.id;
@@ -2267,6 +2431,13 @@ var CustomerService = function(props) {
2267
2431
  var text = "<p class='".concat(styles.copyCode, " copyCodeFun' data-id=").concat(item.id, " data-position=").concat(position, ">\n <span class='").concat(styles.icon, ' copy\' >\n <svg\n width="1em"\n height="1em"\n viewBox="0 0 14 14"\n shape-rendering="geometricPrecision"\n fill="currentColor"\n xmlns="http://www.w3.org/2000/svg"\n >\n <g clip-path="url(#clip0_518_8403)">\n <path\n d="M6.16666 1.66666H13.1667C13.4761 1.66666 13.7728 1.78957 13.9916 2.00837C14.2104 2.22716 14.3333 2.5239 14.3333 2.83332V9.83332C14.3333 10.1427 14.2104 10.4395 13.9916 10.6583C13.7728 10.8771 13.4761 11 13.1667 11H6.16666C5.85724 11 5.5605 10.8771 5.34171 10.6583C5.12291 10.4395 5 10.1427 5 9.83332V2.83332C5 2.5239 5.12291 2.22716 5.34171 2.00837C5.5605 1.78957 5.85724 1.66666 6.16666 1.66666ZM6.16666 2.66666C6.12246 2.66666 6.08007 2.68422 6.04881 2.71547C6.01756 2.74673 6 2.78912 6 2.83332V9.83332C6 9.85521 6.00431 9.87688 6.01268 9.8971C6.02106 9.91732 6.03334 9.9357 6.04881 9.95117C6.06429 9.96665 6.08266 9.97893 6.10288 9.9873C6.1231 9.99568 6.14478 9.99999 6.16666 9.99999H13.1667C13.2109 9.99999 13.2533 9.98243 13.2845 9.95117C13.3158 9.91992 13.3333 9.87753 13.3333 9.83332V2.83332C13.3333 2.78912 13.3158 2.74673 13.2845 2.71547C13.2533 2.68422 13.2109 2.66666 13.1667 2.66666H6.16666ZM10 12C10 11.8674 10.0527 11.7402 10.1464 11.6464C10.2402 11.5527 10.3674 11.5 10.5 11.5C10.6326 11.5 10.7598 11.5527 10.8536 11.6464C10.9473 11.7402 11 11.8674 11 12V13.1667C11 13.4761 10.8771 13.7728 10.6583 13.9916C10.4395 14.2104 10.1427 14.3333 9.83333 14.3333H2.83333C2.52391 14.3333 2.22717 14.2104 2.00837 13.9916C1.78958 13.7728 1.66666 13.4761 1.66666 13.1667V6.16666C1.66666 5.85724 1.78958 5.56049 2.00837 5.3417C2.22717 5.12291 2.52391 4.99999 2.83333 4.99999H4C4.13261 4.99999 4.25978 5.05267 4.35355 5.14644C4.44732 5.2402 4.5 5.36738 4.5 5.49999C4.5 5.6326 4.44732 5.75978 4.35355 5.85354C4.25978 5.94731 4.13261 5.99999 4 5.99999H2.83333C2.78913 5.99999 2.74674 6.01755 2.71548 6.04881C2.68422 6.08006 2.66666 6.12245 2.66666 6.16666V13.1667C2.66666 13.2109 2.68422 13.2533 2.71548 13.2845C2.74674 13.3158 2.78913 13.3333 2.83333 13.3333H9.83333C9.87753 13.3333 9.91993 13.3158 9.95118 13.2845C9.98244 13.2533 10 13.2109 10 13.1667V12Z"\n />\n </g>\n <defs>\n <clipPath id="clip0_518_8403">\n <rect width="16" height="16" />\n </clipPath>\n </defs>\n </svg>\n </span>\n <span class=\'').concat(styles.icon, ' copy_success_flag\'>\n <svg\n width="1em"\n height="1em"\n shape-rendering="geometricPrecision"\n fill="currentColor"\n viewBox="0 0 12 7"\n xmlns="http://www.w3.org/2000/svg"\n >\n <path d="M11.2242 0.375687C11.4586 0.610002 11.4586 0.989901 11.2242 1.22422L4.82424 7.62422C4.58992 7.85853 4.21003 7.85853 3.97571 7.62422L0.775712 4.42422C0.541397 4.1899 0.541397 3.81 0.775712 3.57569C1.01003 3.34137 1.38993 3.34137 1.62424 3.57569L4.39998 6.35142L10.3757 0.375687C10.61 0.141373 10.9899 0.141373 11.2242 0.375687Z" />\n </svg>\n </span><span class="copyCode">复制代码</span></p><pre');
2268
2432
  return text;
2269
2433
  });
2434
+ // message = message.replaceAll(
2435
+ // new RegExp(`<img`, "ig"),
2436
+ // (i: any, index: any) => {
2437
+ // let text = `<div class='${styles.a}'><img`;
2438
+ // return text;
2439
+ // }
2440
+ // );
2270
2441
  if (item.sender == mid) {
2271
2442
  //只有引用和复制功能
2272
2443
  li = /*#__PURE__*/ _jsxs(_Fragment, {
@@ -2469,10 +2640,8 @@ var CustomerService = function(props) {
2469
2640
  // onMouseEnter方法内:判断回答内容的气泡是否在可视区域内,动态判断点赞按钮显示的上下位置
2470
2641
  var isSmall = showType == 1 || showType == 3;
2471
2642
  var container = document.getElementById(isSmall ? "chat_content" : "chat_content_modal");
2472
- console.log("onMouseEnter1", container);
2473
2643
  if (container) {
2474
2644
  var dom = container.querySelector('[id="'.concat(item.id, '"]'));
2475
- console.log("onMouseEnter2", dom);
2476
2645
  if (dom) {
2477
2646
  // const con_h=document.getElementById('chat_content').clientHeight-24;//滚动区域的高度
2478
2647
  var con_h = container.clientHeight - (isSmall ? 24 : 0); //滚动区域的高度;
@@ -2480,14 +2649,6 @@ var CustomerService = function(props) {
2480
2649
  var h = dom.clientHeight + (isSmall ? 24 : 0); //当前元素高度
2481
2650
  var topDom = dom.getElementsByClassName(styles.operate_modal_showtop)[0];
2482
2651
  var bottomDom = dom.getElementsByClassName(styles.operate_modal_showbottom)[0];
2483
- console.log("onMouseEnter3", topDom, bottomDom);
2484
- console.log("onMouseEnter4", {
2485
- h: h,
2486
- con_h: con_h,
2487
- rectY: rectY,
2488
- topDom: topDom,
2489
- bottomDom: bottomDom
2490
- });
2491
2652
  if (topDom && bottomDom) {
2492
2653
  if (rectY > 0) {
2493
2654
  //显示上边
@@ -2671,6 +2832,18 @@ var CustomerService = function(props) {
2671
2832
  children: li
2672
2833
  }, item.id);
2673
2834
  };
2835
+ // return (
2836
+ // <pre className={`${styles.mermaid}`}>
2837
+ // {`graph TD
2838
+ // A[开始] --> B[步骤1]
2839
+ // B --> C{条件判断}
2840
+ // C -- 是 --> D[步骤2]
2841
+ // C -- 否 --> E[步骤3]
2842
+ // D --> F[结束]
2843
+ // E --> F
2844
+ // `}
2845
+ // </pre>
2846
+ // )
2674
2847
  return /*#__PURE__*/ _jsx("ul", {
2675
2848
  className: styles.message_con,
2676
2849
  style: {
@@ -2684,45 +2857,101 @@ var CustomerService = function(props) {
2684
2857
  style: {
2685
2858
  height: "100%"
2686
2859
  },
2687
- // initialTopMostItemIndex={isPositionState? { index: "LAST", align: "end" }:undefined}
2688
- startReached: function() {
2689
- if (pageCount > pageNum && pageCount > 0) {
2860
+ initialTopMostItemIndex: !finished && isPositionState ? undefined : {
2861
+ index: "LAST",
2862
+ align: "end",
2863
+ offset: showType === 3 ? 58 : showType === 4 ? 144 : 58
2864
+ },
2865
+ initialItemCount: 10,
2866
+ itemsRendered: function() {
2867
+ var t = setTimeout(function() {
2868
+ mermaid.init({
2869
+ querySelector: ".".concat(styles.mermaid, ':not([data-processed="true"])'),
2870
+ suppressErrors: true
2871
+ }, ".".concat(styles.mermaid, ':not([data-processed="true"])'));
2872
+ clearTimeout(t);
2873
+ }, 100);
2874
+ },
2875
+ // startReached={(index) => {
2876
+ // console.log('atTopStateChange-startReached',index,lastIdRef.current)
2877
+ // if (pageCount > pageNum && pageCount > 0&& !loading&&lastIdRef.current=='') {
2878
+ // let number = pageNum + 1;
2879
+ // setPageNum((pageNum) => {
2880
+ // return pageNum + 1;
2881
+ // });
2882
+ // setLoading(true);
2883
+ // listTimer.current = setTimeout(() => {
2884
+ // getHistoryMessage(number, 2);
2885
+ // lastIdRef.current = "";
2886
+ // setLastId("");
2887
+ // }, 1000);
2888
+ // }
2889
+ // }}
2890
+ atTopStateChange: function(atTop) {
2891
+ // 判断是否滚动到顶部
2892
+ console.log("StateChange-atTopStateChange", {
2893
+ pageCount: pageCount,
2894
+ pageNum: pageNum
2895
+ }, getLisyFlagRef.current);
2896
+ if (atTop && pageCount > pageNum && pageCount > 0 && getLisyFlagRef.current != 1 && getLisyFlagRef.current != 4) {
2690
2897
  var number = pageNum + 1;
2691
2898
  setPageNum(function(pageNum) {
2692
2899
  return pageNum + 1;
2693
2900
  });
2694
2901
  setLoading(true);
2902
+ setBottomLoading(false);
2695
2903
  listTimer.current = setTimeout(function() {
2696
2904
  getHistoryMessage(number, 2);
2697
- }, 1000);
2905
+ }, 100);
2698
2906
  }
2699
2907
  },
2700
- endReached: function() {
2701
- if (pageNumHistory > 1) {
2908
+ // endReached={(index) => {
2909
+ // console.log('endReached',pageNumHistory,lastIdRef.current)
2910
+ // if (pageNumHistory > 1&&lastIdRef.current=='') {
2911
+ // let number = pageNumHistory - 1;
2912
+ // setPageNumHistory(number);
2913
+ // clearTimeout(listTimer.current);
2914
+ // listTimer.current = setTimeout(() => {
2915
+ // if (number > 0) {
2916
+ // setBottomLoading(true);
2917
+ // getHistoryMessage(number, 4);
2918
+ // lastIdRef.current = "";
2919
+ // setLastId("");
2920
+ // } else {
2921
+ // setPageNumHistory(0);
2922
+ // }
2923
+ // }, 1000);
2924
+ // }
2925
+ // }}
2926
+ atBottomStateChange: function(atBottom) {
2927
+ console.log("StateChange-atBottomStateChange", pageNumHistory, getLisyFlagRef.current);
2928
+ if (atBottom && pageNumHistory > 1 && getLisyFlagRef.current != 1) {
2702
2929
  var number = pageNumHistory - 1;
2703
2930
  setPageNumHistory(number);
2704
2931
  clearTimeout(listTimer.current);
2705
2932
  listTimer.current = setTimeout(function() {
2706
2933
  if (number > 0) {
2707
2934
  setBottomLoading(true);
2935
+ setLoading(false);
2708
2936
  getHistoryMessage(number, 4);
2937
+ lastIdRef.current = "";
2709
2938
  setLastId("");
2710
2939
  } else {
2711
2940
  setPageNumHistory(0);
2712
2941
  }
2713
- }, 1000);
2942
+ }, 100);
2714
2943
  }
2715
2944
  },
2716
- context: {
2717
- loading: loading
2718
- },
2945
+ // context={{ loading }}
2719
2946
  firstItemIndex: firstItemIndex,
2720
- increaseViewportBy: 200,
2721
- overscan: 10,
2722
2947
  logLevel: 0,
2948
+ overscan: {
2949
+ main: 1000,
2950
+ reverse: 1000
2951
+ },
2723
2952
  onScroll: function(e) {
2724
2953
  //生成答案过程中
2725
- if (!finishedRef.current) {
2954
+ if (!finishedRef.current && isWheelRef.current) {
2726
2955
  var _container, _container1, _container2;
2727
2956
  var container = e.target;
2728
2957
  var _container_scrollTop;
@@ -2741,6 +2970,7 @@ var CustomerService = function(props) {
2741
2970
  isPosition.current = true;
2742
2971
  setIsPositionState(true);
2743
2972
  }
2973
+ isWheelRef.current = false;
2744
2974
  console.log("Scroll-onScroll", {
2745
2975
  container: container,
2746
2976
  scrollTop: scrollTop,
@@ -2749,6 +2979,11 @@ var CustomerService = function(props) {
2749
2979
  isPosition: isPosition.current
2750
2980
  });
2751
2981
  }
2982
+ },
2983
+ onWheel: function() {
2984
+ if (!finishedRef.current) {
2985
+ isWheelRef.current = true;
2986
+ }
2752
2987
  }
2753
2988
  })
2754
2989
  });
@@ -3552,6 +3787,7 @@ var CustomerService = function(props) {
3552
3787
  if (page != 1) {
3553
3788
  setPageNumHistory(page);
3554
3789
  }
3790
+ lastIdRef.current = id;
3555
3791
  setLastId(id); //用于定位
3556
3792
  setPageNum(page);
3557
3793
  //如果是当前聊天室
@@ -4126,6 +4362,14 @@ var CustomerService = function(props) {
4126
4362
  resolve(viewBase64);
4127
4363
  });
4128
4364
  }
4365
+ }),
4366
+ showMemaid && memaidContent && /*#__PURE__*/ _jsx(ViewMemaid, {
4367
+ visible: showMemaid,
4368
+ onCancel: function() {
4369
+ return setShowMemaid(false);
4370
+ },
4371
+ className: "",
4372
+ content: memaidContent
4129
4373
  })
4130
4374
  ]
4131
4375
  });