bhd-components 0.10.11 → 0.10.13

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.
@@ -15,6 +15,7 @@
15
15
  & > i {
16
16
  color: rgba(140, 140, 140, 1);
17
17
  font-size: 16px;
18
+ display: flex;
18
19
  }
19
20
  &:hover {
20
21
  background-color: rgba(0, 0, 0, 0.04);
@@ -58,7 +58,8 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
58
58
  useImperativeHandle(ref, ()=>{
59
59
  return _object_spread({
60
60
  setTextValue,
61
- sendMsg: sendMsg,
61
+ sendMsg,
62
+ refreshSendMsg,
62
63
  clearText: ()=>{
63
64
  setTextValue("");
64
65
  },
@@ -205,22 +206,43 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
205
206
  });
206
207
  sendMsgAjax();
207
208
  };
208
- const sendMsgAjax = ()=>{
209
+ // 重新发送消息
210
+ const refreshSendMsg = function(msgId, value, reference, fileList) {
211
+ sendMsgAjax({
212
+ id: msgId,
213
+ value: value,
214
+ reference: reference || null,
215
+ fileList: fileList || []
216
+ });
217
+ };
218
+ const sendMsgAjax = (recordObj)=>{
209
219
  const { url, method = "POST", headers = ()=>({}), params = ()=>"", onOpen = ()=>{}, onMessage = (ev)=>ev, onClose = ()=>{}, onError = ()=>{}, coverProps = {}, beforeSendMsg = ()=>Promise.resolve() } = sendMsgAjaxParams;
210
220
  ctrl.current = new AbortController();
211
221
  // apiRef
212
222
  console.log("apiRef", apiRef);
213
223
  let msgId = "inputing";
214
224
  let createTime = new Date().getTime();
215
- apiRef.contentApi.addMsg({
216
- id: msgId,
217
- createTime: createTime,
218
- content: "正在输入...",
219
- location: "left",
220
- reference: null,
221
- source: null,
222
- fileList: fileListRef.current.getFileList()
223
- });
225
+ if (recordObj) {
226
+ apiRef.contentApi.addMsg({
227
+ id: msgId,
228
+ createTime: createTime,
229
+ content: "正在输入...",
230
+ location: "left",
231
+ reference: recordObj.reference || null,
232
+ source: null,
233
+ fileList: recordObj.fileList || []
234
+ });
235
+ } else {
236
+ apiRef.contentApi.addMsg({
237
+ id: msgId,
238
+ createTime: createTime,
239
+ content: "正在输入...",
240
+ location: "left",
241
+ reference: null,
242
+ source: null,
243
+ fileList: fileListRef.current.getFileList()
244
+ });
245
+ }
224
246
  let msgContent = "";
225
247
  setSending(true);
226
248
  setTextValue("");
@@ -232,6 +254,19 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
232
254
  recordRef.current.referencesSource,
233
255
  fileListRef.current ? fileListRef.current.getFileList() : []
234
256
  ];
257
+ if (recordObj) {
258
+ arg = [
259
+ recordObj.value,
260
+ recordObj.reference || null,
261
+ recordObj.fileList || []
262
+ ];
263
+ } else {
264
+ arg = [
265
+ recordRef.current.value,
266
+ recordRef.current.referencesSource,
267
+ fileListRef.current ? fileListRef.current.getFileList() : []
268
+ ];
269
+ }
235
270
  beforeSendMsg(...arg).then((beforeInfo)=>{
236
271
  const callback = ()=>{
237
272
  let isClose = false;
@@ -242,8 +277,8 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
242
277
  setSending(false);
243
278
  if (recordMsgObj.id) {
244
279
  apiRef.contentApi.recordMsg(recordMsgObj);
245
- apiRef.contentApi.setSendingId(recordMsgObj.id);
246
280
  }
281
+ apiRef.contentApi.setSendingId("");
247
282
  console.log("onclose: ", recordMsgObj);
248
283
  };
249
284
  fetchEventSource(url, _object_spread({
@@ -267,6 +302,9 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
267
302
  },
268
303
  onmessage: (ev)=>{
269
304
  let data = onMessage(ev, closeCallback);
305
+ if (recordObj) {
306
+ data.id = recordObj.id;
307
+ }
270
308
  msgContent += data.content;
271
309
  let str = msgContent.replace(/\\n/g, "\n");
272
310
  str = conversionContent(str);
@@ -281,9 +319,9 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
281
319
  apiRef.contentApi.setSendingId(data.id);
282
320
  apiRef.contentApi.updateMsg(msgId, recordMsgObj);
283
321
  msgId = data.id;
284
- updateMsgRef.current = setTimeout(function() {
285
- apiRef.contentApi.scrollToBottom();
286
- }, 100);
322
+ // updateMsgRef.current = setTimeout(function () {
323
+ apiRef.contentApi.scrollToBottom();
324
+ // }, 100);
287
325
  },
288
326
  onclose: ()=>{
289
327
  closeCallback();
@@ -6,6 +6,7 @@
6
6
  & > i {
7
7
  color: rgba(140, 140, 140, 1);
8
8
  font-size: 16px;
9
+ display: flex;
9
10
  }
10
11
  &:hover {
11
12
  background-color: rgba(0, 0, 0, 0.04);
@@ -70,6 +70,7 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
70
70
  sendingId: ""
71
71
  });
72
72
  const timeRenderCache = useRef(new Map()).current;
73
+ const autoScrollBottom = useRef(true);
73
74
  const htmlRenderCache = useRef(new Map()).current;
74
75
  useImperativeHandle(ref, ()=>{
75
76
  return {
@@ -161,6 +162,9 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
161
162
  recordRef.current.dataSource = dataSource;
162
163
  recordRef.current.maxPage = Math.ceil(total / pageSize);
163
164
  recordRef.current.sendingId = sendingId;
165
+ if (!sendingId) {
166
+ autoScrollBottom.current = true;
167
+ }
164
168
  }, [
165
169
  page,
166
170
  pageSize,
@@ -197,14 +201,15 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
197
201
  ...list
198
202
  ];
199
203
  });
200
- timerRef.current.scrollTimer = setTimeout(()=>{
201
- scrollToBottom();
202
- }, 100);
204
+ // timerRef.current.scrollTimer = setTimeout(() => {
205
+ scrollToBottom();
206
+ // }, 100);
203
207
  };
204
208
  const scrollToBottom = ()=>{
205
- if (!virtuosoRef.current) return;
209
+ if (!virtuosoRef.current || !autoScrollBottom.current) return;
206
210
  virtuosoRef.current.scrollToIndex({
207
211
  index: "LAST",
212
+ align: "end",
208
213
  behavior: "auto"
209
214
  });
210
215
  };
@@ -654,8 +659,10 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
654
659
  p[0].innerText = "复制代码";
655
660
  }
656
661
  };
657
- const onScroll = ()=>{
658
- console.log("滚动滚动");
662
+ const onWheel = ()=>{
663
+ if (recordRef.current.sendingId && recordRef.current.sendingId !== "inputing") {
664
+ autoScrollBottom.current = false;
665
+ }
659
666
  };
660
667
  return /*#__PURE__*/ _jsx("div", {
661
668
  className: `${getCls("virtuosoList-wrapper")}`,
@@ -682,7 +689,7 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
682
689
  },
683
690
  increaseViewportBy: 200,
684
691
  overscan: 10,
685
- onScroll: onScroll
692
+ onWheel: onWheel
686
693
  })
687
694
  });
688
695
  });
