perf: 优化新建聊天不重新创建socket

This commit is contained in:
“huailei000”
2023-12-15 11:00:47 +08:00
committed by huailei
parent c1d0994781
commit f947fa8d36
5 changed files with 17 additions and 3 deletions

View File

@@ -80,7 +80,6 @@ export default {
this.inputValue = ''
},
onSelectChange(value) {
this.inputValue = value
this.$emit('select-prompt', value)
}
}

View File

@@ -37,6 +37,7 @@ import { getInputFocus, useChat } from '../../useChat.js'
const {
setLoading,
clearChats,
addChatMessageById,
addMessageToActiveChat,
newChatAndAddMessageById,
@@ -179,6 +180,12 @@ export default {
onSelectPromptHandle(value) {
this.prompt = value
this.currentConversationId = ''
this.showIntroduction = false
this.onSendHandle(value)
},
onNewChat() {
clearChats()
this.initChatMessage()
},
onStopHandle() {
this.$axios.post(

View File

@@ -73,7 +73,7 @@ export default {
onNewChat() {
this.active = 'chat'
this.$nextTick(() => {
this.$refs.component?.init()
this.$refs.component?.onNewChat()
getInputFocus()
})
}

View File

@@ -23,6 +23,10 @@ export function useChat() {
store.commit('chat/addChatToStore', data)
}
const clearChats = () => {
store.commit('chat/clearChats')
}
const addMessageToActiveChat = (chat) => {
store.commit('chat/addMessageToActiveChat', chat)
}
@@ -69,6 +73,7 @@ export function useChat() {
chatStore,
setLoading,
onNewChat,
clearChats,
getInputFocus,
addMessageToActiveChat,
newChatAndAddMessageById,

View File

@@ -1,7 +1,6 @@
const state = {
loading: false,
tabNum: 0,
activeTab: 0,
chatsStore: [],
activeChat: {}
@@ -24,6 +23,10 @@ const mutations = {
state.activeChat.chats?.push(chat)
},
clearChats(state) {
state.activeChat.chats = []
},
removeLoadingMessageInChat(state) {
const { chats } = state.activeChat
const length = chats?.length