perf: use hooks

main
ChenZhaoYu 2 years ago
parent 07b92d4ede
commit a2fcd31f24

@ -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<boolean>(true)
function toggleUsingContext() {
usingContext.value = !usingContext.value
if (usingContext.value)
ms.success(t('chat.turnOnContext'))
else
ms.warning(t('chat.turnOffContext'))
}
return {
usingContext,
toggleUsingContext,
}
}

@ -7,6 +7,7 @@ import { Message } from './components'
import { useScroll } from './hooks/useScroll' import { useScroll } from './hooks/useScroll'
import { useChat } from './hooks/useChat' import { useChat } from './hooks/useChat'
import { useCopyCode } from './hooks/useCopyCode' import { useCopyCode } from './hooks/useCopyCode'
import { useUsingContext } from './hooks/useUsingContext'
import HeaderComponent from './components/Header/index.vue' import HeaderComponent from './components/Header/index.vue'
import { HoverButton, SvgIcon } from '@/components/common' import { HoverButton, SvgIcon } from '@/components/common'
import { useBasicLayout } from '@/hooks/useBasicLayout' import { useBasicLayout } from '@/hooks/useBasicLayout'
@ -25,9 +26,11 @@ const ms = useMessage()
const chatStore = useChatStore() const chatStore = useChatStore()
useCopyCode() useCopyCode()
const { isMobile } = useBasicLayout() const { isMobile } = useBasicLayout()
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat() const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
const { scrollRef, scrollToBottom } = useScroll() const { scrollRef, scrollToBottom } = useScroll()
const { usingContext, toggleUsingContext } = useUsingContext()
const { uuid } = route.params as { uuid: string } const { uuid } = route.params as { uuid: string }
@ -36,7 +39,6 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item.
const prompt = ref<string>('') const prompt = ref<string>('')
const loading = ref<boolean>(false) const loading = ref<boolean>(false)
const usingContext = ref<boolean>(true)
function handleSubmit() { function handleSubmit() {
onConversation() 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(() => { const placeholder = computed(() => {
if (isMobile.value) if (isMobile.value)
return t('chat.placeholderMobile') return t('chat.placeholderMobile')

Loading…
Cancel
Save