diff --git a/frontend/src/views/chat/ChatListContainer.vue b/frontend/src/views/chat/ChatListContainer.vue
index 9678fc6d..5231c6dc 100644
--- a/frontend/src/views/chat/ChatListContainer.vue
+++ b/frontend/src/views/chat/ChatListContainer.vue
@@ -103,54 +103,61 @@ function onChatCreated(chat: ChatInfo) {
const chatCreatorRef = ref()
-function goEmpty() {
+function goEmpty(func?: (...p: any[]) => void, ...params: any[]) {
_currentChat.value = new ChatInfo()
_currentChatId.value = undefined
- emits('goEmpty')
+ emits('goEmpty', func, ...params)
}
const createNewChat = async () => {
- if (!_loading.value) {
- goEmpty()
- if (isAssistant.value) {
- const assistantChat = await assistantStore.setChat()
- if (assistantChat) {
- onChatCreated(assistantChat)
- }
- return
- } else {
- chatCreatorRef.value?.showDs()
+ goEmpty(doCreateNewChat)
+}
+
+async function doCreateNewChat() {
+ if (isAssistant.value) {
+ const assistantChat = await assistantStore.setChat()
+ if (assistantChat) {
+ onChatCreated(assistantChat)
}
+ return
+ } else {
+ chatCreatorRef.value?.showDs()
}
}
function onClickHistory(chat: Chat) {
- if (chat !== undefined && chat.id !== undefined && !_loading.value) {
- goEmpty()
- nextTick(() => {
- if (chat !== undefined && chat.id !== undefined) {
- _currentChat.value = new ChatInfo(chat)
- _currentChatId.value = chat.id
- _loading.value = true
- chatApi
- .get(chat.id)
- .then((res) => {
- const info = chatApi.toChatInfo(res)
- if (info) {
- _currentChat.value = info
-
- // scrollToBottom()
- emits('onClickHistory', info)
- }
- })
- .finally(() => {
- _loading.value = false
- })
- }
- })
+ if (chat !== undefined && chat.id !== undefined) {
+ if (_currentChatId.value === chat.id) {
+ return
+ }
+ goEmpty(goHistory, chat)
}
}
+function goHistory(chat: Chat) {
+ nextTick(() => {
+ if (chat !== undefined && chat.id !== undefined) {
+ _currentChat.value = new ChatInfo(chat)
+ _currentChatId.value = chat.id
+ _loading.value = true
+ chatApi
+ .get(chat.id)
+ .then((res) => {
+ const info = chatApi.toChatInfo(res)
+ if (info && info.id === _currentChatId.value) {
+ _currentChat.value = info
+
+ // scrollToBottom()
+ emits('onClickHistory', info)
+ }
+ })
+ .finally(() => {
+ _loading.value = false
+ })
+ }
+ })
+}
+
function onChatDeleted(id: number) {
for (let i = 0; i < _chatList.value.length; i++) {
if (_chatList.value[i].id === id) {
diff --git a/frontend/src/views/chat/RecommendQuestion.vue b/frontend/src/views/chat/RecommendQuestion.vue
index 31c01fbb..d239ee32 100644
--- a/frontend/src/views/chat/RecommendQuestion.vue
+++ b/frontend/src/views/chat/RecommendQuestion.vue
@@ -1,5 +1,5 @@
diff --git a/frontend/src/views/chat/answer/AnalysisAnswer.vue b/frontend/src/views/chat/answer/AnalysisAnswer.vue
index feaf51f5..0757e9f5 100644
--- a/frontend/src/views/chat/answer/AnalysisAnswer.vue
+++ b/frontend/src/views/chat/answer/AnalysisAnswer.vue
@@ -1,7 +1,7 @@
diff --git a/frontend/src/views/chat/answer/ChartAnswer.vue b/frontend/src/views/chat/answer/ChartAnswer.vue
index 3d9f3743..fd478e9d 100644
--- a/frontend/src/views/chat/answer/ChartAnswer.vue
+++ b/frontend/src/views/chat/answer/ChartAnswer.vue
@@ -2,7 +2,7 @@
import BaseAnswer from './BaseAnswer.vue'
import { Chat, chatApi, ChatInfo, type ChatMessage, ChatRecord, questionApi } from '@/api/chat.ts'
import { useAssistantStore } from '@/stores/assistant'
-import { computed, nextTick, ref } from 'vue'
+import { computed, nextTick, onBeforeUnmount, ref } from 'vue'
const assistantStore = useAssistantStore()
const props = withDefaults(
defineProps<{
@@ -25,6 +25,7 @@ const props = withDefaults(
const emits = defineEmits([
'finish',
'error',
+ 'stop',
'update:loading',
'update:chatList',
'update:currentChat',
@@ -102,11 +103,10 @@ const sendMessage = async () => {
question: currentRecord.question,
chat_id: _currentChatId.value,
assistant_certificate: assistantStore.getCertificate,
- controller,
}
console.log(assistantStore.getCertificate)
console.log(param)
- const response = await questionApi.add(param)
+ const response = await questionApi.add(param, controller)
const reader = response.body.getReader()
const decoder = new TextDecoder()
@@ -235,7 +235,13 @@ function getChatData(recordId?: number) {
function stop() {
stopFlag.value = true
_loading.value = false
+ emits('stop')
}
+
+onBeforeUnmount(() => {
+ stop()
+})
+
defineExpose({ sendMessage, index: () => index.value, stop })
diff --git a/frontend/src/views/chat/answer/PredictAnswer.vue b/frontend/src/views/chat/answer/PredictAnswer.vue
index 7aee5005..992f18c2 100644
--- a/frontend/src/views/chat/answer/PredictAnswer.vue
+++ b/frontend/src/views/chat/answer/PredictAnswer.vue
@@ -1,7 +1,7 @@
diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue
index c98681d8..bbf51f25 100644
--- a/frontend/src/views/chat/index.vue
+++ b/frontend/src/views/chat/index.vue
@@ -99,6 +99,7 @@
:questions="message.recommended_question"
:first-chat="message.first_chat"
@click-question="quickAsk"
+ @stop="onChatStop"
/>