接了智能体列表,其他接口暂不可接

This commit is contained in:
2026-08-04 14:44:48 +08:00
parent c4fb90b755
commit 2f1702c858
3 changed files with 330 additions and 13 deletions

View File

@@ -20,15 +20,59 @@
</view> </view>
<uni-icons type="arrow-right" class="arrow-right-style"></uni-icons> <uni-icons type="arrow-right" class="arrow-right-style"></uni-icons>
</view> </view>
<view class="ncd-option ncd-intelligence"> <view class="ncd-option ncd-intelligence" @click="selectAgentChat">
<view class="ncd-opt-icon"> <view class="ncd-opt-icon">
<uni-icons type="star" color="#ffffff" size="30"></uni-icons> <uni-icons type="star" color="#ffffff" size="30"></uni-icons>
</view>
<view class="ncd-opt-title">
<view class="ncd-opt-title-1">智能体会话</view>
<view class="ncd-opt-title-2">选择专属智能体获得精准专业服务</view>
</view>
<uni-icons type="arrow-right" class="arrow-right-style"></uni-icons>
</view>
</view>
</view>
</view>
<!-- 智能体选择弹窗 -->
<view class="agent-modal-mask" v-if="showAgentModal" @click="closeAgentModal">
<view class="agent-modal" @click.stop>
<view class="agent-modal-header">
<text class="agent-modal-title">选择智能体</text>
<view class="agent-modal-close" @click="closeAgentModal">
<uni-icons type="closeempty" size="20" color="#999"></uni-icons>
</view>
</view>
<scroll-view class="agent-list" scroll-y="true">
<view v-if="agentLoading" class="agent-loading">
<uni-icons type="spinner-cycle" size="24" color="#1677ff"></uni-icons>
<text class="agent-loading-text">加载智能体列表...</text>
</view>
<view v-else-if="agentList.length === 0" class="agent-empty">
<text class="agent-empty-text">暂无可用智能体</text>
</view>
<view v-else
v-for="agent in agentList"
:key="agent._id"
class="agent-card"
@click="handleAgentSelect(agent)"
>
<view class="agent-card-header">
<view class="agent-avatar">
<uni-icons type="vip" size="22" color="#fff"></uni-icons>
</view>
<view class="agent-card-info">
<text class="agent-card-title">{{ agent.title }}</text>
<!-- <text class="agent-card-category">{{ agent.category_name }}</text> -->
</view>
</view> </view>
<view class="ncd-opt-title"> <text class="agent-card-desc">{{ agent.description }}</text>
<view class="ncd-opt-title-1">智能体会话</view> <!-- <text class="agent-card-welcome" v-if="agent.welcome_message">{{ agent.welcome_message }}</text> -->
<view class="ncd-opt-title-2">选择专属智能体获得精准专业服务</view> </view>
</view> </scroll-view>
<uni-icons type="arrow-right" class="arrow-right-style"></uni-icons> <view class="agent-modal-footer">
<view class="agent-modal-btn agent-modal-btn-cancel" @click="closeAgentModal">
<text>取消</text>
</view> </view>
</view> </view>
</view> </view>
@@ -315,7 +359,8 @@
createConversation, createConversation,
getUserInfo, getUserInfo,
getUserAvatar, getUserAvatar,
conversationMessageDownload conversationMessageDownload,
getAgentList
} from '@/utils/cloud-api.js' } from '@/utils/cloud-api.js'
import { import {
getToken, getToken,
@@ -689,6 +734,66 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
showNewChatModal.value = false; 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 isChatSidebar = ref(false)
const handleChatSidebar = () => { const handleChatSidebar = () => {
@@ -1500,8 +1605,8 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
const takeConversationMessages = async () => { const takeConversationMessages = async () => {
try { try {
allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || []; allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || [];
console.log("获取到的所有消息:", JSON.stringify(allmessages.value) ); // console.log("获取到的所有消息:", JSON.stringify(allmessages.value) );
console.log("获取到的所有消息:", allmessages.value); // console.log("获取到的所有消息:", allmessages.value);
// currentMessages.value = allmessages.value.slice(-pageInfoNumber); // currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// 数据获取后执行滚动 // 数据获取后执行滚动
scrollToBottom(); scrollToBottom();
@@ -1702,6 +1807,194 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
<style lang="scss" scoped> <style lang="scss" scoped>
@import "./chat.css"; @import "./chat.css";
/* ========== 智能体选择弹窗 ========== */
.agent-modal-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.45);
backdrop-filter: blur(4px);
-webkit-backdrop-filter: blur(4px);
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
}
.agent-modal {
width: 85%;
max-height: 70%;
background-color: #ffffff;
border-radius: 24rpx;
overflow: hidden;
display: flex;
flex-direction: column;
box-shadow: 0 16rpx 48rpx rgba(0, 0, 0, 0.12);
}
.agent-modal-header {
display: flex;
justify-content: center;
align-items: center;
padding: 30rpx 30rpx 20rpx;
position: relative;
border-bottom: 2rpx solid #f0f0f0;
}
.agent-modal-title {
font-size: 34rpx;
font-weight: 700;
color: #1a1a2e;
}
.agent-modal-close {
position: absolute;
right: 24rpx;
top: 50%;
transform: translateY(-50%);
padding: 10rpx;
}
.agent-list {
box-sizing: border-box;
flex: 1;
padding: 20rpx 24rpx;
max-height: 600rpx;
}
.agent-loading {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60rpx 0;
}
.agent-loading-text {
margin-top: 16rpx;
font-size: 26rpx;
color: #999;
}
.agent-empty {
display: flex;
align-items: center;
justify-content: center;
padding: 80rpx 0;
}
.agent-empty-text {
font-size: 28rpx;
color: #999;
}
.agent-card {
box-sizing: border-box;
width: 100%;
background: linear-gradient(135deg, #f8f5ff, #efe8ff);
border: 2rpx solid #c4b5fd;
border-radius: 20rpx;
padding: 28rpx 24rpx;
margin-bottom: 20rpx;
transition: all 0.2s ease;
overflow: hidden;
}
.agent-card:active {
transform: scale(0.98);
border-color: #a78bfa;
background: linear-gradient(135deg, #f3efff, #e8dcff);
}
.agent-card-header {
display: flex;
align-items: center;
margin-bottom: 16rpx;
}
.agent-avatar {
width: 70rpx;
height: 70rpx;
border-radius: 20rpx;
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.agent-card-info {
margin-left: 16rpx;
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
}
.agent-card-title {
font-size: 30rpx;
font-weight: 600;
color: #1a1a2e;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.agent-card-category {
font-size: 22rpx;
color: #8b5cf6;
margin-top: 4rpx;
}
.agent-card-desc {
font-size: 26rpx;
color: #555;
line-height: 1.5;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
overflow: hidden;
}
.agent-card-welcome {
font-size: 24rpx;
color: #7c3aed;
margin-top: 12rpx;
padding-top: 12rpx;
border-top: 2rpx dashed #ddd6fe;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.agent-modal-footer {
padding: 20rpx 30rpx 30rpx;
border-top: 2rpx solid #f0f0f0;
display: flex;
justify-content: flex-end;
}
.agent-modal-btn {
padding: 18rpx 48rpx;
border-radius: 16rpx;
font-size: 28rpx;
font-weight: 500;
}
.agent-modal-btn-cancel {
background: #f0f0f0;
color: #666;
}
.agent-modal-btn-cancel:active {
background: #e0e0e0;
}
</style> </style>
<!-- v-html 渲染的 markdown 内容无法被 scoped 样式命中需非 scoped 样式块 --> <!-- v-html 渲染的 markdown 内容无法被 scoped 样式命中需非 scoped 样式块 -->

View File

@@ -6692,8 +6692,6 @@ This will fail in production.`);
const takeConversationMessages = async () => { const takeConversationMessages = async () => {
try { try {
allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || []; 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(); scrollToBottom();
} catch (error) { } catch (error) {
uni.showToast({ uni.showToast({

View File

@@ -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}`)
}
}
})
})
}