wujingjing
2024-09-20 635c207f171dcfa5dbb03422d807f12c786da354
src/components/chat/Chat.vue
@@ -1,5 +1,5 @@
<template>
   <div class="flex h-full">
   <div class="flex h-full px-5">
      <div class="flex flex-col h-full flex-auto">
         <div class="h-full flex flex-col items-center overflow-y-auto">
            <div ref="chatListDom" class="h-full" :style="{ width: chatWidth }">
@@ -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"
@@ -76,7 +76,7 @@
                                    @click="copyClick(item)"
                                 />
                              </div>
                              <template v-if="item.content.errCode !== ErrorCode.Message">
                              <!-- <template v-if="item.content.errCode !== ErrorCode.Message">
                                 <div class="flex items-center justify-center size-[15px]">
                                    <i
                                       :class="{ 'text-[#0284ff]': item.state === AnswerState.Like }"
@@ -91,9 +91,9 @@
                                       @click="unLikeClick(item)"
                                    />
                                 </div>
                              </template>
                              </template> -->
                              <div class="flex items-center justify-center size-[15px] relative">
                              <!-- <div class="flex items-center justify-center size-[15px] relative">
                                 <i
                                    class="p-2 ywifont ywicon-wentifankui cursor-pointer hover:text-[#0284ff] !text-[13px] hover:!text-[15px]"
                                    @click="
@@ -115,11 +115,11 @@
                                    :chatItem="currentFeedbackMapItem"
                                    :position="feedbackPosition"
                                 />
                              </div>
                              </div> -->
                           </div>
                        </div>
                        <Loading v-if="isTalking && index === messageList.length - 1" class="w-fit" />
                        <Loading v-if="isTalking && index === messageList.length - 1" class="w-fit my-auto" />
                     </div>
                  </div>
               </div>
@@ -139,7 +139,7 @@
            </div>
         </div>
         <div class="sticky bottom-0 w-full p-6 pb-8 bg-[rgb(247,248,250)] flex justify-center">
         <div class="sticky bottom-0 w-full py-6 flex justify-center">
            <PlayBar
               v-model:voicePageIsShow="voicePageIsShow"
               :isTalking="isTalking"
@@ -157,8 +157,8 @@
<script setup lang="ts">
import _ from 'lodash';
import type { PropType } from 'vue';
import { computed, ref } from 'vue';
import FeedbackPanel from './components/FeedbackPanel.vue';
import Loading from './components/Loading/Loading.vue';
import { useAssistantContentOpt } from './hooks/useAssistantContentOpt';
import { useScrollToBottom } from './hooks/useScrollToBottom';
@@ -167,13 +167,13 @@
import { GetHistoryAnswer, extCallQuery } from '/@/api/ai/chat';
import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
import { ErrorCode } from '/@/utils/request';
import { checkSupervisorValidate } from '/@/api/supervisorAdmin';
import { CancelTokenSource } from 'axios';
const emit = defineEmits<{
   (event: 'question',inputText): any;
}>();
const props = defineProps({
   questionApi: Function as PropType<(text: string, sourceObj: { source: CancelTokenSource }) => any>,
});
const chatWidth = '75%';
const chatWidth = '100%';
const voicePageIsShow = ref(false);
let isTalking = ref(false);
let messageContent = ref<ChatContent>({
@@ -193,7 +193,6 @@
      type: AnswerType.Text,
      values: '解析失败!',
   };
   switch (res.answer_type) {
      case AnswerType.RecordSet:
         content = {
@@ -248,14 +247,13 @@
};
let questionRes = null;
const questionAi = async (text) => {
   const params = {
      id: 'net3_summary',
      question: text,
   } as any;
// 作为参数传进去,携带参数出来
let lastSourceObj: { source: CancelTokenSource } = {
   source:null
};
   // const res = await emit('question',text);
   const res = await checkSupervisorValidate(params);
const questionAi = async (text) => {
   const res = await props.questionApi(text, lastSourceObj);
   questionRes = res?.values;
   const content = parseContent(res?.values);
   return content;
@@ -272,11 +270,9 @@
      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;
   let resMsgContent: ChatContent = null;
   try {
@@ -312,7 +308,7 @@
   }
};
const sendClick = (cb) => {
const sendClick = (cb?) => {
   sendChatMessage(messageContent.value, cb);
};
const appendLastMessageContent = (content: ChatContent) => {
@@ -326,6 +322,23 @@
   displayMessageList: computedMessageList,
});
const autoSend = (text) => {
   messageContent.value.values = text;
   sendClick();
};
const clearContent = () => {
   lastSourceObj.source?.cancel();
   messageList.value = [];
   // 清空输入框
   clearMessageContent();
};
defineExpose({
   autoSend,
   clear: clearContent,
});
//#region ====================== 关联查询 ======================
// const relativeQueryClick = async (val) => {
//    sendChatMessage(