From b3cfe7a976c027a8ba3878c643b60ebb85751ae9 Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Fri, 17 Mar 2023 08:40:45 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=AE=B0=E5=BD=95=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E8=AE=BE=E5=AE=9A=E4=BF=9D=E5=AD=98=E5=88=B0=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/chat/helper.ts | 7 ++++++- src/store/modules/chat/index.ts | 5 +++++ src/typings/chat.d.ts | 1 + src/views/chat/hooks/useUsingContext.ts | 8 +++++--- src/views/chat/index.vue | 1 + src/views/chat/layout/sider/Footer.vue | 3 ++- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/store/modules/chat/helper.ts b/src/store/modules/chat/helper.ts index 28efa5a..39adb7a 100644 --- a/src/store/modules/chat/helper.ts +++ b/src/store/modules/chat/helper.ts @@ -4,7 +4,12 @@ const LOCAL_NAME = 'chatStorage' export function defaultState(): Chat.ChatState { const uuid = 1002 - return { active: uuid, history: [{ uuid, title: 'New Chat', isEdit: false }], chat: [{ uuid, data: [] }] } + return { + active: uuid, + usingContext: true, + history: [{ uuid, title: 'New Chat', isEdit: false }], + chat: [{ uuid, data: [] }], + } } export function getLocalState(): Chat.ChatState { diff --git a/src/store/modules/chat/index.ts b/src/store/modules/chat/index.ts index 540954d..38f3215 100644 --- a/src/store/modules/chat/index.ts +++ b/src/store/modules/chat/index.ts @@ -23,6 +23,11 @@ export const useChatStore = defineStore('chat-store', { }, actions: { + setUsingContext(context: boolean) { + this.usingContext = context + this.recordState() + }, + addHistory(history: Chat.History, chatData: Chat.Chat[] = []) { this.history.unshift(history) this.chat.unshift({ uuid: history.uuid, data: chatData }) diff --git a/src/typings/chat.d.ts b/src/typings/chat.d.ts index c0b80c9..0c8012e 100644 --- a/src/typings/chat.d.ts +++ b/src/typings/chat.d.ts @@ -18,6 +18,7 @@ declare namespace Chat { interface ChatState { active: number | null + usingContext: boolean; history: History[] chat: { uuid: number; data: Chat[] }[] } diff --git a/src/views/chat/hooks/useUsingContext.ts b/src/views/chat/hooks/useUsingContext.ts index f3b3a16..8b7c800 100644 --- a/src/views/chat/hooks/useUsingContext.ts +++ b/src/views/chat/hooks/useUsingContext.ts @@ -1,13 +1,15 @@ -import { ref } from 'vue' +import { computed } from 'vue' import { useMessage } from 'naive-ui' import { t } from '@/locales' +import { useChatStore } from '@/store' export function useUsingContext() { const ms = useMessage() - const usingContext = ref(true) + const chatStore = useChatStore() + const usingContext = computed(() => chatStore.usingContext) function toggleUsingContext() { - usingContext.value = !usingContext.value + chatStore.setUsingContext(!usingContext.value) if (usingContext.value) ms.success(t('chat.turnOnContext')) else diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 9d1e1c6..06de62c 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -416,6 +416,7 @@ const searchOptions = computed(() => { return [] } }) + // value反渲染key const renderOption = (option: { label: string }) => { for (const i of promptTemplate.value) { diff --git a/src/views/chat/layout/sider/Footer.vue b/src/views/chat/layout/sider/Footer.vue index 5837547..74e47c6 100644 --- a/src/views/chat/layout/sider/Footer.vue +++ b/src/views/chat/layout/sider/Footer.vue @@ -12,7 +12,8 @@ const show = ref(false)
- + +