From cf8e2dd7b655db45111f9508b434442436801a11 Mon Sep 17 00:00:00 2001
From: ChenZhaoYu <790348264@qq.com>
Date: Tue, 14 Feb 2023 15:56:44 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=A4=9A=E4=BC=9A?=
=?UTF-8?q?=E8=AF=9D=E5=86=85=E5=AE=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/business/Chat/hooks/useChat.ts | 23 ++++++++++++-------
src/components/business/Chat/index.vue | 19 +++++++++++++--
src/store/modules/history/index.ts | 9 ++++----
3 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/src/components/business/Chat/hooks/useChat.ts b/src/components/business/Chat/hooks/useChat.ts
index 270fe5e..7e7ea5e 100644
--- a/src/components/business/Chat/hooks/useChat.ts
+++ b/src/components/business/Chat/hooks/useChat.ts
@@ -3,14 +3,21 @@ import { useHistoryStore } from '@/store'
export function useChat() {
const historyStore = useHistoryStore()
- function addChat(message: string, args?: { reversal?: boolean; error?: boolean; options?: Chat.ChatOptions }) {
- historyStore.addChat({
- dateTime: new Date().toLocaleString(),
- message,
- reversal: args?.reversal ?? false,
- error: args?.error ?? false,
- options: args?.options ?? undefined,
- })
+ function addChat(
+ message: string,
+ args?: { reversal?: boolean; error?: boolean; options?: Chat.ChatOptions },
+ uuid?: number | null,
+ ) {
+ historyStore.addChat(
+ {
+ dateTime: new Date().toLocaleString(),
+ message,
+ reversal: args?.reversal ?? false,
+ error: args?.error ?? false,
+ options: args?.options ?? undefined,
+ },
+ uuid,
+ )
}
function clearChat() {
diff --git a/src/components/business/Chat/index.vue b/src/components/business/Chat/index.vue
index c22942a..dfdceaf 100644
--- a/src/components/business/Chat/index.vue
+++ b/src/components/business/Chat/index.vue
@@ -1,5 +1,5 @@
diff --git a/src/store/modules/history/index.ts b/src/store/modules/history/index.ts
index 24ea21b..29401b6 100644
--- a/src/store/modules/history/index.ts
+++ b/src/store/modules/history/index.ts
@@ -16,15 +16,16 @@ export const useHistoryStore = defineStore('history-store', {
},
},
actions: {
- addChat(data: Chat.Chat) {
+ addChat(data: Chat.Chat, uuid: number | null = null) {
if (this.active === null) {
this.historyChat.push({ title: data.message, isEdit: false, data: [data] })
this.active = this.historyChat.length - 1
}
else {
- if (this.historyChat[this.active].title === '')
- this.historyChat[this.active].title = data.message
- this.historyChat[this.active].data.push(data)
+ const active = uuid !== null ? uuid : this.active
+ if (this.historyChat[active].title === '')
+ this.historyChat[active].title = data.message
+ this.historyChat[active].data.push(data)
}
setLocalHistory(this.$state)
},