From de34af8747e3669f6f2379bb96817f72a6be38ac Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Tue, 14 Feb 2023 15:07:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=9A=E4=BC=9A=E8=AF=9D=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E9=80=BB=E8=BE=91=E6=A2=B3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/business/Chat/hooks/useChat.ts | 30 +++++++++ src/components/business/Chat/index.vue | 40 +++++------- .../business/Chat/layout/sider/List.vue | 63 ++++++++++++------- .../business/Chat/layout/sider/index.vue | 22 ++----- src/components/business/Chat/types.ts | 18 ------ src/store/modules/app/helper.ts | 12 ++-- src/store/modules/app/index.ts | 6 +- src/store/modules/history/helper.ts | 21 +++++++ src/store/modules/history/index.ts | 59 ++++++++++++++--- src/typings/chat.d.ts | 20 ++++++ src/utils/storage/local.ts | 29 ++++++--- 11 files changed, 213 insertions(+), 107 deletions(-) create mode 100644 src/components/business/Chat/hooks/useChat.ts delete mode 100644 src/components/business/Chat/types.ts create mode 100644 src/store/modules/history/helper.ts create mode 100644 src/typings/chat.d.ts diff --git a/src/components/business/Chat/hooks/useChat.ts b/src/components/business/Chat/hooks/useChat.ts new file mode 100644 index 0000000..f6ebd50 --- /dev/null +++ b/src/components/business/Chat/hooks/useChat.ts @@ -0,0 +1,30 @@ +import { useHistoryStore } from '@/store' + +export function useChat() { + const historyStore = useHistoryStore() + + function addChat(message: string, args?: { reversal?: boolean; error?: boolean; options?: Chat.ChatOptions }) { + if (historyStore.historyChat.length === 0) { + historyStore.addHistory({ + title: message, + isEdit: false, + data: [], + }) + historyStore.chooseHistory(historyStore.historyChat.length - 1) + } + + historyStore.addChat({ + dateTime: new Date().toLocaleString(), + message, + reversal: args?.reversal ?? false, + error: args?.error ?? false, + options: args?.options ?? undefined, + }) + } + + function clearChat() { + historyStore.clearChat() + } + + return { addChat, clearChat } +} diff --git a/src/components/business/Chat/index.vue b/src/components/business/Chat/index.vue index 279ea44..c22942a 100644 --- a/src/components/business/Chat/index.vue +++ b/src/components/business/Chat/index.vue @@ -1,27 +1,26 @@ @@ -96,8 +88,8 @@ function handleClear() {