wujingjing
2024-11-08 1711b75cf4e9f706be461c2be82edf760b28d3bd
src/components/chat/hooks/useScrollLoad.ts
@@ -2,7 +2,9 @@
import { Ref, ShallowRef, computed, nextTick, onBeforeUnmount, ref, unref } from 'vue';
import { LOAD_CHAT_LIMIT } from '../constants';
import { AnswerType, ChatContent, ChatMessage, RoleEnum, StepEnum, StepItem } from '../model/types';
import { GetHistoryAnswer, QueryHistoryDetail } from '/@/api/ai/chat';
import { GetHistoryAnswer, QueryHistoryDetail, getShareChatJsonByPost } from '/@/api/ai/chat';
import router from '/@/router';
import { isSharePage } from '/@/stores/chatRoom';
type UseScrollLoadOption = {
   container: ShallowRef<HTMLDivElement>;
   historyGroupId: string | Ref<string>;
@@ -23,7 +25,7 @@
   };
};
export const convertProcessToStep = (process: any[]) => {
   const stepList = (process??[]).map<StepItem>((item) => {
   const stepList = (process ?? []).map<StepItem>((item) => {
      return convertProcessItem(item);
   });
   return stepList;
@@ -65,7 +67,7 @@
               type: AnswerType.Text,
               values: item.question,
            },
            isChecked:false,
            isChecked: false,
         } as ChatMessage;
      });
      const resList = await Promise.all(
@@ -79,7 +81,7 @@
         const insertIndex = index + 1 + i;
         const currentUserMsg = tmpMessageList[insertIndex - 1];
         currentUserMsg.content.values = item?.answer?.question ?? currentUserMsg.content.values;
         const mapUser = userItemIdMap.get(item.answer?.history_id);
         const answerTime = formatShowTimeYear.value(mapUser?.create_time);
@@ -96,9 +98,9 @@
                     sectionAId: mapUser?.section_a_id,
                     createTime: answerTime,
                     stepList: convertProcessToStep(item?.answer?.exec_process),
                     stepIsShow:false,
                     conclusion:item?.answer?.conclusion ??[],
                     isChecked:false,
                     stepIsShow: false,
                     conclusion: item?.answer?.conclusion ?? [],
                     isChecked: false,
                 }
         );
         i++;
@@ -108,9 +110,48 @@
   };
   /**
    * 加载分享数据
    */
   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),
         stepList: convertProcessToStep(msgValue.exec_process),
         stepIsShow: false,
         conclusion: msgValue.conclusion ?? [],
         isChecked: false,
      };
      messageList.value = [userMsg, assistantMsg];
   };
   /**
    * 加载滚动范围数据
    */
   const loadRangeData = async (lastEnd = nextUserMsgEndIndex.value) => {
      if (isSharePage.value) {
         await loadShareData();
         return;
      }
      const res = await QueryHistoryDetail({
         history_group_id: unref(historyGroupId),
         last_end: lastEnd,