bhd-components 0.10.8 → 0.10.9

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.
@@ -129,7 +129,8 @@ const FileList = /*#__PURE__*/ forwardRef((props, ref)=>{
129
129
  fileId: fileId,
130
130
  url: "",
131
131
  status: "waiting",
132
- source: file
132
+ source: file,
133
+ size: file.size
133
134
  };
134
135
  }
135
136
  return item;
@@ -152,7 +153,8 @@ const FileList = /*#__PURE__*/ forwardRef((props, ref)=>{
152
153
  fileId: fileId,
153
154
  url: "",
154
155
  status: "uploading",
155
- source: file
156
+ source: file,
157
+ size: file.size
156
158
  };
157
159
  }
158
160
  return item;
@@ -234,7 +236,8 @@ const FileList = /*#__PURE__*/ forwardRef((props, ref)=>{
234
236
  fileId: params.fileId || guidGenerator(),
235
237
  url: params.url || "",
236
238
  status: params.status || "waiting",
237
- source: file
239
+ source: file,
240
+ size: file.size
238
241
  };
239
242
  return customFile;
240
243
  };
@@ -55,7 +55,7 @@ const ReferencesIcon = (props)=>{
55
55
  }
56
56
  };
57
57
  return /*#__PURE__*/ _jsx("div", {
58
- className: `${getCls("msgItem-action-references")}`,
58
+ className: `${getCls("msgItem-action-reference")}`,
59
59
  onClick: ()=>clickFn(),
60
60
  children: referencesIcon
61
61
  });
@@ -1,4 +1,4 @@
1
- .msgItem-action-references {
1
+ .msgItem-action-reference {
2
2
  cursor: pointer;
3
3
  border-radius: 2px;
4
4
  display: flex;
@@ -45,8 +45,8 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
45
45
  const { prefix, contentConfig, apiRef } = props;
46
46
  const { getList, coverRenderText, msgAction = [
47
47
  "copy",
48
- "references"
49
- ], coverRenderReferences, onRecordMessage = ()=>{}, onVoteChange = ()=>{}, onRefresh = ()=>{}, iconFileRender } = contentConfig;
48
+ "reference"
49
+ ], coverRenderReferences, onRecordMessage = ()=>{}, onVoteChange = ()=>{}, onRefresh = ()=>{}, helloMsg, fileCustomRender = {} } = contentConfig;
50
50
  const loadMoreProps = contentConfig.loadMore || true;
51
51
  const virtuosoRef = useRef(null);
52
52
  const [loading, setLoading] = useState(false); // 是否加载中
@@ -73,21 +73,7 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
73
73
  const htmlRenderCache = useRef(new Map()).current;
