From bbcfd3bfdc048e0e6264be17e774e90e5a3ac239 Mon Sep 17 00:00:00 2001 From: ivamp Date: Fri, 13 Sep 2024 00:43:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E5=BD=93=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=AF=B9=E8=AF=9D=E7=9A=84=E6=97=B6=E5=80=99=E5=88=99?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=AF=B9=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chat/chat.vue | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/components/chat/chat.vue b/src/components/chat/chat.vue index b120ee5..5339c80 100644 --- a/src/components/chat/chat.vue +++ b/src/components/chat/chat.vue @@ -128,6 +128,7 @@ import { EntityChatMessage, SchemaChatMessageAddRequestRoleEnum } from "@/api"; import getApi from "@/plugins/api"; import MessageList from "./MessageList.vue"; import { useChatStore } from "@/stores/chat"; +import router from "@/router"; // 获取组件传入的 chatId const chatId: Ref = ref(null); @@ -293,17 +294,22 @@ async function sendMessage( return; } + let redirect = false; + if (!chatId.value) { - getApi() + await getApi() .Chat.apiV1ChatsPost({ name: text.slice(0, 10), }) .then(async (res) => { chatId.value = res.data.data?.id; + + if (chatId.value) { + chatStore.currentChatId = chatId.value; + redirect = true; + } await getChatMessages(); }); - - return; } toolError.value = false; @@ -330,7 +336,7 @@ async function sendMessage( if (streamId) { await getChatMessages(); - streamChat(streamId); + streamChat(streamId, redirect); } }) .catch(async (err) => { @@ -340,7 +346,7 @@ async function sendMessage( if (streamId) { await getChatMessages(); - streamChat(streamId); + streamChat(streamId, redirect); } } }); @@ -382,7 +388,7 @@ async function getChatMessages() { return false; } -function streamChat(streamId: String) { +function streamChat(streamId: String, redirect = false) { const url = getApi().conf.basePath + "/api/v1/stream/" + streamId; const evtSource = new EventSource(url); @@ -397,6 +403,16 @@ function streamChat(streamId: String) { evtSource.close(); processing.value = false; + if (redirect && chatId.value != undefined) { + // 改变 URL + router.replace({ + name: "/chat/[id]/", + params: { + id: chatId.value, + }, + }); + } + return; }