yangyin
2024-11-08 b5e920831f3e2ea94c809b0dd99f08c16d9feceb
src/components/chat/hooks/useAssistantContentOpt.ts
@@ -6,17 +6,18 @@
import { AnswerState, AnswerType, RoleEnum } from '../model/types';
import { SetHistoryAnswerState } from '/@/api/ai/chat';
import { useClickOther } from '/@/hooks/useClickOther';
import { onClickOutside } from '@vueuse/core';
import { chatDisplayMode } from '/@/stores/chatRoom';
export type AssistantContentOptOption = {
   forbidScroll: Ref<boolean>;
   sendChatMessage: any;
   displayMessageList: ComputedRef<ChatMessage[]>;
};
export const useAssistantContentOpt = (option: AssistantContentOptOption) => {
   const { forbidScroll, sendChatMessage, displayMessageList } = option;
   const { sendChatMessage, displayMessageList } = option;
   const { toClipboard } = useClipboard();
   const isNextChat = ref(false);
   const preQuestion = ref(null);
   const copyClick = (item) => {
      const type = item.content.type;
@@ -37,10 +38,7 @@
         answer_state: toSetState,
      });
      item.state = toSetState;
      forbidScroll.value = true;
      nextTick(() => {
         forbidScroll.value = false;
      });
   };
   const unLikeClick = async (item) => {
@@ -51,10 +49,7 @@
      });
      item.state = toSetState;
      forbidScroll.value = true;
      nextTick(() => {
         forbidScroll.value = false;
      });
   };
   const feedbackPosition = ref({
      x: 0,
@@ -79,19 +74,27 @@
         };
      });
   };
   useClickOther(
      computed(() => feedbackPanelRef.value[curFeedbackIndex.value]),
      feedbackIsShow,
      () => {
   onClickOutside(
      computed(() => feedbackPanelRef.value?.[curFeedbackIndex.value]),
      (e) => {
         feedbackIsShow.value = false;
         feedbackContent.value = '';
      }
   );
   // useClickOther(
   //    computed(() => feedbackPanelRef.value?.[curFeedbackIndex.value]),
   //    feedbackIsShow,
   //    () => {
   //       feedbackIsShow.value = false;
   //       feedbackContent.value = '';
   //    }
   // );
   const showAskMore = computed(() => {
      if (!displayMessageList.value || displayMessageList.value.length === 0) return false;
      const last = displayMessageList.value.at(-1);
      const isShow = last?.role === RoleEnum.assistant && last?.content?.values && last.content?.askMoreList?.length > 0;
      return isShow;
      return isShow && chatDisplayMode.value ==='default' ;
   });
   const showFixQuestion = (item) => {
@@ -103,16 +106,16 @@
      sendChatMessage({ type: AnswerType.Text, values: item.question });
   };
   const fixQuestionClick = (item) => {
   const fixQuestionClick = (item, originData) => {
      if (!item.question) return;
      isNextChat.value = true;
      preQuestion.value = originData?.question;
      try {
         sendChatMessage({
            type: AnswerType.Text,
            values: item.question,
         });
      } finally {
         isNextChat.value = false;
         preQuestion.value = null;
      }
   };
@@ -129,7 +132,7 @@
      feedbackClick,
      askMoreClick,
      fixQuestionClick,
      isNextChat,
      preQuestion,
      showAskMore,
      showFixQuestion,
   };