perf: 优化智能问答返回显示系统消息

This commit is contained in:
“huailei000”
2023-12-27 17:04:43 +08:00
committed by huailei
parent 3c900ce387
commit fba2f77874
3 changed files with 11 additions and 15 deletions

View File

@@ -42,7 +42,6 @@ const {
addMessageToActiveChat,
newChatAndAddMessageById,
removeLoadingMessageInChat,
removeLoadingAndAddMessageToChat,
updateChaMessageContentById,
addTemporaryLoadingToChat
} = useChat()
@@ -120,12 +119,11 @@ export default {
}
},
onChatMessage(data) {
if (!data.message.content && data.conversation_id) {
if (data.conversation_id) {
setLoading(true)
removeLoadingAndAddMessageToChat(data)
removeLoadingMessageInChat()
this.currentConversationId = data.conversation_id
} else {
updateChaMessageContentById(data.message.id, data.message.content)
updateChaMessageContentById(data.message.id, data)
}
if (data.message?.type === 'finish') {
setLoading(false)

View File

@@ -59,13 +59,8 @@ export function useChat() {
addChatMessageById(chat)
}
const removeLoadingAndAddMessageToChat = (chat) => {
store.commit('chat/removeLoadingMessageInChat')
store.commit('chat/addMessageToActiveChat', chat)
}
const updateChaMessageContentById = (id, content) => {
store.commit('chat/updateChaMessageContentById', { id, content })
const updateChaMessageContentById = (id, data) => {
store.commit('chat/updateChaMessageContentById', { id, data })
pageScroll('scrollRef')
}
@@ -78,7 +73,6 @@ export function useChat() {
addMessageToActiveChat,
newChatAndAddMessageById,
removeLoadingMessageInChat,
removeLoadingAndAddMessageToChat,
addChatMessageById,
addTemporaryLoadingToChat,
updateChaMessageContentById

View File

@@ -38,10 +38,14 @@ const mutations = {
}
},
updateChaMessageContentById(state, { id, content }) {
updateChaMessageContentById(state, { id, data }) {
const chats = state.activeChat.chats || []
const filterChat = chats.filter((chat) => chat.message.id === id)?.[0] || {}
filterChat.message.content = content
if (Object.keys(filterChat).length > 0) {
filterChat.message.content = data.message.content
} else {
chats?.push(data)
}
}
}