diff --git a/src/views/ai/chat/index.vue b/src/views/ai/chat/index.vue index 8ce1e473..8046e108 100644 --- a/src/views/ai/chat/index.vue +++ b/src/views/ai/chat/index.vue @@ -4,7 +4,7 @@
- + 新建对话 @@ -29,10 +29,10 @@
- + {{ conversation.title }}
@@ -215,26 +215,13 @@ marked.use({ renderer: renderer }) -const conversationList = [ - { - id: 1, - title: '测试标题', - avatar: - 'http://test.yudao.iocoder.cn/96c787a2ce88bf6d0ce3cd8b6cf5314e80e7703cd41bf4af8cd2e2909dbd6b6d.png' - }, - { - id: 2, - title: '测试对话', - avatar: - 'http://test.yudao.iocoder.cn/96c787a2ce88bf6d0ce3cd8b6cf5314e80e7703cd41bf4af8cd2e2909dbd6b6d.png' - } -] +const conversationList = ref([] as ChatConversationVO[]) // 初始化 copy 到粘贴板 const { copy } = useClipboard() const searchName = ref('') // 查询的内容 const inputTimeout = ref() // 处理输入中回车的定时器 -const conversationId = ref('1781604279872581648') // 对话id +const conversationId = ref(0) // 选中的对话编号 const conversationInProgress = ref() // 对话进行中 conversationInProgress.value = false const conversationInAbortController = ref() // 对话进行中 abort 控制器(控制 stream 对话) @@ -253,9 +240,19 @@ const useModal = ref() // 使用的modal const useConversation = ref() // 使用的 Conversation const modalList = ref([]) // 列表的数据 -const changeConversation = (conversation) => { - console.log(conversation) - conversationId.value = conversation.id +/** 新建对话 */ +const createConversation = async () => { + // 新建对话 + const conversationId = await ChatConversationApi.createChatConversationMy( + {} as unknown as ChatConversationVO + ) + changeConversation(conversationId) + // 刷新对话列表 + await getChatConversationList() +} + +const changeConversation = (id: number) => { + conversationId.value = id // 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 () => { + // 获得聊天会话列表 + await getChatConversationList() // 获取模型 getModalList() // 获取对话信息