# Conflicts:
#	src/views/ai/chat/index.vue
This commit is contained in:
YunaiV 2024-05-24 20:54:10 +08:00
commit ac18d871ca
2 changed files with 23 additions and 26 deletions

View File

@ -387,6 +387,8 @@ onMounted(async () => {
// //
if (conversationList.value.length) { if (conversationList.value.length) {
activeConversationId.value = conversationList.value[0].id activeConversationId.value = conversationList.value[0].id
// onConversationClick
await emits('onConversationClick', conversationList.value[0])
} }
} }
}) })

View File

@ -36,11 +36,10 @@
<div class="message-container" > <div class="message-container" >
<MessageLoading v-if="listLoading" /> <MessageLoading v-if="listLoading" />
<MessageNewChat v-if="!activeConversation" @on-new-chat="handlerNewChat" /> <MessageNewChat v-if="!activeConversation" @on-new-chat="handlerNewChat" />
<ChatEmpty v-if="!listLoading && messageList.length === 0 && activeConversation" @on-prompt="doSend"/> <ChatEmpty v-if="!listLoading && list.length === 0 && activeConversation" @on-prompt="doSend"/>
<Message v-if="!listLoading && messageList.length > 0" <Message v-if="!listLoading && list.length > 0"
ref="messageRef" ref="messageRef"
:conversation="activeConversation" :list="list"
:list="messageList"
@on-delete-success="handlerMessageDelete" @on-delete-success="handlerMessageDelete"
@on-edit="handlerMessageEdit" @on-edit="handlerMessageEdit"
@on-refresh="handlerMessageRefresh"/> @on-refresh="handlerMessageRefresh"/>
@ -103,12 +102,14 @@ import MessageLoading from './MessageLoading.vue'
import MessageNewChat from './MessageNewChat.vue' import MessageNewChat from './MessageNewChat.vue'
import {ChatMessageApi, ChatMessageVO} from '@/api/ai/chat/message' import {ChatMessageApi, ChatMessageVO} from '@/api/ai/chat/message'
import {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation' import {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation'
import { getUserProfile, ProfileVO } from '@/api/system/user/profile' import {getUserProfile, ProfileVO} from '@/api/system/user/profile'
import {useClipboard} from '@vueuse/core'
import ChatConversationUpdateForm from "@/views/ai/chat/components/ChatConversationUpdateForm.vue"; import ChatConversationUpdateForm from "@/views/ai/chat/components/ChatConversationUpdateForm.vue";
import {Download, Top} from "@element-plus/icons-vue"; import {Download, Top} from "@element-plus/icons-vue";
const route = useRoute() // const route = useRoute() //
const message = useMessage() // const message = useMessage() //
const {copy} = useClipboard() // copy
// ref // ref
const activeConversationId = ref<string | null>(null) // const activeConversationId = ref<string | null>(null) //
@ -338,8 +339,14 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
userMessage.content, userMessage.content,
conversationInAbortController.value, conversationInAbortController.value,
enableContext.value, enableContext.value,
async (message) => { async (res) => {
const data = JSON.parse(message.data) // TODO console.log('res', res)
const { code, data, msg } = JSON.parse(res.data)
if (code !== 0) {
message.alert(`对话异常! ${msg}`)
return
}
// //
if (data.receive.content === '') { if (data.receive.content === '') {
return return
@ -360,14 +367,13 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
await scrollToBottom() await scrollToBottom()
}, },
(error) => { (error) => {
console.log('onError') message.alert(`对话异常! ${error}`)
// //
conversationInProgress.value = false conversationInProgress.value = false
// stream // stream
conversationInAbortController.value.abort() conversationInAbortController.value.abort()
}, },
() => { () => {
console.log('onClose')
// //
conversationInProgress.value = false conversationInProgress.value = false
// stream // stream
@ -390,23 +396,6 @@ const stopStream = async () => {
// ============== message ================= // ============== message =================
/** 消息列表 */
const messageList = computed(() => {
if (list.value.length > 0) {
return list.value
}
// systemMessage
// TODO add by
if (activeConversation.value?.systemMessage) {
return [{
id: 0,
type: 'system',
content: activeConversation.value.systemMessage
}]
}
return []
})
/** /**
* 获取 - message 列表 * 获取 - message 列表
*/ */
@ -486,6 +475,8 @@ const handleConversationClick = async (conversation: ChatConversationVO) => {
await getMessageList() await getMessageList()
// //
scrollToBottom(true) scrollToBottom(true)
//
prompt.value = ''
return true return true
} }
@ -536,6 +527,10 @@ const handlerNewChat = async () => {
* 删除 message * 删除 message
*/ */
const handlerMessageDelete = async () => { const handlerMessageDelete = async () => {
if (conversationInProgress.value) {
message.alert('回答中,不能删除!')
return
}
// message // message
await getMessageList() await getMessageList()
} }