wujingjing
2024-10-09 0e1d9c99e8a7c266225d7d9e132637771579b204
src/components/chat/Chat.vue
@@ -17,7 +17,7 @@
                     srcset=""
                  />
                  <div class="flex-auto flex" :class="{ 'justify-end': item.role === RoleEnum.user }">
                     <div class="inline-flex flex-col" :class="{ 'w-full': item.role === RoleEnum.assistant }">
                     <div class="inline-flex flex-col w-full" :class="{ 'w-full': item.role === RoleEnum.assistant }">
                        <div class="w-full" v-if="item.content?.values">
                           <div
                              class="text-sm rounded-[6px] p-4 leading-relaxed"
@@ -119,7 +119,7 @@
                           </div>
                        </div>
                        <Loading v-if="isTalking && index === messageList.length - 1" class="w-fit" />
                        <Loading v-if="isTalking && index === computedMessageList.length - 1" class="w-fit my-auto" />
                     </div>
                  </div>
               </div>
@@ -139,7 +139,7 @@
            </div>
         </div>
         <div class="sticky bottom-0 w-full pb-3 flex justify-center">
         <div class="sticky bottom-0 w-full py-6 flex justify-center">
            <PlayBar
               v-model:voicePageIsShow="voicePageIsShow"
               :isTalking="isTalking"
@@ -167,11 +167,10 @@
import { GetHistoryAnswer, extCallQuery } from '/@/api/ai/chat';
import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
import { ErrorCode } from '/@/utils/request';
import { CancelTokenSource } from 'axios';
const props = defineProps({
   questionApi: Function as PropType<(...params: any[]) => any>,
   questionApi: Function as PropType<(text: string, sourceObj: { source: CancelTokenSource }) => any>,
});
const chatWidth = '100%';
@@ -194,7 +193,6 @@
      type: AnswerType.Text,
      values: '解析失败!',
   };
   switch (res.answer_type) {
      case AnswerType.RecordSet:
         content = {
@@ -249,8 +247,13 @@
};
let questionRes = null;
// 作为参数传进去,携带参数出来
let lastSourceObj: { source: CancelTokenSource } = {
   source:null
};
const questionAi = async (text) => {
   const res = await props.questionApi(text);
   const res = await props.questionApi(text, lastSourceObj);
   questionRes = res?.values;
   const content = parseContent(res?.values);
   return content;
@@ -267,7 +270,6 @@
      history_id: historyId,
   });
};
const sendChatMessage = async (content: ChatContent = messageContent.value, cb?: any, isCallExtParams?: any) => {
   if (!content?.values || isTalking.value) return;
   const isNewChat = messageList.value.length === 0;
@@ -326,6 +328,7 @@
};
const clearContent = () => {
   lastSourceObj.source?.cancel();
   messageList.value = [];
   // 清空输入框
   clearMessageContent();
@@ -333,7 +336,7 @@
defineExpose({
   autoSend,
   clear:clearContent
   clear: clearContent,
});
//#region ====================== 关联查询 ======================