| | |
| | | <template> |
| | | <ChatContainer |
| | | :loading="chatListLoading" |
| | | :more-is-loading="moreIsLoading" |
| | | :is-share-page="isSharePage" |
| | | :chat-width="chatWidth" |
| | | ref="containerRef" |
| | | > |
| | | <ChatContainer :loading="chatListLoading" :more-is-loading="moreIsLoading" :is-share-page="isSharePage" ref="containerRef"> |
| | | <!-- 消息列表 --> |
| | | <template #message-list> |
| | | <MessageList |
| | |
| | | import moment from 'moment'; |
| | | import { computed, onActivated, onMounted, ref } from 'vue'; |
| | | import { loadAmisSource } from '../amis/load'; |
| | | import { convertProcessItem, convertProcessToStep, formatShowTimeYear, useScrollLoad } from './hooks/useScrollLoad'; |
| | | import { useScrollLoad } from './hooks/useScrollLoad'; |
| | | import type { ChatContent } from './model/types'; |
| | | import { AnswerState, AnswerType, RoleEnum, type ChatMessage } from './model/types'; |
| | | import { getShareChatJsonByPost, questionStreamByPost } from '/@/api/ai/chat'; |
| | |
| | | import emitter from '/@/utils/mitt'; |
| | | import { useCompRef } from '/@/utils/types'; |
| | | import { toMyFixed } from '/@/utils/util'; |
| | | import { useLoadData } from './hooks/useLoadData'; |
| | | import { useSyncMsg } from './hooks/useSyncMsg'; |
| | | const containerRef = useCompRef(ChatContainer); |
| | | const chatListDom = computed(() => containerRef.value?.chatListDom); |
| | | const chatWidth = '75%'; |
| | | |
| | | const { loadReplyData, parseContent, parseExtraContent, convertProcessItem, convertProcessToStep, formatShowTimeYear } = useLoadData(); |
| | | const voicePageIsShow = ref(false); |
| | | let isTalking = ref(false); |
| | | |
| | | const chatWidth = computed(() => containerRef.value?.chatWidth); |
| | | let messageContent = ref<ChatContent>({ |
| | | type: AnswerType.Text, |
| | | values: '', |
| | |
| | | const computedMessageList = computed(() => { |
| | | return messageList.value.filter((v) => !!v); |
| | | }); |
| | | |
| | | const parseExtraContent = (res) => { |
| | | if (!res) return {}; |
| | | const askMoreList = orderBy(res.context_history, [(item) => Number(item.radio)], ['desc']); |
| | | const errCode = res?.err_code; |
| | | const errMsg = res?.json_msg; |
| | | const origin = res; |
| | | |
| | | return { |
| | | askMoreList, |
| | | errCode, |
| | | errMsg, |
| | | origin, |
| | | }; |
| | | }; |
| | | |
| | | const parseContent = (res, reportIsShow = false, extraContent?) => { |
| | | if (!res) return null; |
| | | let content: ChatContent = { |
| | | type: AnswerType.Text, |
| | | values: '解析失败!', |
| | | }; |
| | | if (res.type) { |
| | | res.answer_type = res.type; |
| | | } |
| | | const curExtraContent = parseExtraContent(res); |
| | | |
| | | switch (res.answer_type) { |
| | | case AnswerType.RecordSet: |
| | | content = { |
| | | type: AnswerType.RecordSet, |
| | | values: res.values, |
| | | }; |
| | | break; |
| | | case AnswerType.Text: |
| | | content = { |
| | | type: AnswerType.Text, |
| | | values: res.values ?? res.answer, |
| | | }; |
| | | break; |
| | | case AnswerType.Script: |
| | | content = { |
| | | type: AnswerType.Script, |
| | | values: res, |
| | | }; |
| | | break; |
| | | |
| | | case AnswerType.Knowledge: |
| | | content = { |
| | | type: AnswerType.Knowledge, |
| | | values: res.knowledge, |
| | | }; |
| | | |
| | | break; |
| | | case AnswerType.Report: |
| | | content = { |
| | | type: AnswerType.Report, |
| | | values: (res?.reports ?? []).map((item) => ({ |
| | | content: parseContent(item, reportIsShow, { origin: item, conclusion: item.conclusion ?? [] }), |
| | | })), |
| | | }; |
| | | break; |
| | | |
| | | case AnswerType.Summary: |
| | | content = { |
| | | type: AnswerType.Summary, |
| | | values: res.summary?.map((item) => { |
| | | item.reportIsShow = reportIsShow; |
| | | return item; |
| | | }), |
| | | }; |
| | | break; |
| | | case AnswerType.Url: |
| | | content = { |
| | | type: AnswerType.Url, |
| | | values: res.url, |
| | | }; |
| | | break; |
| | | case AnswerType.Map: |
| | | content = { |
| | | type: AnswerType.Map, |
| | | values: res.values, |
| | | }; |
| | | break; |
| | | default: |
| | | content = { |
| | | type: AnswerType.Text, |
| | | values: '解析失败!', |
| | | }; |
| | | break; |
| | | } |
| | | if (!extraContent) { |
| | | content = { |
| | | ...content, |
| | | ...curExtraContent, |
| | | }; |
| | | } else { |
| | | content = { |
| | | ...content, |
| | | ...extraContent, |
| | | }; |
| | | } |
| | | |
| | | return content; |
| | | }; |
| | | |
| | | let questionRes = null; |
| | | let position = null; |
| | |
| | | const getLastGroup = () => { |
| | | const lastGroup = computedMessageList.value.at(-1).stepGroup.at(-1); |
| | | return lastGroup; |
| | | } |
| | | }; |
| | | const getLastStepList = () => { |
| | | const stepList = getLastGroup()?.value ?? []; |
| | | return stepList; |
| | |
| | | scrollToBottom(); |
| | | return; |
| | | } |
| | | |
| | | |
| | | |
| | | // 暂时不考虑多个 report情况 |
| | | |
| | |
| | | updateLoadIndex(); |
| | | |
| | | userItem.historyId = questionRes?.history_id; |
| | | const current = moment().format('YYYY-MM-DD HH:mm:ss'); |
| | | userItem.createTime = current; |
| | | userItem.content.values = questionRes?.question ?? userItem.content.values; |
| | | assistantItem.historyId = questionRes?.history_id; |
| | | const currentTime = formatShowTimeYear(moment().format('YYYY-MM-DD HH:mm:ss')); |
| | | const currentTime = formatShowTimeYear(current); |
| | | assistantItem.createTime = currentTime; |
| | | assistantItem.content = resMsgContent; |
| | | setTimeout(() => { |
| | |
| | | container: chatListDom, |
| | | historyGroupId: currentRouteId, |
| | | messageList, |
| | | parseAnswerContent: parseContent, |
| | | loadReplyData, |
| | | }); |
| | | |
| | | useSyncMsg({ |
| | | msgList: computedMessageList, |
| | | updateLoadIndex, |
| | | historyGroupId: currentRouteId, |
| | | }); |
| | | const chatListLoading = ref(true); |
| | | |
| | | onActivated(() => { |
| | |
| | | } |
| | | loadAmisSource(); |
| | | }); |
| | | |
| | | |
| | | |
| | | const askMoreClick = (item) => { |
| | | if (!item.question) return; |