【新增】AI:对话接入聊天会话列表

This commit is contained in:
YunaiV 2024-05-15 00:00:03 +08:00
parent 051a610e56
commit 67ece2ac5c

View File

@ -4,7 +4,7 @@
<el-aside width="260px" class="conversation-container"> <el-aside width="260px" class="conversation-container">
<div> <div>
<!-- 左顶部新建对话 --> <!-- 左顶部新建对话 -->
<el-button class="w-1/1 btn-new-conversation" type="primary"> <el-button class="w-1/1 btn-new-conversation" type="primary" @click="createConversation">
<Icon icon="ep:plus" class="mr-5px" /> <Icon icon="ep:plus" class="mr-5px" />
新建对话 新建对话
</el-button> </el-button>
@ -29,10 +29,10 @@
<el-row v-for="conversation in conversationList" :key="conversation.id"> <el-row v-for="conversation in conversationList" :key="conversation.id">
<div <div
:class="conversation.id === conversationId ? 'conversation active' : 'conversation'" :class="conversation.id === conversationId ? 'conversation active' : 'conversation'"
@click="changeConversation(conversation)" @click="changeConversation(conversation.id)"
> >
<div class="title-wrapper"> <div class="title-wrapper">
<img class="avatar" :src="conversation.avatar" /> <img class="avatar" :src="conversation.roleAvatar" />
<span class="title">{{ conversation.title }}</span> <span class="title">{{ conversation.title }}</span>
</div> </div>
<div class="button-wrapper"> <div class="button-wrapper">
@ -215,26 +215,13 @@ marked.use({
renderer: renderer renderer: renderer
}) })
const conversationList = [ const conversationList = ref([] as ChatConversationVO[])
{
id: 1,
title: '测试标题',
avatar:
'http://test.yudao.iocoder.cn/96c787a2ce88bf6d0ce3cd8b6cf5314e80e7703cd41bf4af8cd2e2909dbd6b6d.png'
},
{
id: 2,
title: '测试对话',
avatar:
'http://test.yudao.iocoder.cn/96c787a2ce88bf6d0ce3cd8b6cf5314e80e7703cd41bf4af8cd2e2909dbd6b6d.png'
}
]
// copy // copy
const { copy } = useClipboard() const { copy } = useClipboard()
const searchName = ref('') // const searchName = ref('') //
const inputTimeout = ref<any>() // const inputTimeout = ref<any>() //
const conversationId = ref('1781604279872581648') // id const conversationId = ref(0) //
const conversationInProgress = ref<Boolean>() // const conversationInProgress = ref<Boolean>() //
conversationInProgress.value = false conversationInProgress.value = false
const conversationInAbortController = ref<any>() // abort ( stream ) const conversationInAbortController = ref<any>() // abort ( stream )
@ -253,9 +240,19 @@ const useModal = ref<ChatModelVO>() // 使用的modal
const useConversation = ref<ChatConversationVO>() // 使 Conversation const useConversation = ref<ChatConversationVO>() // 使 Conversation
const modalList = ref<ChatModelVO[]>([]) // const modalList = ref<ChatModelVO[]>([]) //
const changeConversation = (conversation) => { /** 新建对话 */
console.log(conversation) const createConversation = async () => {
conversationId.value = conversation.id //
const conversationId = await ChatConversationApi.createChatConversationMy(
{} as unknown as ChatConversationVO
)
changeConversation(conversationId)
//
await getChatConversationList()
}
const changeConversation = (id: number) => {
conversationId.value = id
// TODO // TODO
} }
@ -505,8 +502,25 @@ const getConversation = async (conversationId: string) => {
} }
} }
/** 获得聊天会话列表 */
const getChatConversationList = async () => {
conversationList.value = await ChatConversationApi.getChatConversationMyList()
//
if (conversationList.value.length === 0) {
conversationId.value = 0
// TODO
} else {
if (conversationId.value === 0) {
conversationId.value = conversationList.value[0].id
changeConversation(conversationList.value[0].id)
}
}
}
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
//
await getChatConversationList()
// //
getModalList() getModalList()
// //