@@ -160,6 +160,7 @@ export type fileStatus =
160
160
  export interface footerRefProps {
161
161
  setTextValue: (value: string) => void; // 设置输入框的值
162
162
  sendMsg: (value: string) => void; // 发送消息
163
+ refreshSendMsg:(msgId:string,value:string,reference?:any,fileList?:any)=>void;// 刷新消息
163
164
  clearText: () => void; // 清空输入框
164
165
  getCanSendMsg: () => boolean; //获取当前是否允许发送消息的状态
165
166
  stopMessage: () => void; //停止发送消息
@@ -110,6 +110,7 @@ const CustomerService = (props)=>{
110
110
  const mid = props.userData.mid;
111
111
  const renderAiAnswerTimer = useRef(null);
112
112
  const remarkable = new Remarkable({
113
+ html: true,
113
114
  highlight: function(str, lang) {
114
115
  if (lang && hljs.getLanguage(lang)) {
115
116
  try {
@@ -124,6 +125,7 @@ const CustomerService = (props)=>{
124
125
  });
125
126
  const remarkReplaceKey = (message, keyWordProblem)=>{
126
127
  let newRemarkable = new Remarkable({
128
+ html: true,
127
129
  highlight: function(str, lang) {
128
130
  if (lang && hljs.getLanguage(lang)) {
129
131
  try {
@@ -1171,6 +1173,7 @@ const CustomerService = (props)=>{
1171
1173
  console.log('返回中', msg);
1172
1174
  content = content + msg.message;
1173
1175
  // isPosition.current = true;
1176
+ clearTimeout(renderAiAnswerTimer.current);
1174
1177
  renderAiAnswerTimer.current = setTimeout(()=>{
1175
1178
  if (!finishedRef.current) {
1176
1179
  renderAiAnswer(msg, id, type);
@@ -15,6 +15,7 @@
15
15
  & > i {
16
16
  color: rgba(140, 140, 140, 1);
17
17
  font-size: 16px;
18
+ display: flex;
18
19
  }
19
20
  &:hover {
20
21
  background-color: rgba(0, 0, 0, 0.04);
@@ -63,6 +63,7 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
63
63
  return _object_spread({
64
64
  setTextValue: setTextValue,
65
65
  sendMsg: sendMsg,
66
+ refreshSendMsg: refreshSendMsg,
66
67
  clearText: function() {
67
68
  setTextValue("");
68
69
  },
@@ -209,7 +210,16 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
209
210
  });
210
211
  sendMsgAjax();
211
212
  };
212
- var sendMsgAjax = function() {
213
+ // 重新发送消息
214
+ var refreshSendMsg = function refreshSendMsg(msgId, value, reference, fileList) {
215
+ sendMsgAjax({
216
+ id: msgId,
217
+ value: value,
218
+ reference: reference || null,
219
+ fileList: fileList || []
220
+ });
221
+ };
222
+ var sendMsgAjax = function(recordObj) {
213
223
  var url = sendMsgAjaxParams.url, _sendMsgAjaxParams_method = sendMsgAjaxParams.method, method = _sendMsgAjaxParams_method === void 0 ? "POST" : _sendMsgAjaxParams_method, _sendMsgAjaxParams_headers = sendMsgAjaxParams.headers, headers = _sendMsgAjaxParams_headers === void 0 ? function() {
214
224
  return {};
215
225
  } : _sendMsgAjaxParams_headers, _sendMsgAjaxParams_params = sendMsgAjaxParams.params, params = _sendMsgAjaxParams_params === void 0 ? function() {
@@ -224,15 +234,27 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
224
234
  console.log("apiRef", apiRef);
225
235
  var msgId = "inputing";
226
236
  var createTime = new Date().getTime();
227
- apiRef.contentApi.addMsg({
228
- id: msgId,
229
- createTime: createTime,
230
- content: "正在输入...",
231
- location: "left",
232
- reference: null,
233
- source: null,
234
- fileList: fileListRef.current.getFileList()
235
- });
237
+ if (recordObj) {
238
+ apiRef.contentApi.addMsg({
239
+ id: msgId,
240
+ createTime: createTime,
241
+ content: "正在输入...",
242
+ location: "left",
243
+ reference: recordObj.reference || null,
244
+ source: null,
245
+ fileList: recordObj.fileList || []
246
+ });
247
+ } else {
248
+ apiRef.contentApi.addMsg({
249
+ id: msgId,
250
+ createTime: createTime,
251
+ content: "正在输入...",
252
+ location: "left",
253
+ reference: null,
254
+ source: null,
255
+ fileList: fileListRef.current.getFileList()
256
+ });
257
+ }
236
258
  var msgContent = "";
237
259
  setSending(true);
238
260
  setTextValue("");
@@ -244,6 +266,19 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
244
266
  recordRef.current.referencesSource,
245
267
  fileListRef.current ? fileListRef.current.getFileList() : []
246
268
  ];
269
+ if (recordObj) {
270
+ arg = [
271
+ recordObj.value,
272
+ recordObj.reference || null,
273
+ recordObj.fileList || []
274
+ ];
275
+ } else {
276
+ arg = [
277
+ recordRef.current.value,
278
+ recordRef.current.referencesSource,
279
+ fileListRef.current ? fileListRef.current.getFileList() : []
280
+ ];
281
+ }
247
282
  beforeSendMsg.apply(void 0, _to_consumable_array(arg)).then(function(beforeInfo) {
248
283
  var callback = function() {
249
284
  var isClose = false;
@@ -254,8 +289,8 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
254
289
  setSending(false);
255
290
  if (recordMsgObj.id) {
256
291
  apiRef.contentApi.recordMsg(recordMsgObj);
257
- apiRef.contentApi.setSendingId(recordMsgObj.id);
258
292
  }
293
+ apiRef.contentApi.setSendingId("");
259
294
  console.log("onclose: ", recordMsgObj);
260
295
  };
261
296
  fetchEventSource(url, _object_spread({
@@ -281,6 +316,9 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
281
316
  },
282
317
  onmessage: function(ev) {
283
318
  var data = onMessage(ev, closeCallback);
319
+ if (recordObj) {
320
+ data.id = recordObj.id;
321
+ }
284
322
  msgContent += data.content;
285
323
  var str = msgContent.replace(/\\n/g, "\n");
286
324
  str = conversionContent(str);
@@ -295,9 +333,9 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
295
333
  apiRef.contentApi.setSendingId(data.id);
296
334
  apiRef.contentApi.updateMsg(msgId, recordMsgObj);
297
335
  msgId = data.id;
298
- updateMsgRef.current = setTimeout(function() {
299
- apiRef.contentApi.scrollToBottom();
300
- }, 100);
336
+ // updateMsgRef.current = setTimeout(function () {
337
+ apiRef.contentApi.scrollToBottom();
338
+ // }, 100);
301
339
  },
302
340
  onclose: function() {
303
341
  closeCallback();
@@ -6,6 +6,7 @@
6
6
  & > i {
7
7
  color: rgba(140, 140, 140, 1);
8
8
  font-size: 16px;
9
+ display: flex;
9
10
  }
10
11
  &:hover {
11
12
  background-color: rgba(0, 0, 0, 0.04);
@@ -74,6 +74,7 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
74
74
  sendingId: ""
75
75
  });
76
76
  var timeRenderCache = useRef(new Map()).current;
77
+ var autoScrollBottom = useRef(true);
77
78
  var htmlRenderCache = useRef(new Map()).current;
78
79
  useImperativeHandle(ref, function() {
79
80
  return {
@@ -167,6 +168,9 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
167
168
  recordRef.current.dataSource = dataSource;
168
169
  recordRef.current.maxPage = Math.ceil(total / pageSize);
169
170
  recordRef.current.sendingId = sendingId;
171
+ if (!sendingId) {
172
+ autoScrollBottom.current = true;
173
+ }
170
174
  }, [
171
175
  page,
172
176
  pageSize,
@@ -200,14 +204,15 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
200
204
  setDataSource(function(data) {
201
205
  return _to_consumable_array(data).concat(_to_consumable_array(list));
202
206
  });
203
- timerRef.current.scrollTimer = setTimeout(function() {
204
- scrollToBottom();
205
- }, 100);
207
+ // timerRef.current.scrollTimer = setTimeout(() => {
208
+ scrollToBottom();
209
+ // }, 100);
206
210
  };
207
211
  var scrollToBottom = function() {
208
- if (!virtuosoRef.current) return;
212
+ if (!virtuosoRef.current || !autoScrollBottom.current) return;
209
213
  virtuosoRef.current.scrollToIndex({
210
214
  index: "LAST",
215
+ align: "end",
211
216
  behavior: "auto"
212
217
  });
213
218
  };
@@ -631,8 +636,10 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
631
636
  p[0].innerText = "复制代码";
632
637
  }
633
638
  };
634
- var onScroll = function() {
635
- console.log("滚动滚动");
639
+ var onWheel = function() {
640
+ if (recordRef.current.sendingId && recordRef.current.sendingId !== "inputing") {
641
+ autoScrollBottom.current = false;
642
+ }
636
643
  };
637
644
  return /*#__PURE__*/ _jsx("div", {
638
645
  className: "".concat(getCls("virtuosoList-wrapper")),
@@ -659,7 +666,7 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
659
666
  },
660
667
  increaseViewportBy: 200,
661
668
  overscan: 10,
662
- onScroll: onScroll
669
+ onWheel: onWheel
663
670
  })
664
671
  });
665
672
  });
@@ -160,6 +160,7 @@ export type fileStatus =
160
160
  export interface footerRefProps {
161
161
  setTextValue: (value: string) => void; // 设置输入框的值
162
162
  sendMsg: (value: string) => void; // 发送消息
163
+ refreshSendMsg:(msgId:string,value:string,reference?:any,fileList?:any)=>void;// 刷新消息
163
164
  clearText: () => void; // 清空输入框
164
165
  getCanSendMsg: () => boolean; //获取当前是否允许发送消息的状态
165
166
  stopMessage: () => void; //停止发送消息
@@ -114,6 +114,7 @@ var CustomerService = function(props) {
114
114
  var mid = props.userData.mid;
115
115
  var renderAiAnswerTimer = useRef(null);
116
116
  var remarkable = new Remarkable({
117
+ html: true,
117
118
  highlight: function highlight(str, lang) {
118
119
  if (lang && hljs.getLanguage(lang)) {
119
120
  try {
@@ -128,6 +129,7 @@ var CustomerService = function(props) {
128
129
  });
129
130
  var remarkReplaceKey = function(message, keyWordProblem) {
130
131
  var newRemarkable = new Remarkable({
132
+ html: true,
131
133
  highlight: function highlight(str, lang) {
132
134
  if (lang && hljs.getLanguage(lang)) {
133
135
  try {
@@ -1262,6 +1264,7 @@ var CustomerService = function(props) {
1262
1264
  console.log("返回中", msg);
1263
1265
  content = content + msg.message;
1264
1266
  // isPosition.current = true;
1267
+ clearTimeout(renderAiAnswerTimer.current);
1265
1268
  renderAiAnswerTimer.current = setTimeout(function() {
1266
1269
  if (!finishedRef.current) {
1267
1270
  renderAiAnswer(msg, id, type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bhd-components",
3
- "version": "0.10.11",
3
+ "version": "0.10.13",
4
4
  "description": "组件功能描述",
5
5
  "config": {
6
6
  "commitizen": {