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)
- + +