From 42f30230f2f3e497d6871cb77f885ae5f0de3b83 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 19 Nov 2025 11:47:26 +0800 Subject: [PATCH 01/18] =?UTF-8?q?feat=EF=BC=9A=E3=80=90ele=E3=80=91?= =?UTF-8?q?=E3=80=90ai=E3=80=91=E4=BC=98=E5=8C=96=20chat=20=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-ele/src/views/ai/chat/index/index.vue | 3 +- .../chat/index/modules/conversation/list.vue | 364 ++++++++++-------- 2 files changed, 210 insertions(+), 157 deletions(-) diff --git a/apps/web-ele/src/views/ai/chat/index/index.vue b/apps/web-ele/src/views/ai/chat/index/index.vue index ae58f6ab6..a97b48ca5 100644 --- a/apps/web-ele/src/views/ai/chat/index/index.vue +++ b/apps/web-ele/src/views/ai/chat/index/index.vue @@ -673,7 +673,8 @@ onMounted(async () => { {{ conversationInProgress ? '进行中' : '发送' }} diff --git a/apps/web-ele/src/views/ai/chat/index/modules/conversation/list.vue b/apps/web-ele/src/views/ai/chat/index/modules/conversation/list.vue index b87c15b1f..3e92f64e6 100644 --- a/apps/web-ele/src/views/ai/chat/index/modules/conversation/list.vue +++ b/apps/web-ele/src/views/ai/chat/index/modules/conversation/list.vue @@ -166,87 +166,119 @@ async function getConversationGroupByCreateTime( return groupMap; } -/** 新建对话 */ -async function handleConversationCreate() { - // 1. 创建对话 - const conversationId = await createChatConversationMy({ - roleId: undefined, - } as unknown as AiChatConversationApi.ChatConversation); - - // 2. 刷新列表 +async function createConversation() { + // 1. 新建对话 + const conversationId = await createChatConversationMy( + {} as unknown as AiChatConversationApi.ChatConversation, + ); + // 2. 获取对话内容 await getChatConversationList(); - - // 3. 回调 - emits('onConversationCreate', conversationId); + // 3. 选中对话 + await handleConversationClick(conversationId); + // 4. 回调 + emits('onConversationCreate'); } /** 清空未置顶的对话 */ -async function handleConversationClear() { - await confirm({ - title: '清空未置顶的对话', - content: h('div', {}, [ - h('p', '确认清空未置顶的对话吗?'), - h('p', '清空后,未置顶的对话将被删除,无法恢复!'), - ]), +async function handleClearConversation() { + try { + await confirm('确认后对话会全部清空,置顶的对话除外。'); + await deleteChatConversationMyByUnpinned(); + ElMessage.success($t('ui.actionMessage.operationSuccess')); + // 清空对话、对话内容 + activeConversationId.value = null; + // 获取对话列表 + await getChatConversationList(); + // 回调 方法 + emits('onConversationClear'); + } catch {} +} + +/** 删除聊天对话 */ +async function deleteChatConversation( + conversation: AiChatConversationApi.ChatConversation, +) { + try { + // 删除的二次确认 + await confirm(`是否确认删除对话 - ${conversation.title}?`); + // 发起删除 + await deleteChatConversationMy(conversation.id); + ElMessage.success('对话已删除'); + // 刷新列表 + await getChatConversationList(); + // 回调 + emits('onConversationDelete', conversation); + } catch {} +} + +/** 对话置顶 */ +async function handleTop(conversation: AiChatConversationApi.ChatConversation) { + // 更新对话置顶 + conversation.pinned = !conversation.pinned; + await updateChatConversationMy(conversation); + // 刷新对话 + await getChatConversationList(); +} + +/** 修改对话的标题 */ +async function updateConversationTitle( + conversation: AiChatConversationApi.ChatConversation, +) { + // 1. 二次确认 + await prompt({ + async beforeClose(scope) { + if (scope.isConfirm) { + if (scope.value) { + try { + // 2. 发起修改 + await updateChatConversationMy({ + id: conversation.id, + title: scope.value, + } as AiChatConversationApi.ChatConversation); + ElMessage.success('重命名成功'); + // 3. 刷新列表 + await getChatConversationList(); + // 4. 过滤当前切换的 + const filterConversationList = conversationList.value.filter( + (item) => { + return item.id === conversation.id; + }, + ); + if ( + filterConversationList.length > 0 && + filterConversationList[0] && // tip:避免切换对话 + activeConversationId.value === filterConversationList[0].id! + ) { + emits('onConversationClick', filterConversationList[0]); + } + } catch { + return false; + } + } else { + ElMessage.error('请输入标题'); + return false; + } + } + }, + component: () => { + return h(ElInput, { + placeholder: '请输入标题', + clearable: true, + modelValue: conversation.title, + }); + }, + content: '请输入标题', + title: '修改标题', + modelPropName: 'modelValue', }); - // 清空 - await deleteChatConversationMyByUnpinned(); - // 刷新列表 - await getChatConversationList(); - // 回调 - emits('onConversationClear'); } -/** 删除对话 */ -async function handleConversationDelete(id: number) { - await confirm({ - title: '删除对话', - content: h('div', {}, [ - h('p', '确认删除该对话吗?'), - h('p', '删除后,该对话将被删除,无法恢复!'), - ]), - }); - // 删除 - await deleteChatConversationMy(id); - // 刷新列表 - await getChatConversationList(); - // 回调 - emits('onConversationDelete', id); -} +// ============ 角色仓库 ============ -/** 置顶对话 */ -async function handleConversationPin(conversation: any) { - // 更新 - await updateChatConversationMy({ - id: conversation.id, - pinned: !conversation.pinned, - } as AiChatConversationApi.ChatConversation); - // 刷新列表 - await getChatConversationList(); -} - -/** 编辑对话 */ -async function handleConversationEdit(conversation: any) { - const title = await prompt({ - title: '编辑对话', - content: '请输入对话标题', - defaultValue: conversation.title, - }); - // 更新 - await updateChatConversationMy({ - id: conversation.id, - title, - } as AiChatConversationApi.ChatConversation); - // 刷新列表 - await getChatConversationList(); - // 提示 - ElMessage.success($t('ui.actionMessage.operationSuccess')); -} - -/** 打开角色仓库 */ -async function handleRoleRepositoryOpen() { +/** 角色仓库抽屉 */ +const handleRoleRepository = async () => { drawerApi.open(); -} +}; /** 监听 activeId 变化 */ watch( @@ -260,138 +292,158 @@ const { activeId } = toRefs(props); /** 初始化 */ onMounted(async () => { - // 获取对话列表 + // 获取 对话列表 await getChatConversationList(); - // 设置选中的对话 - if (activeId.value) { - activeConversationId.value = activeId.value; + // 默认选中 + if (props.activeId) { + activeConversationId.value = props.activeId; + } else { + // 首次默认选中第一个 + if (conversationList.value.length > 0 && conversationList.value[0]) { + activeConversationId.value = conversationList.value[0].id; + // 回调 onConversationClick + emits('onConversationClick', conversationList.value[0]); + } } }); -defineExpose({ getChatConversationList }); +defineExpose({ createConversation });