| | |
| | | const computedMessageList = computed(() => { |
| | | return messageList.value.filter((v) => v.role !== RoleEnum.system); |
| | | }); |
| | | // onMounted(() => { |
| | | // if (!activeChatRoom.value) { |
| | | // router.replace({ |
| | | // name: 'Home', |
| | | // }); |
| | | // return; |
| | | // } |
| | | // messageContent.value = { |
| | | // type: AnswerType.Text, |
| | | // values: activeChatRoom.value.title, |
| | | // }; |
| | | // sendChatMessage(); |
| | | // }); |
| | | |
| | | const getAnswerById = async (historyId: string) => { |
| | | return await GetHistoryAnswer({ |
| | | history_id: historyId, |
| | | }); |
| | | }; |
| | | let currentSectionId = ''; |
| | | watch( |
| | | () => activeRoomId.value, |
| | | async (val) => { |
| | | if (!val) { |
| | | router.replace({ |
| | | name: 'Home', |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | const res = await QueryHistoryDetail({ |
| | | history_group_id: activeRoomId.value, |
| | | }); |
| | | messageList.value = (res.details ?? []).map((item) => { |
| | | return { |
| | | role: RoleEnum.user, |
| | | content: { |
| | | type: AnswerType.Text, |
| | | values: item.question, |
| | | }, |
| | | } as ChatMessage; |
| | | }); |
| | | currentSectionId = res?.details?.[0]?.section_a_id; |
| | | const resList = await Promise.all((res.details ?? []).map((item) => getAnswerById(item.history_id))); |
| | | let i = 0; |
| | | |
| | | resList.map((item, index) => { |
| | | const insertIndex = index + 1 + i; |
| | | messageList.value.splice(insertIndex, 0, { |
| | | role: RoleEnum.assistant, |
| | | content: parseContent(item.answer), |
| | | }); |
| | | i++; |
| | | }); |
| | | |
| | | }, |
| | | { |
| | | immediate: true, |
| | | } |
| | | ); |
| | | |
| | | const parseContent = (res) => { |
| | | let content: ChatContent = { |
| | |
| | | const questionAi = async (text) => { |
| | | const res = await QuestionAi({ |
| | | question: text, |
| | | section_a_id: currentSectionId, |
| | | // FIXME: 暂时这样 |
| | | section_a_id: 'undefined', |
| | | history_group_id: activeRoomId.value, |
| | | }); |
| | | // const res = { |
| | |
| | | return content; |
| | | }; |
| | | |
| | | const clearMessageContent = () => |
| | | (messageContent.value = { |
| | | type: AnswerType.Text, |
| | | values: '', |
| | | }); |
| | | |
| | | const scrollToBottom = () => { |
| | | if (!chatListDom.value) return; |
| | | chatListDom.value.lastElementChild?.scrollIntoView(); |
| | | }; |
| | | |
| | | const getAnswerById = async (historyId: string) => { |
| | | return await GetHistoryAnswer({ |
| | | history_id: historyId, |
| | | }); |
| | | }; |
| | | const sendChatMessage = async (content: ChatContent = messageContent.value) => { |
| | | if (!messageContent.value?.values) return; |
| | | if (activeChatRoom.value.isInitial) { |
| | |
| | | isTalking.value = false; |
| | | } |
| | | }; |
| | | |
| | | const appendLastMessageContent = (content: ChatContent) => { |
| | | if(messageList.value.at(-1)){ |
| | | messageList.value.at(-1).content = content; |
| | | }; |
| | | |
| | | const clearMessageContent = () => |
| | | (messageContent.value = { |
| | | type: AnswerType.Text, |
| | | values: '', |
| | | } |
| | | }; |
| | | let currentSectionId = ''; |
| | | watch( |
| | | () => activeRoomId.value, |
| | | async (val) => { |
| | | if (!val) { |
| | | router.replace({ |
| | | name: 'Home', |
| | | }); |
| | | |
| | | const scrollToBottom = () => { |
| | | if (!chatListDom.value) return; |
| | | chatListDom.value.lastElementChild?.scrollIntoView(); |
| | | return; |
| | | } |
| | | if (activeChatRoom.value.isInitial) { |
| | | messageContent.value = { |
| | | type: AnswerType.Text, |
| | | values: activeChatRoom.value.title, |
| | | }; |
| | | console.log("🚀 ~ activeChatRoom.value.title:", activeChatRoom.value.title) |
| | | sendChatMessage(); |
| | | } else { |
| | | const res = await QueryHistoryDetail({ |
| | | history_group_id: activeRoomId.value, |
| | | }); |
| | | messageList.value = (res.details ?? []).map((item) => { |
| | | return { |
| | | role: RoleEnum.user, |
| | | content: { |
| | | type: AnswerType.Text, |
| | | values: item.question, |
| | | }, |
| | | } as ChatMessage; |
| | | }); |
| | | currentSectionId = res?.details?.[0]?.section_a_id; |
| | | const resList = await Promise.all((res.details ?? []).map((item) => getAnswerById(item.history_id))); |
| | | let i = 0; |
| | | |
| | | resList.map((item, index) => { |
| | | const insertIndex = index + 1 + i; |
| | | messageList.value.splice(insertIndex, 0, { |
| | | role: RoleEnum.assistant, |
| | | content: parseContent(item.answer), |
| | | }); |
| | | i++; |
| | | }); |
| | | } |
| | | }, |
| | | { |
| | | immediate: true, |
| | | } |
| | | ); |
| | | |
| | | watch( |
| | | messageList, |