From 7ab9aa77b864a0d18125189d3d672db313729e2b Mon Sep 17 00:00:00 2001 From: cherishsince Date: Thu, 16 May 2024 23:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91Chat=20?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E5=A2=9E=E5=8A=A0=E6=9B=B4=E6=96=B0=E9=80=89?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/ai/chat/Conversation.vue | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/views/ai/chat/Conversation.vue b/src/views/ai/chat/Conversation.vue index 60158cef..a75f12c4 100644 --- a/src/views/ai/chat/Conversation.vue +++ b/src/views/ai/chat/Conversation.vue @@ -87,7 +87,7 @@ const message = useMessage() // 消息弹窗 // 定义属性 const searchName = ref('') // 对话搜索 -const activeConversationId = ref(null) // 选中的对话,默认为 null +const activeConversationId = ref(null) // 选中的对话,默认为 null const conversationList = ref([] as ChatConversationVO[]) // 对话列表 const conversationMap = ref({}) // 对话分组 (置顶、今天、三天前、一星期前、一个月前) const drawer = ref(false) // 角色仓库抽屉 @@ -95,13 +95,13 @@ const drawer = ref(false) // 角色仓库抽屉 // 定义组件 props const props = defineProps({ activeId: { - type: Number || null, + type: String || null, required: true } }) // 定义钩子 -const emits = defineEmits(['onConversationClick', 'onConversationClear']) +const emits = defineEmits(['onConversationClick', 'onConversationClear', 'onConversationDelete']) /** * 对话 - 搜索 @@ -113,7 +113,7 @@ const searchConversation = () => { /** * 对话 - 点击 */ -const handleConversationClick = async (id: number) => { +const handleConversationClick = async (id: string) => { // 切换对话 activeConversationId.value = id const filterConversation = conversationList.value.filter(item => { @@ -227,6 +227,8 @@ const deleteChatConversation = async (conversation: ChatConversationVO) => { message.success('会话已删除') // 刷新列表 await getChatConversationList() + // 回调 + emits('onConversationDelete', conversation) } catch { } } @@ -276,10 +278,16 @@ const handleClearConversation = async () => { // ============ 组件 onMounted -onMounted(async () => { - // - if (props.activeId != null) { +const { activeId } = toRefs(props) +watch(activeId, async (newValue, oldValue) => { + // 更新选中 + activeConversationId.value = newValue as string +}) +onMounted(async () => { + // 默认选中 + if (props.activeId != null) { + activeConversationId.value = props.activeId } // 获取 对话列表 await getChatConversationList()