From 2f1702c8583ee4a0455d616457d2a35a0879fbb5 Mon Sep 17 00:00:00 2001 From: YiLin <482244139@qq.com> Date: Tue, 4 Aug 2026 14:44:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E4=BA=86=E6=99=BA=E8=83=BD=E4=BD=93?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=8C=E5=85=B6=E4=BB=96=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9A=82=E4=B8=8D=E5=8F=AF=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/Chat/Chat.vue | 315 ++++++++++++++++++++- unpackage/dist/dev/app-plus/app-service.js | 2 - utils/cloud-api.js | 26 ++ 3 files changed, 330 insertions(+), 13 deletions(-) diff --git a/pages/Chat/Chat.vue b/pages/Chat/Chat.vue index 06fdf82..0a34c80 100644 --- a/pages/Chat/Chat.vue +++ b/pages/Chat/Chat.vue @@ -20,15 +20,59 @@ - - - + + + + + + 智能体会话 + 选择专属智能体,获得精准专业服务 + + + + + + + + + + + + 选择智能体 + + + + + + + + 加载智能体列表... + + + 暂无可用智能体 + + + + + + + + {{ agent.title }} + + - - 智能体会话 - 选择专属智能体,获得精准专业服务 - - + {{ agent.description }} + + + + + + 取消 @@ -315,7 +359,8 @@ createConversation, getUserInfo, getUserAvatar, - conversationMessageDownload + conversationMessageDownload, + getAgentList } from '@/utils/cloud-api.js' import { getToken, @@ -689,6 +734,66 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener. showNewChatModal.value = false; } + // 智能体选择相关 + const showAgentModal = ref(false) + const agentList = ref([]) + const agentLoading = ref(false) + + const selectAgentChat = async () => { + try { + showNewChatModal.value = false + showAgentModal.value = true + agentLoading.value = true + agentList.value = [] + // getAgentList 直接返回智能体对象数组 + const agents = await getAgentList(userToken.value) + if (agents && Array.isArray(agents)) { + agentList.value = agents + } else { + uni.showToast({ title: '获取智能体列表失败', icon: 'none' }) + } + } catch (error) { + console.error('获取智能体列表失败:', error) + uni.showToast({ title: '获取智能体列表失败,请重试', icon: 'none' }) + } finally { + agentLoading.value = false + } + } + + const closeAgentModal = () => { + showAgentModal.value = false + agentList.value = [] + } + + const handleAgentSelect = async (agent) => { + console.log("点击了",agent.title); + // try { + // closeAgentModal() + // const chars = '0123456789abcdef' + // let name = '' + // for (let i = 0; i < 24; i++) { + // name += chars[Math.floor(Math.random() * chars.length)] + // } + // const workspaceId = await createWorkspace(userToken.value, name) + // if (!workspaceId) { + // uni.showToast({ title: '工作区创建失败', icon: 'none' }) + // return + // } + // const loginInfo = uni.getStorageSync('yxd_login_info') + // const userName = loginInfo ? (loginInfo.username || '') : '' + // const conversationId = await createConversation(userToken.value, workspaceId, agent.title, userName) + // if (!conversationId) { + // uni.showToast({ title: '智能体会话创建失败', icon: 'none' }) + // return + // } + // uni.showToast({ title: `已创建「${agent.title}」会话`, icon: 'success' }) + // takeUserConversations() + // } catch (error) { + // console.error('创建智能体会话失败:', error) + // uni.showToast({ title: '创建失败,请重试', icon: 'none' }) + // } + } + // 侧边栏相关 const isChatSidebar = ref(false) const handleChatSidebar = () => { @@ -1500,8 +1605,8 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener. const takeConversationMessages = async () => { try { allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || []; - console.log("获取到的所有消息:", JSON.stringify(allmessages.value) ); - console.log("获取到的所有消息:", allmessages.value); + // console.log("获取到的所有消息:", JSON.stringify(allmessages.value) ); + // console.log("获取到的所有消息:", allmessages.value); // currentMessages.value = allmessages.value.slice(-pageInfoNumber); // 数据获取后执行滚动 scrollToBottom(); @@ -1702,6 +1807,194 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener. diff --git a/unpackage/dist/dev/app-plus/app-service.js b/unpackage/dist/dev/app-plus/app-service.js index d87f692..3840b66 100644 --- a/unpackage/dist/dev/app-plus/app-service.js +++ b/unpackage/dist/dev/app-plus/app-service.js @@ -6692,8 +6692,6 @@ This will fail in production.`); const takeConversationMessages = async () => { try { allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || []; - formatAppLog("log", "at pages/Chat/Chat.vue:1503", "获取到的所有消息:", JSON.stringify(allmessages.value)); - formatAppLog("log", "at pages/Chat/Chat.vue:1504", "获取到的所有消息:", allmessages.value); scrollToBottom(); } catch (error) { uni.showToast({ diff --git a/utils/cloud-api.js b/utils/cloud-api.js index 095cfbd..765adcd 100644 --- a/utils/cloud-api.js +++ b/utils/cloud-api.js @@ -1718,3 +1718,29 @@ export const conversationMessageDownload = (token, workspacesId, localUrl) => { }); }); }; + +// 智能体 +// 获取智能体列表 +export const getAgentList = (token) =>{ + return new Promise((resolve,reject)=>{ + uni.request({ + url:`${BASE_URL}/cloud_api/agent/list`, + method:"POST", + header:{'Content-Type':'application/json'}, + data:{"access_token":token}, + success: (res) => { + if(res.statusCode === 200){ + const respond = res.data; + if(respond.success){ + resolve(respond.data) + } else { + const msg = '获取智能体列表出错啦'; + reject(msg); + } + }else{ + reject(`获取智能体列表失败:${res.statusCode}`) + } + } + }) + }) +}