|
@@ -10,15 +10,22 @@ import { useScroll } from '@/composables/useScroll';
|
|
|
import { useChat } from '@/composables/useChat';
|
|
|
import { useRecommend } from '@/composables/useRecommend';
|
|
|
|
|
|
+const ANSWER_ID_KEY = '@@id@@';
|
|
|
+
|
|
|
+let controller = new AbortController();
|
|
|
+
|
|
|
// TODO: 如果这里的key不一样,将会在拆一层组件出来 - list
|
|
|
const { recordList, isFetching, onScrolltolower, onReset, addHistoryRecord } = useInfinite({model: 0});
|
|
|
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll();
|
|
|
-const { chatDataSource, addChat, updateChat, clearChat } = useChat();
|
|
|
+const { chatDataSource, addChat, updateChat, clearChat, updateById } = useChat();
|
|
|
const { recommendList } = useRecommend({type: 0});
|
|
|
|
|
|
const message = useMessage();
|
|
|
|
|
|
+const switchActive = ref(true);
|
|
|
+
|
|
|
const isLoading = ref(false);
|
|
|
+const inputRef = ref(null);
|
|
|
|
|
|
const currenSessionId = ref(null);
|
|
|
|
|
@@ -35,35 +42,44 @@ const handleCreateDialog = async () => {
|
|
|
if (!unref(chatDataSource).length) {
|
|
|
return message.info('已切换最新会话');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ inputRef.value.clearInpVal();
|
|
|
+
|
|
|
+ currenSessionId.value = null;
|
|
|
+
|
|
|
clearChat();
|
|
|
}
|
|
|
|
|
|
// 查询对话详情
|
|
|
const handleChatDetail = async ({ sessionId }) => {
|
|
|
isLoading.value = false;
|
|
|
+
|
|
|
+ controller.abort();
|
|
|
+
|
|
|
const { data } = await chatApi.getAnswerHistoryDetail({ sessionId });
|
|
|
- chatDataSource.value = data.map(({ createTime, sessionId, question, answer }) => ({
|
|
|
- createTime,
|
|
|
- sessionId,
|
|
|
- question,
|
|
|
- answer,
|
|
|
- loading: false
|
|
|
- }));
|
|
|
+
|
|
|
+ chatDataSource.value = data.map(item => ({ ...item, loading: false, }));
|
|
|
currenSessionId.value = sessionId;
|
|
|
+
|
|
|
scrollToBottom();
|
|
|
}
|
|
|
|
|
|
const onRegenerate = async ({ question, realQuestion }) => {
|
|
|
+ controller = new AbortController();
|
|
|
+
|
|
|
const sessionId = unref(currenSessionId);
|
|
|
const params = {
|
|
|
data: {
|
|
|
sessionId,
|
|
|
question: realQuestion || question,
|
|
|
+ module: 0,
|
|
|
+ isStrong: Number(unref(switchActive))
|
|
|
},
|
|
|
+ signal: controller.signal,
|
|
|
onDownloadProgress: ({ event }) => {
|
|
|
const xhr = event.target;
|
|
|
- const { responseText: answer } = xhr;
|
|
|
+ const { responseText } = xhr;
|
|
|
+ const [ answer ] = responseText.split(ANSWER_ID_KEY);
|
|
|
|
|
|
updateChat({
|
|
|
sessionId,
|
|
@@ -78,8 +94,12 @@ const onRegenerate = async ({ question, realQuestion }) => {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- const { data: answer } = await chatApi.getChatStream(params);
|
|
|
+ const { data } = await chatApi.getChatStream(params);
|
|
|
+
|
|
|
+ const [ answer, id ] = data.split(ANSWER_ID_KEY);
|
|
|
+
|
|
|
updateChat({
|
|
|
+ id,
|
|
|
sessionId,
|
|
|
question,
|
|
|
answer,
|
|
@@ -87,8 +107,12 @@ const onRegenerate = async ({ question, realQuestion }) => {
|
|
|
delayLoading: false
|
|
|
})
|
|
|
}
|
|
|
+ catch {
|
|
|
+ console.log("取消了请求 - catch");
|
|
|
+ }
|
|
|
finally {
|
|
|
isLoading.value = false;
|
|
|
+ onReset();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -100,7 +124,7 @@ const handleSubmit = async (question, realQuestion = '') => {
|
|
|
const { data: sessionId } = await chatApi.getChatSessionTag();
|
|
|
currenSessionId.value = sessionId;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
isLoading.value = true;
|
|
|
|
|
|
addChat({
|
|
@@ -134,7 +158,6 @@ const handeChatDelete = async (id) => {
|
|
|
<template>
|
|
|
<section class="flex items-start h-full">
|
|
|
<TheSubMenu title="历史记录" @scrollToLower="onScrolltolower" :loading="isFetching">
|
|
|
-
|
|
|
<template #top>
|
|
|
<div class="create-btn px-[11px] pb-[22px]">
|
|
|
<BaseButton @click="handleCreateDialog">新建对话</BaseButton>
|
|
@@ -168,12 +191,25 @@ const handeChatDelete = async (id) => {
|
|
|
<div class="conversation-item" v-if="chatDataSource.length">
|
|
|
<template v-for="item in chatDataSource" :key="item.id">
|
|
|
<ChatAsk :content="item.question"></ChatAsk>
|
|
|
- <ChatAnswer :content="item.answer" :loading="item.loading" :delay-loading="item.delayLoading"></ChatAnswer>
|
|
|
+ <ChatAnswer
|
|
|
+ :id="item.id"
|
|
|
+ :content="item.answer"
|
|
|
+ :loading="item.loading"
|
|
|
+ :delay-loading="item.delayLoading"
|
|
|
+ :isSatisfied="item.isSatisfied"
|
|
|
+ @on-click-icon=" params => updateById(params)"
|
|
|
+ ></ChatAnswer>
|
|
|
</template>
|
|
|
</div>
|
|
|
|
|
|
<template #footer>
|
|
|
- <ChatInput @on-click="handleSubmit" @on-enter="handleSubmit" v-model:loading="isLoading"></ChatInput>
|
|
|
+ <ChatInput
|
|
|
+ ref="inputRef"
|
|
|
+ v-model:loading="isLoading"
|
|
|
+ v-model:switch="switchActive"
|
|
|
+ @on-click="handleSubmit"
|
|
|
+ @on-enter="handleSubmit"
|
|
|
+ ></ChatInput>
|
|
|
</template>
|
|
|
</TheChatView>
|
|
|
</section>
|