| | |
| | | import { ElMessage } from 'element-plus'; |
| | | import type { ComputedRef, Ref } from 'vue'; |
| | | import type { ComputedRef } from 'vue'; |
| | | import { computed, nextTick, ref } from 'vue'; |
| | | import useClipboard from 'vue-clipboard3'; |
| | | // import useClipboard from 'vue-clipboard3'; |
| | | import { onClickOutside, useClipboard } from '@vueuse/core'; |
| | | import type { ChatMessage } from '../model/types'; |
| | | import { AnswerState, AnswerType, RoleEnum } from '../model/types'; |
| | | import { SetHistoryAnswerState } from '/@/api/ai/chat'; |
| | | import { useClickOther } from '/@/hooks/useClickOther'; |
| | | import { isSharePage } 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 { toClipboard } = useClipboard(); |
| | | const isNextChat = ref(false); |
| | | const { sendChatMessage, displayMessageList } = option; |
| | | const { copy } = useClipboard(); |
| | | const preQuestion = ref(null); |
| | | |
| | | const copyClick = (item) => { |
| | | const type = item.content.type; |
| | |
| | | text = item.content.values; |
| | | } |
| | | ElMessage.success('复制成功'); |
| | | toClipboard(text); |
| | | copy(text); |
| | | }; |
| | | |
| | | const likeClick = async (item) => { |
| | |
| | | answer_state: toSetState, |
| | | }); |
| | | item.state = toSetState; |
| | | forbidScroll.value = true; |
| | | nextTick(() => { |
| | | forbidScroll.value = false; |
| | | }); |
| | | }; |
| | | |
| | | const unLikeClick = async (item) => { |
| | |
| | | answer_state: toSetState, |
| | | }); |
| | | item.state = toSetState; |
| | | |
| | | forbidScroll.value = true; |
| | | nextTick(() => { |
| | | forbidScroll.value = false; |
| | | }); |
| | | }; |
| | | const feedbackPosition = ref({ |
| | | x: 0, |
| | |
| | | }; |
| | | }); |
| | | }; |
| | | 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 && !isSharePage; |
| | | }); |
| | | |
| | | const showFixQuestion = (item) => { |
| | | const isShow = item?.role === RoleEnum.assistant && item?.content?.values && item.content?.origin?.err_json?.fix_question; |
| | | const isShow = item?.role === RoleEnum.assistant && item.content?.origin?.sample_question?.length > 0; |
| | | return isShow; |
| | | }; |
| | | const askMoreClick = (item) => { |
| | |
| | | sendChatMessage({ type: AnswerType.Text, values: item.question }); |
| | | }; |
| | | |
| | | const fixQuestionClick = (item) => { |
| | | if (!item.question) return; |
| | | isNextChat.value = true; |
| | | const fixQuestionClick = (item, originData) => { |
| | | if (!item) return; |
| | | // preQuestion.value = originData?.question; |
| | | try { |
| | | sendChatMessage({ |
| | | type: AnswerType.Text, |
| | | values: item.question, |
| | | values: item, |
| | | }); |
| | | } finally { |
| | | isNextChat.value = false; |
| | | // preQuestion.value = null; |
| | | } |
| | | }; |
| | | |
| | |
| | | feedbackClick, |
| | | askMoreClick, |
| | | fixQuestionClick, |
| | | isNextChat, |
| | | preQuestion, |
| | | showAskMore, |
| | | showFixQuestion, |
| | | }; |