|
@@ -6,7 +6,7 @@ import { BaseButton, RecodeCardItem, TheSubMenu, TheChatView, ChatWelcome } from
|
|
|
import { ChatAsk, ChatAnswer, ChatInput } from '@/components/Chat';
|
|
|
import { chatApi } from '@/api/chat';
|
|
|
|
|
|
-import {useInfinite, useScroll, useChat, useRecommend} from '@/composables';
|
|
|
+import { useInfinite, useScroll, useChat, useRecommend } from '@/composables';
|
|
|
|
|
|
const ANSWER_ID_KEY = '@@id@@';
|
|
|
|
|
@@ -17,7 +17,7 @@ const chatStore = useChatStore();
|
|
|
const { recordList, isFetching, onScrolltolower, onReset } = useInfinite('/front/bigModel/qa/pageList', { module: 0 });
|
|
|
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll();
|
|
|
const { chatDataSource, addChat, updateChat, clearChat, updateById } = useChat();
|
|
|
-const { recommendList } = useRecommend({type: 0});
|
|
|
+const { recommendList } = useRecommend({ type: 0 });
|
|
|
|
|
|
const message = useMessage();
|
|
|
|
|
@@ -63,7 +63,7 @@ const handleChatDetail = async ({ sessionId }) => {
|
|
|
|
|
|
const { data } = await chatApi.getAnswerHistoryDetail({ sessionId });
|
|
|
|
|
|
- chatDataSource.value = data.map(item => ({ ...item, loading: false, }));
|
|
|
+ chatDataSource.value = data.map(item => ({ ...item, loading: false, }));
|
|
|
currenSessionId.value = sessionId;
|
|
|
|
|
|
scrollToBottom();
|
|
@@ -85,7 +85,7 @@ const onRegenerate = async ({ question, realQuestion }) => {
|
|
|
onDownloadProgress: ({ event }) => {
|
|
|
const xhr = event.target;
|
|
|
const { responseText } = xhr;
|
|
|
- const [ answer ] = responseText.split(ANSWER_ID_KEY);
|
|
|
+ const [answer] = responseText.split(ANSWER_ID_KEY);
|
|
|
|
|
|
updateChat({
|
|
|
sessionId,
|
|
@@ -100,9 +100,9 @@ const onRegenerate = async ({ question, realQuestion }) => {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- const { data } = await chatApi.getChatStream(params);
|
|
|
-
|
|
|
- const [ answer, id ] = data.split(ANSWER_ID_KEY);
|
|
|
+ const { data } = await chatApi.getChatStream(params);
|
|
|
+
|
|
|
+ const [answer, id] = data.split(ANSWER_ID_KEY);
|
|
|
|
|
|
updateChat({
|
|
|
id,
|
|
@@ -112,10 +112,10 @@ const onRegenerate = async ({ question, realQuestion }) => {
|
|
|
loading: false,
|
|
|
delayLoading: false
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
scrollToBottomIfAtBottom();
|
|
|
}
|
|
|
- catch (error){
|
|
|
+ catch (error) {
|
|
|
console.log("取消了请求 - catch", error);
|
|
|
}
|
|
|
finally {
|
|
@@ -126,12 +126,12 @@ const onRegenerate = async ({ question, realQuestion }) => {
|
|
|
// 提交问题
|
|
|
const handleSubmit = async (question, realQuestion = '') => {
|
|
|
// 用于模拟 - 内容生成前置等待状态
|
|
|
-
|
|
|
+
|
|
|
if (unref(isExistInHistory)) {
|
|
|
const { data: sessionId } = await chatApi.getChatSessionTag();
|
|
|
currenSessionId.value = sessionId;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
isLoading.value = true;
|
|
|
|
|
|
addChat({
|
|
@@ -150,7 +150,7 @@ const handleSubmit = async (question, realQuestion = '') => {
|
|
|
|
|
|
// 处理推荐问题
|
|
|
const handleWelcomeRecommend = ({ question, realQuestion }) => {
|
|
|
- handleSubmit( question, realQuestion );
|
|
|
+ handleSubmit(question, realQuestion);
|
|
|
}
|
|
|
|
|
|
// 删除历史对话
|
|
@@ -163,7 +163,7 @@ const handeChatDelete = async (id) => {
|
|
|
|
|
|
onMounted(() => {
|
|
|
const question = chatStore.chatQuestion;
|
|
|
- if ( Object.keys(question).length ) {
|
|
|
+ if (Object.keys(question).length) {
|
|
|
handleWelcomeRecommend(chatStore.chatQuestion);
|
|
|
chatStore.clearChatQuestion();
|
|
|
}
|
|
@@ -184,52 +184,30 @@ onUnmounted(() => {
|
|
|
</template>
|
|
|
|
|
|
<div class="pr-[4px] text-[#5e5e5e]">
|
|
|
- <RecodeCardItem
|
|
|
- v-for="item, index in recordList"
|
|
|
- :key="item.sessionId + index"
|
|
|
- :title="item.showVal"
|
|
|
- :time="item.createTime"
|
|
|
- :data-item="item"
|
|
|
- :class="{'recode-card-item_active': recordActive === item.sessionId}"
|
|
|
- @on-click="handleChatDetail"
|
|
|
- @on-delete="handeChatDelete"
|
|
|
- />
|
|
|
+ <RecodeCardItem v-for="item, index in recordList" :key="item.sessionId + index" :title="item.showVal"
|
|
|
+ :time="item.createTime" :data-item="item"
|
|
|
+ :class="{ 'recode-card-item_active': recordActive === item.sessionId }" @on-click="handleChatDetail"
|
|
|
+ @on-delete="handeChatDelete" />
|
|
|
</div>
|
|
|
|
|
|
</TheSubMenu>
|
|
|
|
|
|
<TheChatView ref="scrollRef">
|
|
|
- <ChatWelcome title="您好,我是LibraAI专家问答" card-title="您可以试着问我:"
|
|
|
- :sub-title="[
|
|
|
- '期待与您一同规划和完成未来的工作。有任何重点或需讨论的事项,随时告诉我'
|
|
|
- ]"
|
|
|
- :card-content="recommendList"
|
|
|
- v-if="!chatDataSource.length"
|
|
|
- @on-click="handleWelcomeRecommend"
|
|
|
- />
|
|
|
-
|
|
|
+ <ChatWelcome title="您好,我是LibraAI专家问答" card-title="您可以试着问我:" :sub-title="[
|
|
|
+ '期待与您一同规划和完成未来的工作。有任何重点或需讨论的事项,随时告诉我'
|
|
|
+ ]" :card-content="recommendList" v-if="!chatDataSource.length" @on-click="handleWelcomeRecommend" />
|
|
|
+
|
|
|
<div class="conversation-item" v-if="chatDataSource.length">
|
|
|
<template v-for="item in chatDataSource" :key="item.id">
|
|
|
<ChatAsk :content="item.question" :sessionId="item.sessionId"></ChatAsk>
|
|
|
- <ChatAnswer
|
|
|
- :id="item.id"
|
|
|
- :content="item.answer"
|
|
|
- :loading="item.loading"
|
|
|
- :delay-loading="item.delayLoading"
|
|
|
- :isSatisfied="item.isSatisfied"
|
|
|
- @on-click-icon=" params => updateById(params)"
|
|
|
- ></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
|
|
|
- ref="inputRef"
|
|
|
- v-model:loading="isLoading"
|
|
|
- v-model:switch="switchActive"
|
|
|
- @on-click="handleSubmit"
|
|
|
- @on-enter="handleSubmit"
|
|
|
- ></ChatInput>
|
|
|
+ <ChatInput ref="inputRef" v-model:loading="isLoading" v-model:switch="switchActive" @on-click="handleSubmit"
|
|
|
+ @on-enter="handleSubmit"></ChatInput>
|
|
|
</template>
|
|
|
</TheChatView>
|
|
|
</section>
|