From a2fcd31f24fb55d77b0a7d553a98ad573023a00b Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Fri, 10 Mar 2023 14:30:02 +0800 Subject: [PATCH] perf: use hooks --- src/views/chat/hooks/useUsingContext.ts | 21 +++++++++++++++++++++ src/views/chat/index.vue | 12 +++--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 src/views/chat/hooks/useUsingContext.ts diff --git a/src/views/chat/hooks/useUsingContext.ts b/src/views/chat/hooks/useUsingContext.ts new file mode 100644 index 0000000..f3b3a16 --- /dev/null +++ b/src/views/chat/hooks/useUsingContext.ts @@ -0,0 +1,21 @@ +import { ref } from 'vue' +import { useMessage } from 'naive-ui' +import { t } from '@/locales' + +export function useUsingContext() { + const ms = useMessage() + const usingContext = ref(true) + + function toggleUsingContext() { + usingContext.value = !usingContext.value + if (usingContext.value) + ms.success(t('chat.turnOnContext')) + else + ms.warning(t('chat.turnOffContext')) + } + + return { + usingContext, + toggleUsingContext, + } +} diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 9deb15f..f18cd4b 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -7,6 +7,7 @@ import { Message } from './components' import { useScroll } from './hooks/useScroll' import { useChat } from './hooks/useChat' import { useCopyCode } from './hooks/useCopyCode' +import { useUsingContext } from './hooks/useUsingContext' import HeaderComponent from './components/Header/index.vue' import { HoverButton, SvgIcon } from '@/components/common' import { useBasicLayout } from '@/hooks/useBasicLayout' @@ -25,9 +26,11 @@ const ms = useMessage() const chatStore = useChatStore() useCopyCode() + const { isMobile } = useBasicLayout() const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat() const { scrollRef, scrollToBottom } = useScroll() +const { usingContext, toggleUsingContext } = useUsingContext() const { uuid } = route.params as { uuid: string } @@ -36,7 +39,6 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item. const prompt = ref('') const loading = ref(false) -const usingContext = ref(true) function handleSubmit() { onConversation() @@ -392,14 +394,6 @@ function handleStop() { } } -function toggleUsingContext() { - usingContext.value = !usingContext.value - if (usingContext.value) - ms.success(t('chat.turnOnContext')) - else - ms.warning(t('chat.turnOffContext')) -} - const placeholder = computed(() => { if (isMobile.value) return t('chat.placeholderMobile')