74
74
  useImperativeHandle(ref, ()=>{
75
75
  return {
76
- addMsg: (msg)=>{
77
- if (msg.id !== "inputing") {
78
- // 不记录"正在输入..."的消息
79
- onRecordMessage(msg);
80
- }
81
- setDataSource((data)=>{
82
- return [
83
- ...data,
84
- msg
85
- ];
86
- });
87
- timerRef.current.scrollTimer = setTimeout(()=>{
88
- scrollToBottom();
89
- }, 100);
90
- },
76
+ addMsg,
91
77
  updateMsg: (id, obj)=>{
92
78
  setDataSource((data)=>{
93
79
  return data.map((item)=>{
@@ -129,7 +115,19 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
129
115
  };
130
116
  });
131
117
  useEffect(()=>{
132
- getData(page, pageSize);
118
+ getData(page, pageSize).then(()=>{
119
+ if (helloMsg) {
120
+ addMsg({
121
+ id: "helloMsg",
122
+ createTime: new Date().getTime(),
123
+ content: helloMsg,
124
+ location: "left",
125
+ reference: null,
126
+ source: null,
127
+ fileList: []
128
+ });
129
+ }
130
+ });
133
131
  let removeFn = delegate(wrapperRef.current, "click", `.${styles.copyCode}`, (event, target)=>{
134
132
  findCopyContent(event);
135
133
  });
@@ -170,6 +168,40 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
170
168
  dataSource,
171
169
  sendingId
172
170
  ]);
171
+ const addMsg = (msg)=>{
172
+ if (msg.id !== "inputing" && msg.id !== "helloMsg") {
173
+ // 不记录"正在输入..."的消息
174
+ onRecordMessage(msg);
175
+ }
176
+ let list = [];
177
+ if (msg.location === "right" && msg.fileList && msg.fileList.length > 0) {
178
+ console.log("fileList", msg, msg.fileList);
179
+ msg.fileList.map((item)=>{
180
+ list.push({
181
+ type: "file",
182
+ id: item.fileId,
183
+ createTime: msg.createTime,
184
+ content: "",
185
+ location: "right",
186
+ reference: null,
187
+ source: null,
188
+ suffix: item.suffix,
189
+ fileSize: item.size || 0,
190
+ fileTitle: item.name
191
+ });
192
+ });
193
+ }
194
+ list.push(msg);
195
+ setDataSource((data)=>{
196
+ return [
197
+ ...data,
198
+ ...list
199
+ ];
200
+ });
201
+ timerRef.current.scrollTimer = setTimeout(()=>{
202
+ scrollToBottom();
203
+ }, 100);
204
+ };
173
205
  const scrollToBottom = ()=>{
174
206
  if (!virtuosoRef.current) return;
175
207
  virtuosoRef.current.scrollToIndex({
@@ -179,24 +211,20 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
179
211
  };
180
212
  const getData = (page, pageSize)=>{
181
213
  setLoading(true);
182
- clearTimeout(timerRef.current.loadMore);
183
- timerRef.current.loadMore = setTimeout(()=>{
214
+ return getList(page, pageSize).then((listObj)=>{
184
215
  setLoading(false);
185
- getList(page, pageSize).then((listObj)=>{
186
- setLoading(false);
187
- console.log("listObjlistObj", listObj);
188
- setDataSource((data)=>{
189
- return [
190
- ...data,
191
- ...listObj.dataSource
192
- ];
193
- });
194
- setTotal(listObj.total);
195
- setPage(page);
196
- setPageSize(pageSize);
197
- setFirstItemIndex(listObj.total - pageSize * (page - 1));
216
+ console.log("listObjlistObj", listObj);
217
+ setDataSource((data)=>{
218
+ return [
219
+ ...data,
220
+ ...listObj.dataSource
221
+ ];
198
222
  });
199
- }, 500);
223
+ setTotal(listObj.total);
224
+ setPage(page);
225
+ setPageSize(pageSize);
226
+ setFirstItemIndex(listObj.total - pageSize * (page - 1));
227
+ });
200
228
  };
201
229
  const getCls = (clsName)=>{
202
230
  return styles[clsName] + " " + prefix + "-" + clsName;
@@ -226,26 +254,32 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
226
254
  // item.fileTitle = "这是一个文件名称.docx";
227
255
  // item.fileSize = "5Mb";
228
256
  if (item.type === "file") {
229
- contentNode = /*#__PURE__*/ _jsxs("div", {
230
- className: `${getCls("msgItem-file")}`,
231
- children: [
232
- /*#__PURE__*/ _jsx("div", {
233
- className: `${getCls("msgItem-file-left")}`,
234
- children: fileIconRender(item.suffix, iconFileRender)
235
- }),
236
- /*#__PURE__*/ _jsxs("div", {
237
- className: `${getCls("msgItem-file-right")}`,
238
- children: [
239
- /*#__PURE__*/ _jsx("p", {
240
- children: item.fileTitle
241
- }),
242
- /*#__PURE__*/ _jsx("p", {
243
- children: item.fileSize
257
+ let renderFileObj = _object_spread({
258
+ fileTitleRender: (item)=>{
259
+ return /*#__PURE__*/ _jsx(_Fragment, {
260
+ children: item.fileTitle
261
+ });
262
+ }
263
+ }, fileCustomRender);
264
+ if (renderFileObj.fileRender) {
265
+ contentNode = renderFileObj.fileRender(item);
266
+ } else {
267
+ contentNode = /*#__PURE__*/ _jsxs("div", {
268
+ className: `${getCls("msgItem-file")}`,
269
+ children: [
270
+ /*#__PURE__*/ _jsx("div", {
271
+ className: `${getCls("msgItem-file-left")}`,
272
+ children: fileIconRender(item.suffix, renderFileObj.iconFileRender)
273
+ }),
274
+ /*#__PURE__*/ _jsx("div", {
275
+ className: `${getCls("msgItem-file-right")}`,
276
+ children: /*#__PURE__*/ _jsx("p", {
277
+ children: renderFileObj.fileTitleRender(item)
244
278
  })
245
- ]
246
- })
247
- ]
248
- });
279
+ })
280
+ ]
281
+ });
282
+ }
249
283
  }
250
284
  // 是否显示时间
251
285
  let itemNode = /*#__PURE__*/ _jsx("div", {
@@ -285,12 +319,30 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
285
319
  let referenceNode = null;
286
320
  if (reference.type === "text") {
287
321
  referenceNode = /*#__PURE__*/ _jsx("div", {
288
- className: `${getCls("msgItem-references-text")}`,
322
+ className: `${getCls("msgItem-reference-text")}`,
289
323
  children: /*#__PURE__*/ _jsx("div", {
290
324
  children: reference.value
291
325
  })
292
326
  });
293
327
  }
328
+ if (reference.type === "file") {
329
+ referenceNode = /*#__PURE__*/ _jsx("div", {
330
+ className: `${getCls("msgItem-reference-file")}`,
331
+ children: /*#__PURE__*/ _jsxs("div", {
332
+ className: `${getCls("msgItem-reference-file-box")}`,
333
+ children: [
334
+ /*#__PURE__*/ _jsx("div", {
335
+ className: `${getCls("msgItem-reference-file-left")}`,
336
+ children: fileIconRender(reference.value.suffix, fileCustomRender.iconFileRender)
337
+ }),
338
+ /*#__PURE__*/ _jsx("div", {
339
+ className: `${getCls("msgItem-reference-file-right")}`,
340
+ children: reference.value.name
341
+ })
342
+ ]
343
+ })
344
+ });
345
+ }
294
346
  if (coverRenderReferences) {
295
347
  return coverRenderReferences(item, referenceNode);
296
348
  } else {
@@ -411,7 +463,7 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
411
463
  if (!msgAction.includes("copy")) {
412
464
  copyNode = null;
413
465
  }
414
- if (!msgAction.includes("references")) {
466
+ if (!msgAction.includes("reference")) {
415
467
  referencesNode = null;
416
468
  }
417
469
  if (!msgAction.includes("upVite")) {
@@ -607,6 +659,9 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
607
659
  p[0].innerText = "复制代码";
608
660
  }
609
661
  };
662
+ const onScroll = ()=>{
663
+ console.log("滚动滚动");
664
+ };
610
665
  return /*#__PURE__*/ _jsx("div", {
611
666
  className: `${getCls("virtuosoList-wrapper")}`,
612
667
  ref: wrapperRef,
@@ -631,7 +686,8 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
631
686
  Header: Header
632
687
  },
633
688
  increaseViewportBy: 200,
634
- overscan: 10
689
+ overscan: 10,
690
+ onScroll: onScroll
635
691
  })
636
692
  });
637
693
  });
@@ -274,30 +274,31 @@
274
274
  border-radius: 8px;
275
275
  border: 1px solid #ebebeb;
276
276
  gap: 12px;
277
- .msgItem-file-left{
277
+ min-width: 216px;
278
+ .msgItem-file-left {
278
279
  font-size: 24px;
279
280
  display: flex;
280
281
  justify-content: center;
281
282
  align-items: center;
282
283
  padding: 0;
283
284
  margin: 0;
284
- &>i{
285
+ & > i {
285
286
  display: flex;
286
287
  font-size: 24px;
287
288
  }
288
289
  }
289
- .msgItem-file-right{
290
+ .msgItem-file-right {
290
291
  font-size: 14px;
291
292
  font-weight: 400;
292
293
  color: rgba(0, 0, 0, 0.65);
293
- &>p{
294
- &:nth-child(1){
295
- margin-bottom: 4px;
296
- }
297
- &:nth-child(2){
298
- font-size: 12px;
299
- color: rgba(0, 0, 0, 0.25);
294
+ & > p {
295
+ &:nth-child(1) {
296
+ // margin-bottom: 4px;
300
297
  }
298
+ // &:nth-child(2) {
299
+ // font-size: 12px;
300
+ // color: rgba(0, 0, 0, 0.25);
301
+ // }
301
302
  }
302
303
  }
303
304
  }
@@ -356,7 +357,7 @@
356
357
  }
357
358
  }
358
359
 
359
- .msgItem-references-text {
360
+ .msgItem-reference-text {
360
361
  padding: 8px;
361
362
  border-radius: 2px;
362
363
  background: #e7e7e7;
@@ -375,6 +376,45 @@
375
376
  word-wrap: break-word;
376
377
  }
377
378
  }
379
+ .msgItem-reference-file {
380
+ padding: 8px;
381
+ border-radius: 2px;
382
+ background: #e7e7e7;
383
+ font-size: 12px;
384
+ color: rgba(0, 0, 0, 0.65);
385
+ margin-top: 8px;
386
+
387
+ .msgItem-reference-file-box {
388
+ display: flex;
389
+ align-items: center;
390
+ gap: 12px;
391
+ background: #fafafa;
392
+ border-radius: 8px;
393
+ border: 1px solid #ebebeb;
394
+ display: flex;
395
+ align-items: center;
396
+ gap: 12px;
397
+ padding: 8px 12px;
398
+ min-width: 216px;
399
+ .msgItem-reference-file-left {
400
+ font-size: 24px;
401
+ display: flex;
402
+ justify-content: center;
403
+ align-items: center;
404
+ padding: 0;
405
+ margin: 0;
406
+ & > i {
407
+ display: flex;
408
+ font-size: 24px;
409
+ }
410
+ }
411
+ .msgItem-reference-file-right {
412
+ font-size: 14px;
413
+ font-weight: 400;
414
+ color: rgba(0, 0, 0, 0.65);
415
+ }
416
+ }
417
+ }
378
418
  &.msgItem-left {
379
419
  justify-content: flex-start;
380
420
  .msgItem-box {
@@ -62,7 +62,12 @@ export interface contentConfigProps {
62
62
  onRecordMessage?: (item: dataItemType) => void; // 发送和接收的消息记录
63
63
  onVoteChange?: (type:string,item: dataItemType) => void; // 点赞 或踩
64
64
  onRefresh?: (item:dataItemType) => void;// 刷新
65
- iconFileRender?: (suffix: string) => React.ReactNode; // 文件上传的 icon。参数 文件对象file 返回值为图标
65
+ fileCustomRender?: {// 文件对象的自定义渲染
66
+ iconFileRender?: (suffix: string) => React.ReactNode; // 文件上传的 icon。参数 文件对象file 返回值为图标
67
+ fileTitleRender?: (item: dataItemType) => React.ReactNode;
68
+ fileBottomRender?: (item: dataItemType) => React.ReactNode;
69
+ fileRender?: (item: dataItemType) => React.ReactNode;
70
+ };
66
71
  }
67
72
 
68
73
  // content props
@@ -206,6 +211,7 @@ export interface fileCustomProps {
206
211
  url: string;
207
212
  status: fileStatus | undefined;
208
213
  source: File | undefined;
214
+ size:number
209
215
  }
210
216
 
211
217
  // FileList 组件 ref props
@@ -294,7 +300,7 @@ export interface dataItemType {
294
300
  vote?:string;// "up":点赞。"down":踩
295
301
  type?:"file"|"text",
296
302
  suffix?:string;
297
- fileSize?:string;
303
+ fileSize?:number;
298
304
  fileTitle?:string;
299
305
  fileList?:fileCustomProps[];
300
306
  }
@@ -139,7 +139,8 @@ var FileList = /*#__PURE__*/ forwardRef(function(props, ref) {
139
139
  fileId: fileId,
140
140
  url: "",
141
141
  status: "waiting",
142
- source: file
142
+ source: file,
143
+ size: file.size
143
144
  };
144
145
  }
145
146
  return item;
@@ -161,7 +162,8 @@ var FileList = /*#__PURE__*/ forwardRef(function(props, ref) {
161
162
  fileId: fileId,
162
163
  url: "",
163
164
  status: "uploading",
164
- source: file
165
+ source: file,
166
+ size: file.size
165
167
  };
166
168
  }
167
169
  return item;
@@ -248,7 +250,8 @@ var FileList = /*#__PURE__*/ forwardRef(function(props, ref) {
248
250
  fileId: params.fileId || guidGenerator(),
249
251
  url: params.url || "",
250
252
  status: params.status || "waiting",
251
- source: file
253
+ source: file,
254
+ size: file.size
252
255
  };
253
256
  return customFile;
254
257
  };
@@ -55,7 +55,7 @@ var ReferencesIcon = function(props) {
55
55
  }
56
56
  };
57
57
  return /*#__PURE__*/ _jsx("div", {
58
- className: "".concat(getCls("msgItem-action-references")),
58
+ className: "".concat(getCls("msgItem-action-reference")),
59
59
  onClick: function() {
60
60
  return clickFn();
61
61
  },
@@ -1,4 +1,4 @@
1
- .msgItem-action-references {
1
+ .msgItem-action-reference {
2
2
  cursor: pointer;
3
3
  border-radius: 2px;
4
4
  display: flex;