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() {