wujingjing
2025-04-07 07f5e49d4031f74c296fe01bb79e913c864979e5
src/components/chat/hooks/useSyncMsg.ts
@@ -4,6 +4,8 @@
import { RoleEnum, type ChatMessage } from '../model/types';
import { QueryHistoryDetail } from '/@/api/ai/chat';
import { sseClient } from '/@/stores/global';
import { Logger } from '/@/model/logger/Logger';
import { ElNotification } from 'element-plus';
type UseSyncMsgOptions = {
   updateLoadIndex: (addCount: number) => void;
@@ -12,10 +14,11 @@
   checkCanSync: (data: any) => boolean;
   loadReplyData: (data: any) => Promise<ChatMessage[]>;
   scrollToBottom: () => void;
   showTip: (data: any) => void;
};
export const useSyncMsg = (options: UseSyncMsgOptions) => {
   const { updateLoadIndex, msgList, historyGroupId, checkCanSync, loadReplyData, scrollToBottom } = options;
   const { updateLoadIndex, msgList, historyGroupId, checkCanSync, loadReplyData, scrollToBottom, showTip } = options;
   const insertSyncMsg = (replayData: any[]) => {
      const insertResult: { index: number; item: any }[] = [];
@@ -39,10 +42,21 @@
         msgList.value.splice(resultItem.index, 0, ...resultItem.item);
      });
   };
   const historyUpdate = async (data: any) => {
      if (!checkCanSync(data)) return;
      if (!data) return;
      if (data?.type === 'chat_start') {
         const groupId = unref(historyGroupId);
         const startGroupId = data?.history_group_id;
         if (groupId !== startGroupId) return;
         const isDigitalHuman = data?.is_digital_human;
         if (!isDigitalHuman) {
            showTip(data);
         }
      }
      if (data?.type === 'chat_history_id') {
         const groupId = unref(historyGroupId);
         if (!groupId) return;
@@ -74,6 +88,7 @@
         updateLoadIndex(unSyncedHistoryIds.length);
         scrollToBottom();
      }
   };
   onActivated(() => {