wujingjing
2024-12-31 8e6b518811a52e8c2d783ff6bb7d263783954eac
src/components/chat/hooks/useScrollLoad.ts
@@ -46,7 +46,25 @@
   }, []);
   return stepList;
};
export const formatShowTimeYear = (str: string) => {
   const date = moment(str);
   const now = moment();
   const diffDays = now.diff(date, 'days');
   if (diffDays === 0) {
      return `今天 ${date.format('HH:mm:ss')}`;
   } else if (diffDays === 1) {
      return `昨天 ${date.format('HH:mm:ss')}`;
   } else if (diffDays === 2) {
      return `前天 ${date.format('HH:mm:ss')}`;
   }
   if (date.year() === now.year()) {
      return date.format('MM月DD日 HH:mm:ss');
   } else {
      return date.format('YYYY年MM月DD日 HH:mm:ss');
   }
};
/**
 * 滚动加载数据
 * @returns
@@ -65,11 +83,8 @@
         history_id: historyId,
      });
   };
   const formatShowTimeYear = computed(() => {
      return (str) => {
         return moment(str).format('MM月DD日 HH:mm:ss');
      };
   });
   /**
    * 更新加载索引
@@ -108,7 +123,7 @@
         const mapUser = userItemIdMap.get(item.answer?.history_id);
         const answerTime = formatShowTimeYear.value(mapUser?.create_time);
         const answerTime = formatShowTimeYear(mapUser?.create_time);
         tmpMessageList.splice(
            insertIndex,
            0,
@@ -119,7 +134,6 @@
                     role: RoleEnum.assistant,
                     content: parseAnswerContent(item?.answer),
                     state: item.answer_state,
                     sectionAId: mapUser?.section_a_id,
                     createTime: answerTime,
                     isStopMsg: false,
                     stepGroup: (item?.answer?.reports ?? []).map((item) => ({
@@ -137,53 +151,13 @@
      messageList.value.unshift(...tmpMessageList);
   };
   /**
    * 加载分享数据
    */
   const loadShareData = async () => {
      const res = await getShareChatJsonByPost({
         share_id: router.currentRoute.value.query.id as string,
      });
      const msgValue = res?.values;
      if (!msgValue) {
         messageList.value = [];
         return;
      }
      const userMsg: ChatMessage = {
         historyId: msgValue.history_id,
         role: RoleEnum.user,
         content: {
            type: AnswerType.Text,
            values: msgValue.question,
         },
         isChecked: false,
      };
      const assistantMsg: ChatMessage = {
         historyId: msgValue.history_id,
         role: RoleEnum.assistant,
         content: parseAnswerContent(msgValue),
         stepGroup: (msgValue?.reports ?? []).map((item) => ({
            value: convertProcessToStep(item?.exec_process),
            isShow: false,
         })),
         isStopMsg: false,
         conclusion: msgValue.conclusion ?? [],
         isChecked: false,
      };
      messageList.value = [userMsg, assistantMsg];
   };
   /**
    * 加载滚动范围数据
    */
   const loadRangeData = async (lastEnd = nextUserMsgEndIndex) => {
      if (isSharePage.value) {
         await loadShareData();
         return;
      }
      const res = await QueryHistoryDetail({
         history_group_id: unref(historyGroupId),
         last_end: lastEnd,