bhd-components 0.10.36 → 0.10.37

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.
@@ -136,9 +136,12 @@ const getBase64Image = (src)=>{
136
136
  };
137
137
  const formatDate = (dateStr)=>{
138
138
  const today = new Date();
139
+ today.setHours(0, 0, 0, 0); // 将时间部分设为0,只比较日期
139
140
  const date = new Date(dateStr);
141
+ const cloneDate = new Date(dateStr);
142
+ cloneDate.setHours(0, 0, 0, 0); // 将时间部分设为0,只比较日期
140
143
  let isSameDay = today.getFullYear() === date.getFullYear() && today.getMonth() === date.getMonth() && today.getDate() === date.getDate();
141
- const dayDiff = Math.ceil((today - date) / (1000 * 60 * 60 * 24)); // 计算天数差
144
+ const dayDiff = Math.ceil((today - cloneDate) / (1000 * 60 * 60 * 24)); // 计算天数差
142
145
  // 判断当前的日期 是否于传入的日期为同一天 同一天则显示时间 不是同一天则判断是否超过一周
143
146
  // console.log(dayDiff,'dayDiffdayDiff',today,'___',date);
144
147
  if (isSameDay) {
@@ -146,7 +149,7 @@ const formatDate = (dateStr)=>{
146
149
  return date.toLocaleTimeString('zh-CN', {
147
150
  hour12: false
148
151
  }).substring(0, 5);
149
- } else if (dayDiff <= 7) {
152
+ } else if (dayDiff < 7) {
150
153
  // 一周内
151
154
  return date.toLocaleString('zh-CN', {
152
155
  weekday: 'short'
@@ -804,7 +804,7 @@ const CustomerService = (props)=>{
804
804
  });
805
805
  };
806
806
  //AI窗口,type:1发送打招呼信息欢迎语 2点赞消息 3踩消息 4没有AI客服权限,5,发送超过10万字消息 6, 没有AI客服权限,发送最热的问题
807
- const sendGreetingMessage = (type)=>{
807
+ const sendGreetingMessage = async (type, message = "")=>{
808
808
  let obj = {};
809
809
  if (type == 1) {
810
810
  sendWelcomMessage();
@@ -842,7 +842,7 @@ const CustomerService = (props)=>{
842
842
  roomId: roomId,
843
843
  sender: mid,
844
844
  recevier: "AI",
845
- message: keyWord,
845
+ message: message ? message : keyWord,
846
846
  createdAt: getDataTime(-1),
847
847
  quotedMessage: citationContent.content,
848
848
  extraInfos: [
@@ -852,6 +852,22 @@ const CustomerService = (props)=>{
852
852
  }
853
853
  ]
854
854
  };
855
+ let imageUrl = '';
856
+ if (citationContent.imageUrl) {
857
+ let base64 = await urlToBase64(citationContent.imageUrl);
858
+ imageUrl = base64;
859
+ }
860
+ if (screenshotBese64) {
861
+ imageUrl = screenshotBese64;
862
+ }
863
+ console.log('imageUrl', imageUrl);
864
+ if (imageUrl) {
865
+ obj.image = imageUrl;
866
+ obj.extraInfos.push({
867
+ key: "imageUrl",
868
+ value: imageUrl
869
+ });
870
+ }
855
871
  } else if (type == 5) {
856
872
  obj = {
857
873
  roomId: roomId,
@@ -874,6 +890,7 @@ const CustomerService = (props)=>{
874
890
  setKeyWord("");
875
891
  setQuestionsList([]);
876
892
  setCitationContent({});
893
+ setScreenshotBese64('');
877
894
  http.post(`${urllocation}/chat-service/public/v1.0/history-messages`, obj).then((res)=>{
878
895
  if (res.data.id) {
879
896
  if (pageNumHistory <= 1) {
@@ -1217,7 +1234,7 @@ const CustomerService = (props)=>{
1217
1234
  roomId: roomId,
1218
1235
  sender: "AI",
1219
1236
  recevier: mid,
1220
- message: "正在输入...",
1237
+ message: "正在思考...",
1221
1238
  id: "123456",
1222
1239
  createdAt: getDataTime(-1),
1223
1240
  extraInfo: null
@@ -1231,7 +1248,7 @@ const CustomerService = (props)=>{
1231
1248
  roomId: roomId,
1232
1249
  sender: "AI",
1233
1250
  recevier: mid,
1234
- message: "正在输入...",
1251
+ message: "正在思考...",
1235
1252
  id: "123456",
1236
1253
  createdAt: getDataTime(-1),
1237
1254
  extraInfo: null
@@ -2298,6 +2315,12 @@ const CustomerService = (props)=>{
2298
2315
  let message = item.message;
2299
2316
  let li;
2300
2317
  // 是否需要显示日期
2318
+ // 判断是否第一项:
2319
+ // 如果是第一项显示日期+时间;
2320
+ //
2321
+ // 如果不是第一项:
2322
+ // 先判断是否跨天;如果跨天:就显示日期+时间;
2323
+ // 如果不跨天:判断是否超过10分钟,超过10分钟判断是否是当天,如果当天显示时间,不是当天就显示日期+时间;没超过10分钟不显示
2301
2324
  let itemIndex = historyMessageList.findIndex((ite)=>ite.id === item.id);
2302
2325
  let time = "";
2303
2326
  if (historyMessageList.length > 1) {
@@ -2307,16 +2330,30 @@ const CustomerService = (props)=>{
2307
2330
  } else {
2308
2331
  //非第一项 与上一项进行对比
2309
2332
  let beforeTime = historyMessageList[itemIndex - 1].createdAt;
2310
- //判断与上一条数据 是否跨天
2311
2333
  let beforeTimeObj = parseDate(beforeTime);
2334
+ // 上一条的日期
2312
2335
  let beforeTimeStr = `${beforeTimeObj.year}-${beforeTimeObj.month}-${beforeTimeObj.day}`;
2336
+ // 当前这条的日期
2313
2337
  let curTimeStr = `${timeObj.year}-${timeObj.month}-${timeObj.day}`;
2338
+ let now = new Date();
2339
+ // 当天的日期
2340
+ let nowTimeStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
2341
+ //判断与上一条数据 是否跨天
2314
2342
  if (beforeTimeStr !== curTimeStr) {
2343
+ // 跨天
2344
+ // 显示日期+时间
2315
2345
  time = `${timeObj.year}-${timeObj.month}-${timeObj.day} ${timeObj.hours}:${timeObj.minutes}`;
2316
2346
  } else {
2317
2347
  //没有跨天 判断是否相隔超过10分钟
2318
2348
  if (new Date(item.createdAt).valueOf() - new Date(beforeTime).valueOf() > 10 * 60 * 1000) {
2319
- time = `${timeObj.hours}:${timeObj.minutes}`;
2349
+ //判断是否当天
2350
+ if (curTimeStr === nowTimeStr) {
2351
+ // 当天,显示时间
2352
+ time = `${timeObj.hours}:${timeObj.minutes}`;
2353
+ } else {
2354
+ // 非当天,显示日期+时间
2355
+ time = `${timeObj.year}-${timeObj.month}-${timeObj.day} ${timeObj.hours}:${timeObj.minutes}`;
2356
+ }
2320
2357
  }
2321
2358
  }
2322
2359
  }
@@ -2454,17 +2491,17 @@ const CustomerService = (props)=>{
2454
2491
  },
2455
2492
  className: styles.content_child
2456
2493
  }),
2457
- !item.quotedMessage && item.extraInfo && JSON.parse(item.extraInfo).length > 0 && JSON.parse(item.extraInfo)[0].key == "imageUrl" && /*#__PURE__*/ _jsxs("p", {
2458
- className: `${styles.img_con} ${showType == 2 || showType == 4 ? styles.img_con2 : ""}`,
2494
+ !item.quotedMessage && item.extraInfo && JSON.parse(item.extraInfo).length > 0 && JSON.parse(item.extraInfo).find((x)=>x.key == "imageUrl") && /*#__PURE__*/ _jsxs("p", {
2495
+ className: `${styles.img_con} ${showType == 2 || showType == 4 ? styles.img_con2 : ''}`,
2459
2496
  children: [
2460
2497
  /*#__PURE__*/ _jsx("img", {
2461
- src: JSON.parse(item.extraInfo)[0].value
2498
+ src: JSON.parse(item.extraInfo).find((x)=>x.key == "imageUrl").value
2462
2499
  }),
2463
2500
  /*#__PURE__*/ _jsx("div", {
2464
2501
  className: styles.mask_zoom,
2465
2502
  children: /*#__PURE__*/ _jsx(ZoomInOutlined, {
2466
2503
  onClick: ()=>{
2467
- setViewBase64(JSON.parse(item.extraInfo)[0].value);
2504
+ setViewBase64(JSON.parse(item.extraInfo).find((x)=>x.key == "imageUrl").value);
2468
2505
  setVisible(true);
2469
2506
  }
2470
2507
  })
@@ -2560,7 +2597,8 @@ const CustomerService = (props)=>{
2560
2597
  style: {
2561
2598
  marginRight: "12px"
2562
2599
  },
2563
- children: isAiChatWindow ? item.extraInfo == null || header == 1 ? /*#__PURE__*/ _jsx(CustomAiIcon, {}) : /*#__PURE__*/ _jsx("img", {
2600
+ children: isAiChatWindow ? // item.extraInfo == null || header == 1
2601
+ userData.modules.some((item)=>item.short == "AIservice") ? /*#__PURE__*/ _jsx(CustomAiIcon, {}) : /*#__PURE__*/ _jsx("img", {
2564
2602
  src: knowledge_icon
2565
2603
  }) : /*#__PURE__*/ _jsx("img", {
2566
2604
  src: headImg
@@ -2666,17 +2704,17 @@ const CustomerService = (props)=>{
2666
2704
  })
2667
2705
  ]
2668
2706
  }),
2669
- !item.quotedMessage && item.extraInfo && JSON.parse(item.extraInfo).length > 0 && JSON.parse(item.extraInfo)[0].key == "imageUrl" && /*#__PURE__*/ _jsxs("p", {
2670
- className: `${styles.img_con} ${showType == 2 || showType == 4 ? styles.img_con2 : ""}`,
2707
+ !item.quotedMessage && item.extraInfo && JSON.parse(item.extraInfo).length > 0 && JSON.parse(item.extraInfo).find((x)=>x.key == "imageUrl") && /*#__PURE__*/ _jsxs("p", {
2708
+ className: `${styles.img_con} ${showType == 2 || showType == 4 ? styles.img_con2 : ''}`,
2671
2709
  children: [
2672
2710
  /*#__PURE__*/ _jsx("img", {
2673
- src: JSON.parse(item.extraInfo)[0].value
2711
+ src: JSON.parse(item.extraInfo).find((x)=>x.key == "imageUrl").value
2674
2712
  }),
2675
2713
  /*#__PURE__*/ _jsx("div", {
2676
2714
  className: styles.mask_zoom,
2677
2715
  children: /*#__PURE__*/ _jsx(ZoomInOutlined, {
2678
2716
  onClick: ()=>{
2679
- setViewBase64(JSON.parse(item.extraInfo)[0].value);
2717
+ setViewBase64(JSON.parse(item.extraInfo).find((x)=>x.key == "imageUrl").value);
2680
2718
  setVisible(true);
2681
2719
  }
2682
2720
  })
@@ -3284,44 +3322,48 @@ const CustomerService = (props)=>{
3284
3322
  };
3285
3323
  //发送截图信息
3286
3324
  const sendScreenshotData = (message)=>{
3287
- if (contactsList.length > 0 && contactsList[0].roomId == roomId) {
3288
- setKeyWord("");
3289
- setCitationContent({});
3290
- setBottomRecommendationQuestions([]);
3291
- setHistoryMessageList((historyMessageList)=>{
3292
- let newHistoryMessageList = historyMessageList.concat({
3293
- id: 'p' + new Date().getTime(),
3325
+ if (userData.modules.some((item)=>item.short == "AIservice")) {
3326
+ if (contactsList.length > 0 && contactsList[0].roomId == roomId) {
3327
+ setKeyWord("");
3328
+ setCitationContent({});
3329
+ setBottomRecommendationQuestions([]);
3330
+ setHistoryMessageList((historyMessageList)=>{
3331
+ let newHistoryMessageList = historyMessageList.concat({
3332
+ id: 'p' + new Date().getTime(),
3333
+ roomId: roomId,
3334
+ sender: mid,
3335
+ recevier: 'AI',
3336
+ message: message,
3337
+ createdAt: getDataTime(-1),
3338
+ extraInfo: JSON.stringify([
3339
+ {
3340
+ key: "imageUrl",
3341
+ value: screenshotBese64
3342
+ }
3343
+ ])
3344
+ });
3345
+ return newHistoryMessageList;
3346
+ });
3347
+ //ai窗口
3348
+ aiSendQuestions(3, {
3349
+ //相关数据
3294
3350
  roomId: roomId,
3295
- sender: mid,
3296
- recevier: 'AI',
3297
3351
  message: message,
3298
- createdAt: getDataTime(-1),
3299
- extraInfo: JSON.stringify([
3300
- {
3301
- key: "imageUrl",
3302
- value: screenshotBese64
3303
- }
3304
- ])
3305
- });
3306
- return newHistoryMessageList;
3307
- });
3308
- //ai窗口
3309
- aiSendQuestions(3, {
3310
- //相关数据
3311
- roomId: roomId,
3312
- message: message,
3313
- image: screenshotBese64,
3314
- quotedMessage: citationContent.content || "",
3315
- regenerate: citationContent.content != "" ? false : true,
3316
- generateUpvoteOrDownvoteMessage: false
3317
- }, 1);
3318
- setScreenshotBese64('');
3352
+ image: screenshotBese64,
3353
+ quotedMessage: citationContent.content || "",
3354
+ regenerate: citationContent.content != "" ? false : true,
3355
+ generateUpvoteOrDownvoteMessage: false
3356
+ }, 1);
3357
+ setScreenshotBese64('');
3358
+ } else {
3359
+ //老师窗口
3360
+ sendToTeacher(3, message);
3361
+ }
3362
+ scrollToBottom();
3363
+ resettingBottomHei();
3319
3364
  } else {
3320
- //老师窗口
3321
- sendToTeacher(3, message);
3365
+ sendGreetingMessage(4, message);
3322
3366
  }
3323
- scrollToBottom();
3324
- resettingBottomHei();
3325
3367
  };
3326
3368
  //渲染底部按钮
3327
3369
  const renderBottomAnt = ()=>{
@@ -1,5 +1,9 @@
1
1
  const parseDate = (dateStr)=>{
2
- const date = new Date(dateStr); // 创建一个日期对象,表示当前时间
2
+ let date = new Date(dateStr); // 创建一个日期对象,表示当前时间
3
+ // @ts-ignore
4
+ if (date == "Invalid Date") {
5
+ date = new Date();
6
+ }
3
7
  const year = date.getFullYear().toString(); // 获取年份
4
8
  const month = String(date.getMonth() + 1).padStart(2, "0"); // 获取月份,并补齐两位数
5
9
  const day = String(date.getDate()).padStart(2, "0"); // 获取日期,并补齐两位数
@@ -140,9 +140,12 @@ var getBase64Image = function(src) {
140
140
  };
141
141
  var formatDate = function(dateStr) {
142
142
  var today = new Date();
143
+ today.setHours(0, 0, 0, 0); // 将时间部分设为0,只比较日期
143
144
  var date = new Date(dateStr);
145
+ var cloneDate = new Date(dateStr);
146
+ cloneDate.setHours(0, 0, 0, 0); // 将时间部分设为0,只比较日期
144
147
  var isSameDay = today.getFullYear() === date.getFullYear() && today.getMonth() === date.getMonth() && today.getDate() === date.getDate();
145
- var dayDiff = Math.ceil((today - date) / (1000 * 60 * 60 * 24)); // 计算天数差
148
+ var dayDiff = Math.ceil((today - cloneDate) / (1000 * 60 * 60 * 24)); // 计算天数差
146
149
  // 判断当前的日期 是否于传入的日期为同一天 同一天则显示时间 不是同一天则判断是否超过一周
147
150
  // console.log(dayDiff,'dayDiffdayDiff',today,'___',date);
148
151
  if (isSameDay) {
@@ -150,7 +153,7 @@ var formatDate = function(dateStr) {
150
153
  return date.toLocaleTimeString("zh-CN", {
151
154
  hour12: false
152
155
  }).substring(0, 5);
153
- } else if (dayDiff <= 7) {
156
+ } else if (dayDiff < 7) {
154
157
  // 一周内
155
158
  return date.toLocaleString("zh-CN", {
156
159
  weekday: "short"