Compare commits

...

12 Commits

Author SHA1 Message Date
6bb7f37276 优化加载信息,优化气泡字体大小 2026-08-06 16:55:37 +08:00
23a03d0ed3 Revert "添加日志窗口,辅助测试。"
This reverts commit d1a56f5b23.
2026-08-06 16:21:41 +08:00
d1a56f5b23 添加日志窗口,辅助测试。 2026-08-06 09:37:37 +08:00
add3802d62 界面隐显后继续流式输出;优化中断逻辑 2026-08-06 08:52:06 +08:00
b4e69802c0 优化好友和群聊新建会话逻辑。 2026-08-05 17:56:12 +08:00
941070a2ee 优化新建会话逻辑 2026-08-05 17:31:48 +08:00
2fff814c79 创建智能体 2026-08-05 17:22:00 +08:00
fb421cd021 好友,群聊分页加载 2026-08-05 14:51:15 +08:00
e0d7f93c80 ai对话分页 2026-08-05 11:42:57 +08:00
fbda01a624 两端同步流式输出,刷新状态,强制退出。 2026-08-04 17:49:42 +08:00
b7c3fc9ff6 输出后闪白修复 2026-08-04 15:31:01 +08:00
2f1702c858 接了智能体列表,其他接口暂不可接 2026-08-04 14:44:48 +08:00
10 changed files with 1952 additions and 247 deletions

View File

@@ -269,7 +269,12 @@
// 新建会话
const openNewChatModal = () => {
console.log("点击了新建会话");
// 好友会话(1)或群聊(2)时,跳转到通讯录页面发起新聊天
if (chatType.value === 1 || chatType.value === 2) {
goContactPages()
return
}
// AI 聊天(0)时,弹出新建会话弹窗
emit('update:showNewChatModal', true)
}

View File

@@ -212,6 +212,194 @@
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}
/* ========== 智能体选择弹窗 ========== */
.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;
}
/* ==========新建聊天列表相关====== */
.close-option-card {
width: 100%;
@@ -319,6 +507,10 @@
font-size: 48rpx;
}
.chat-btn-group .head-btn:nth-child(4) {
/* 刷新按钮 */
}
.log-out {
/* background: #ffd4d4; */
}

View File

@@ -20,15 +20,59 @@
</view>
<uni-icons type="arrow-right" class="arrow-right-style"></uni-icons>
</view>
<view class="ncd-option ncd-intelligence">
<view class="ncd-opt-icon">
<uni-icons type="star" color="#ffffff" size="30"></uni-icons>
<view class="ncd-option ncd-intelligence" @click="selectAgentChat">
<view class="ncd-opt-icon">
<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 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>
<text class="agent-card-desc">{{ agent.description }}</text>
<!-- <text class="agent-card-welcome" v-if="agent.welcome_message">{{ agent.welcome_message }}</text> -->
</view>
</scroll-view>
<view class="agent-modal-footer">
<view class="agent-modal-btn agent-modal-btn-cancel" @click="closeAgentModal">
<text>取消</text>
</view>
</view>
</view>
@@ -55,10 +99,13 @@
<view class="head-btn" @click="goWorkSpace">
<view class="iconfont icon-wenjianjia"></view>
</view>
<view class="head-btn" @click="goCloudDatabase">
<view class="iconfont icon-cloud"></view>
</view>
<view class="head-btn log-out" @click="logOut">
<view class="head-btn" @click="goCloudDatabase">
<view class="iconfont icon-cloud"></view>
</view>
<view class="head-btn" @click="handleRefresh">
<uni-icons type="refreshempty" size="24" color="#52c41a"></uni-icons>
</view>
<view class="head-btn log-out" @click="logOut">
<view class="iconfont icon-tuichu"></view>
</view>
</view>
@@ -74,8 +121,12 @@
</view>
<view class="main-chat">
<scroll-view class="chat-messages" direction="vertical" scroll-y :scroll-into-view="scrollToView"
:upper-threshold="0" :scroll-with-animation="!isThinking" @scroll="onScroll">
<scroll-view class="chat-messages" direction="vertical" scroll-y :scroll-into-view="scrollToView"
:upper-threshold="50" :scroll-with-animation="scrollAnimationEnabled && !isThinking" @scroll="onScroll" @scrolltoupper="onScrollToUpper">
<!-- 加载更多提示 -->
<view v-if="(ChatType === 0 && isAILoadingMore) || (ChatType === 1 && isFriendLoadingMore) || (ChatType === 2 && isGroupLoadingMore)" class="load-more-tip">
<text>加载更多消息...</text>
</view>
<!-- 消息加载中弹窗仅会话变化时显示 -->
<view v-if="isLoadingMessages" class="messages-loading-overlay">
<view class="messages-loading-card">
@@ -315,7 +366,9 @@
createConversation,
getUserInfo,
getUserAvatar,
conversationMessageDownload
conversationMessageDownload,
getAgentList,
addConversationAgent
} from '@/utils/cloud-api.js'
import {
getToken,
@@ -672,7 +725,10 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
return
}
closeNewChatModal();
takeUserConversations();
await takeUserConversations();
// 切换到新创建的会话
currentSessionId.value = conversationId;
uni.setStorageSync('currentSessionId', conversationId);
} catch (error) {
// ❌ 统一捕获异步错误,防止崩溃
@@ -689,6 +745,61 @@ 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) => {
closeAgentModal()
uni.showLoading({ title: '正在创建智能体...', mask: true })
try {
const result = await addConversationAgent(userToken.value, agent._id)
if (!result || !result.conversation_id) {
uni.hideLoading()
uni.showToast({ title: '智能体会话创建失败', icon: 'none' })
return
}
// 刷新会话列表
await takeUserConversations()
// 切换到新创建的会话并持久化
currentSessionId.value = result.conversation_id
uni.setStorageSync('currentSessionId', result.conversation_id)
uni.hideLoading()
uni.showToast({ title: `已创建「${result.title || agent.title}」会话`, icon: 'success' })
} catch (error) {
uni.hideLoading()
console.error('创建智能体会话失败:', error)
uni.showToast({ title: typeof error === 'string' ? error : '创建失败,请重试', icon: 'none' })
}
}
// 侧边栏相关
const isChatSidebar = ref(false)
const handleChatSidebar = () => {
@@ -734,6 +845,71 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
})
}
// 刷新当前会话消息
const handleRefresh = async () => {
// 1. 重置输入框状态
isThinking.value = false
isSelfSent.value = false
socketStore.isThinking = false
textMessage.value = ''
uploadedFiles.value = []
previewFileArray.value = []
// 移除流式消息占位
if (streamingMessageId.value) {
allmessages.value = allmessages.value.filter(m => m._id !== streamingMessageId.value)
streamingMessageId.value = null
}
const titleMap = { 0: 'AI消息', 1: '好友消息', 2: '群聊消息' }
const title = titleMap[ChatType.value] || '消息'
uni.showLoading({ title: `刷新${title}中...`, mask: true })
try {
// 2. 检查当前 token 是否还有效
const token = getToken()
if (!token) {
uni.hideLoading()
uni.showToast({ title: '登录已失效,请重新登录', icon: 'none', duration: 1500 })
setTimeout(() => uni.reLaunch({ url: '/pages/Login/Login' }), 1500)
return
}
await getUserInfo(token)
// 3. 确保 AI 对话模式下 socket 连接正常PC 离线由 watcher 实时监控)
if (ChatType.value === 0 && !socketStore.isConnected) {
await handleConnect()
}
// 4. 刷新消息
switch (ChatType.value) {
case 0:
await takeConversationMessages()
break
case 1:
await takeFriendMessages()
break
case 2:
await takeGroupMessages()
break
default:
await takeConversationMessages()
break
}
uni.hideLoading()
uni.showToast({ title: '已刷新', icon: 'success', duration: 1200 })
} catch (e) {
uni.hideLoading()
// 区分 token 失效和其他错误
const errMsg = typeof e === 'string' ? e : (e?.message || '')
if (errMsg.includes('token') || errMsg.includes('Token') || errMsg.includes('登录') || errMsg.includes('过期')) {
uni.showToast({ title: '登录已失效,请重新登录', icon: 'none', duration: 1500 })
setTimeout(() => uni.reLaunch({ url: '/pages/Login/Login' }), 1500)
} else {
uni.showToast({ title: '刷新失败', icon: 'error', duration: 1500 })
}
}
}
const previewFileArray = ref([])
const uploadPhoto = () => {
console.log('点击了拍照上传');
@@ -1242,13 +1418,14 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
streamingMessageId.value = null
}
// 立即关闭弹窗,清除超时
// clearTimeout(aiResponseTimer)
isThinking.value = false
socketStore.isThinking = false
isSelfSent.value = false
textMessage.value = ''
uploadedFiles.value = []
// takeConversationMessages 由后端中断确认驱动(见 handleBusinessMessage
// 中断后刷新消息列表,获取服务端最终状态
await takeConversationMessages()
// await takeUserConversations()
uni.showToast({
title: '已中断',
icon: 'none',
@@ -1257,13 +1434,16 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
}
// 全局监听 socketStore.isThinking跨设备同步思考状态锁/解锁输入框
watch(() => socketStore.isThinking, (newVal, oldVal) => {
watch(() => socketStore.isThinking, async (newVal, oldVal) => {
console.log("isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
// false → true后端开始回复锁定输入框
if (!oldVal && newVal) {
console.log('AI开始回复跨设备同步锁定输入框');
isThinking.value = true
// 非本设备发起时,也需要添加流式气泡
// 跨设备场景:先加载最新消息(含 PC 发的用户消息),再追加流式气泡
if (!isSelfSent.value) {
await takeConversationMessages()
}
if (!streamingMessageId.value) {
streamingMessageId.value = 'streaming-' + Date.now()
allmessages.value = [...allmessages.value, {
@@ -1278,12 +1458,14 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
// true → falseAI 回复结束或中断,解锁输入框并刷新消息列表
if (oldVal && !newVal) {
console.log('AI回复结束正常/中断),解锁并刷新消息列表');
// 移除流式消息气泡,从服务器加载完整消息
// 先从服务器加载完整消息列表
await takeConversationMessages()
// 加载完成后再移除流式消息气泡,避免闪白
if (streamingMessageId.value) {
allmessages.value = allmessages.value.filter(m => m._id !== streamingMessageId.value)
streamingMessageId.value = null
}
takeConversationMessages()
isThinking.value = false
isSelfSent.value = false
textMessage.value = ''
@@ -1309,6 +1491,25 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
}
})
// 监听 pc_offlinePC 端下线时立即强制跳转登录页
watch(() => socketStore.pcOffline, (offline) => {
if (offline) {
isThinking.value = false
socketStore.isThinking = false
socketStore.pcOffline = false
uni.showToast({
title: 'PC端不在线请先登录',
icon: 'none',
duration: 1500
})
setTimeout(() => {
uni.reLaunch({
url: '/pages/Login/Login'
})
}, 1500)
}
})
// 监听流式消息内容,实时更新 AI 回复(流式输出核心)
watch(() => socketStore.messageString, (newContent) => {
if (!streamingMessageId.value || !socketStore.isThinking) return
@@ -1486,9 +1687,25 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
const scrollToView = ref('')
const bottomToggle = ref(false)
const scrollAnimationEnabled = ref(true) // 控制 scroll-with-animation加载更多时关闭避免可见滑动
// 加载状态和分页相关变量
const isLoadingMore = ref(false) // 是否正在加载更多
const isAILoadingMore = ref(false) // AI 会话是否正在加载更多(滚动到顶部触发)
const aiPageNumber = ref(0) // AI 会话当前服务端页码0-based
const hasMoreAIMessages = ref(true) // AI 会话是否还有更多消息可加载
const currentPage = ref(1) // 当前页码(如果后端支持分页)
const pageSize = 20;
// 好友消息分页
const isFriendLoadingMore = ref(false) // 好友会话是否正在加载更多
const friendPageNumber = ref(1) // 好友消息当前页码1-based
const hasMoreFriendMessages = ref(true) // 好友会话是否还有更多消息
// 群聊消息分页
const isGroupLoadingMore = ref(false) // 群聊会话是否正在加载更多
const groupPageNumber = ref(1) // 群聊消息当前页码1-based
const hasMoreGroupMessages = ref(true) // 群聊会话是否还有更多消息
const groupSize = 100;
// 计算属性:自动根据 allmessages 和 currentPage 计算显示消息
const currentMessages = computed(() => {
// return allmessages.value.slice(-pageInfoNumber);
@@ -1499,9 +1716,12 @@ 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);
aiPageNumber.value = 0
hasMoreAIMessages.value = true
const rawMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize, 0) || [];
// API 返回的数据已被过滤,无法通过数量判断是否有更多,始终尝试加载更多
allmessages.value = rawMessages
// console.log("获取到的所有消息:", JSON.stringify(allmessages.value) );
// currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// 数据获取后执行滚动
scrollToBottom();
@@ -1516,7 +1736,10 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
}
const takeFriendMessages = async () => {
try {
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
friendPageNumber.value = 1
hasMoreFriendMessages.value = true
const rawMessages = await getFriendMessages(currentSessionId.value, pageSize, 0) || [];
allmessages.value = rawMessages
// console.log("好友消息:", JSON.stringify(allmessages.value));
// 数据获取后执行滚动
scrollToBottom();
@@ -1531,7 +1754,10 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
}
const takeGroupMessages = async () => {
try {
allmessages.value = await getGroupMessages(currentSessionId.value) || [];
groupPageNumber.value = 1
hasMoreGroupMessages.value = true
const rawMessages = await getGroupMessages(currentSessionId.value, pageSize, 0) || [];
allmessages.value = rawMessages
console.log("群聊消息:", allmessages.value);
// 获取群成员列表并获取头像
const memberList = await getGroupMemberList(currentSessionId.value)
@@ -1569,7 +1795,102 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
// // currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// }
// 滚动到顶部时加载更多消息(根据 ChatType 分发)
const onScrollToUpper = async () => {
if (ChatType.value === 0) {
await loadMoreAIMessages()
} else if (ChatType.value === 1) {
await loadMoreFriendMessages()
} else if (ChatType.value === 2) {
await loadMoreGroupMessages()
}
}
// 加载更多 AI 历史消息(上一页),并定位到原第一条消息
const loadMoreAIMessages = async () => {
if (isAILoadingMore.value || !hasMoreAIMessages.value || !currentSessionId.value) return
isAILoadingMore.value = true
try {
const nextPage = aiPageNumber.value + 1
const olderMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize, nextPage)
if (olderMessages && olderMessages.length > 0) {
aiPageNumber.value = nextPage
allmessages.value = [...olderMessages, ...allmessages.value]
// 定位滚动原本第一条消息old index 0现在在 index = olderMessages.length 处
await nextTick()
scrollAnimationEnabled.value = false // 关闭动画,无感定位
scrollToView.value = 'msg-' + olderMessages.length
await nextTick()
scrollAnimationEnabled.value = true
} else {
// 只有 API 返回空时才确认没有更多
hasMoreAIMessages.value = false
}
} catch (e) {
console.error('加载更多消息失败:', e)
uni.showToast({ title: '加载更多失败', icon: 'none' })
} finally {
isAILoadingMore.value = false
}
}
// 加载更多好友历史消息(上一页),并定位到原第一条消息
const loadMoreFriendMessages = async () => {
if (isFriendLoadingMore.value || !hasMoreFriendMessages.value || !currentSessionId.value) return
isFriendLoadingMore.value = true
try {
const nextPage = friendPageNumber.value + 1
const olderMessages = await getFriendMessages(currentSessionId.value, pageSize, nextPage)
if (olderMessages && olderMessages.length > 0) {
friendPageNumber.value = nextPage
allmessages.value = [...olderMessages, ...allmessages.value]
// 定位滚动
await nextTick()
scrollAnimationEnabled.value = false
scrollToView.value = 'msg-' + olderMessages.length
await nextTick()
scrollAnimationEnabled.value = true
} else {
hasMoreFriendMessages.value = false
}
} catch (e) {
console.error('加载更多好友消息失败:', e)
uni.showToast({ title: '加载更多失败', icon: 'none' })
} finally {
isFriendLoadingMore.value = false
}
}
// 加载更多群聊历史消息(上一页),并定位到原第一条消息
const loadMoreGroupMessages = async () => {
if (isGroupLoadingMore.value || !hasMoreGroupMessages.value || !currentSessionId.value) return
isGroupLoadingMore.value = true
try {
const nextPage = groupPageNumber.value + 1
const olderMessages = await getGroupMessages(currentSessionId.value, pageSize, nextPage)
if (olderMessages && olderMessages.length > 0) {
groupPageNumber.value = nextPage
allmessages.value = [...olderMessages, ...allmessages.value]
// 定位滚动
await nextTick()
scrollAnimationEnabled.value = false
scrollToView.value = 'msg-' + olderMessages.length
await nextTick()
scrollAnimationEnabled.value = true
} else {
hasMoreGroupMessages.value = false
}
} catch (e) {
console.error('加载更多群聊消息失败:', e)
uni.showToast({ title: '加载更多失败', icon: 'none' })
} finally {
isGroupLoadingMore.value = false
}
}
// 监听滚动
const onScroll = (e) => {}
@@ -1672,10 +1993,23 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
if (chatType === 0) {
await takeUserConversations();
// 只有在会话ID存在时才获取消息
// 如果正在流式输出,跳过重新加载消息列表,避免打断流式输出
if (currentSessionId.value) {
isLoadingMessages.value = true
takeConversationMessages();
if (socketStore.isThinking) {
// 流式输出中:不刷新消息,但确保消息列表中包含流式气泡
// 如果流式气泡因某些原因丢失,重新创建
if (streamingMessageId.value && !allmessages.value.some(m => m._id === streamingMessageId.value)) {
allmessages.value = [...allmessages.value, {
role: 'assistant',
content: socketStore.messageString || '',
_streaming: true,
_id: streamingMessageId.value
}]
}
} else {
isLoadingMessages.value = true
takeConversationMessages();
}
}
// AI 对话页面:主动建立 socket 连接,确保消息实时推送
if (userToken.value && currentSessionId.value && !socketStore.isConnected) {
@@ -1702,71 +2036,149 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
<style lang="scss" scoped>
@import "./chat.css";
</style>
<!-- v-html 渲染的 markdown 内容无法被 scoped 样式命中需非 scoped 样式块 -->
<style lang="scss">
// /* 气泡内容字体:确保 v-html 渲染的 markdown 内容使用系统字体栈 */
// .chat-content {
// // font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans', 'MiSans',
// // 'Source Han Sans CN', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
// // font-weight: 400;
// font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans', 'MiSans',
// 'Source Han Sans CN', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif !important;
// font-size: 16px !important;
// font-weight: 600 !important;
// line-height: 1.6;
// margin: 8rpx 0;
// h1 {
// font-size: 42rpx;
// line-height: 1.4;
// margin: 16rpx 0 10rpx;
// }
// h2 {
// font-size: 38rpx;
// line-height: 1.4;
// margin: 14rpx 0 8rpx;
// }
// h3 {
// font-size: 36rpx;
// line-height: 1.4;
// margin: 12rpx 0 8rpx;
// }
// h4,
// h5,
// h6 {
// font-size: 34rpx;
// line-height: 1.5;
// margin: 10rpx 0 6rpx;
// }
// /* 普通正文 */
// p,
// text,
// span {
// font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans', 'MiSans',
// 'Source Han Sans CN', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif !important;
// font-size: 38rpx !important;
// font-weight: 400 !important;
// line-height: 1.6;
// margin: 8rpx 0;
// }
// /* 粗体和斜体样式 */
// strong,
// b {
// font-weight: 600 !important;
// }
// em,
// i {
// font-style: italic !important;
// }
/* 气泡内容字体:确保 v-html 渲染的 markdown 内容使用系统字体栈 */
.chat-content {
// font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans', 'MiSans',
// 'Source Han Sans CN', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
// font-weight: 400;
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans', 'MiSans',
'Source Han Sans CN', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif !important;
font-size: 16px !important;
font-weight: 600 !important;
line-height: 1.6;
margin: 8rpx 0;
font-size: 30rpx !important;
line-height: 48rpx !important;
margin: 8rpx 0 !important;
h1 {
font-size: 42rpx;
line-height: 1.4;
margin: 16rpx 0 10rpx;
font-size: 34rpx !important;
font-weight: 600 !important;
line-height: 56rpx !important;
margin: 22rpx 0 14rpx !important;
}
h2 {
font-size: 38rpx;
line-height: 1.4;
margin: 14rpx 0 8rpx;
font-size: 32rpx !important;
font-weight: 600 !important;
line-height: 52rpx !important;
margin: 18rpx 0 10rpx !important;
}
h3 {
font-size: 36rpx;
line-height: 1.4;
margin: 12rpx 0 8rpx;
font-size: 30rpx !important;
font-weight: 600 !important;
line-height: 48rpx !important;
margin: 14rpx 0 6rpx !important;
}
h4,
h5,
h4 {
font-size: 28rpx !important;
font-weight: 600 !important;
line-height: 48rpx !important;
margin: 14rpx 0 6rpx !important;
}
h5 {
font-size: 26rpx !important;
font-weight: 600 !important;
line-height: 44rpx !important;
margin: 10rpx 0 4rpx !important;
}
h6 {
font-size: 34rpx;
line-height: 1.5;
margin: 10rpx 0 6rpx;
font-size: 24rpx !important;
font-weight: 600 !important;
line-height: 40rpx !important;
margin: 10rpx 0 4rpx !important;
}
/* 普通正文 */
p,
text,
span {
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans', 'MiSans',
'Source Han Sans CN', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif !important;
font-size: 38rpx !important;
font-weight: 400 !important;
line-height: 1.6;
margin: 8rpx 0;
font-size: 30rpx !important;
line-height: 48rpx !important;
margin: 8rpx 0 !important;
}
/* 粗体和斜体样式 */
strong,
b {
font-weight: 600 !important;
}
em,
i {
font-style: italic !important;
}
/* 气泡内的内联链接(替代 <a> 标签,点击由 JS 拦截处理) */
.chat-inline-link {

View File

@@ -66,7 +66,11 @@
</view>
<view class="main-chat">
<scroll-view class="chat-messages" direction="vertical" scroll-y :scroll-into-view="scrollToView"
:upper-threshold="0" :scroll-with-animation="true" @scroll="onScroll">
:upper-threshold="50" :scroll-with-animation="true" @scroll="onScroll" @scrolltoupper="onScrollToUpper">
<!-- 加载更多提示 -->
<view v-if="(ChatType === 0 && isAILoadingMore) || (ChatType === 1 && isFriendLoadingMore) || (ChatType === 2 && isGroupLoadingMore)" class="load-more-tip">
<text>加载更多消息...</text>
</view>
<!-- 与AI的对话内容展示 -->
<template v-for="(message, index) in currentMessages" :key="index">
<view v-if="ChatType === 0 && message.role !== 'tool'" class="chat-message" :id="'msg-' + index"
@@ -1317,6 +1321,22 @@ import { openFile as openFileNative } from '@/utils/fileOpener.js'
// 加载状态和分页相关变量
const isLoadingMore = ref(false) // 是否正在加载更多
const currentPage = ref(1) // 当前页码(如果后端支持分页)
const pageSize = 200;
// AI 消息分页
const isAILoadingMore = ref(false)
const aiPageNumber = ref(0) // AI 会话当前服务端页码0-based
const hasMoreAIMessages = ref(true)
// 好友消息分页
const isFriendLoadingMore = ref(false)
const friendPageNumber = ref(1) // 好友消息当前页码1-based
const hasMoreFriendMessages = ref(true)
// 群聊消息分页
const isGroupLoadingMore = ref(false)
const groupPageNumber = ref(1) // 群聊消息当前页码1-based
const hasMoreGroupMessages = ref(true)
// 计算属性:自动根据 allmessages 和 currentPage 计算显示消息
const currentMessages = computed(() => {
// return allmessages.value.slice(-pageInfoNumber);
@@ -1327,9 +1347,11 @@ import { openFile as openFileNative } from '@/utils/fileOpener.js'
// 获取对话消息
const takeConversationMessages = async () => {
try {
allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || [];
aiPageNumber.value = 0
hasMoreAIMessages.value = true
const rawMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize, 0) || [];
allmessages.value = rawMessages
// console.log("获取到的所有消息:", JSON.stringify(allmessages.value) );
// currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// 数据获取后执行滚动
scrollToBottom();
} catch (error) {
@@ -1341,7 +1363,10 @@ import { openFile as openFileNative } from '@/utils/fileOpener.js'
}
const takeFriendMessages = async () => {
try {
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
friendPageNumber.value = 1
hasMoreFriendMessages.value = true
const rawMessages = await getFriendMessages(currentSessionId.value, 1) || [];
allmessages.value = rawMessages
// console.log("好友消息:", JSON.stringify(allmessages.value));
// 数据获取后执行滚动
scrollToBottom();
@@ -1354,7 +1379,10 @@ import { openFile as openFileNative } from '@/utils/fileOpener.js'
}
const takeGroupMessages = async () => {
try {
allmessages.value = await getGroupMessages(currentSessionId.value) || [];
groupPageNumber.value = 1
hasMoreGroupMessages.value = true
const rawMessages = await getGroupMessages(currentSessionId.value, 1) || [];
allmessages.value = rawMessages
console.log("群聊消息:", allmessages.value);
// 获取群成员列表并获取头像
const memberList = await getGroupMemberList(currentSessionId.value)
@@ -1394,6 +1422,90 @@ import { openFile as openFileNative } from '@/utils/fileOpener.js'
// 监听滚动
const onScroll = (e) => {}
// 滚动到顶部时加载更多消息(根据 ChatType 分发)
const onScrollToUpper = async () => {
if (ChatType.value === 0) {
await loadMoreAIMessages()
} else if (ChatType.value === 1) {
await loadMoreFriendMessages()
} else if (ChatType.value === 2) {
await loadMoreGroupMessages()
}
}
// 加载更多 AI 历史消息(上一页),并定位到原第一条消息
const loadMoreAIMessages = async () => {
if (isAILoadingMore.value || !hasMoreAIMessages.value || !currentSessionId.value) return
isAILoadingMore.value = true
try {
const nextPage = aiPageNumber.value + 1
const olderMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize, nextPage)
if (olderMessages && olderMessages.length > 0) {
aiPageNumber.value = nextPage
allmessages.value = [...olderMessages, ...allmessages.value]
await nextTick()
scrollToView.value = 'msg-' + olderMessages.length
} else {
hasMoreAIMessages.value = false
}
} catch (e) {
console.error('加载更多AI消息失败:', e)
uni.showToast({ title: '加载更多失败', icon: 'none' })
} finally {
isAILoadingMore.value = false
}
}
// 加载更多好友历史消息(上一页),并定位到原第一条消息
const loadMoreFriendMessages = async () => {
if (isFriendLoadingMore.value || !hasMoreFriendMessages.value || !currentSessionId.value) return
isFriendLoadingMore.value = true
try {
const nextPage = friendPageNumber.value + 1
const olderMessages = await getFriendMessages(currentSessionId.value, nextPage)
if (olderMessages && olderMessages.length > 0) {
friendPageNumber.value = nextPage
allmessages.value = [...olderMessages, ...allmessages.value]
await nextTick()
scrollToView.value = 'msg-' + olderMessages.length
} else {
hasMoreFriendMessages.value = false
}
} catch (e) {
console.error('加载更多好友消息失败:', e)
uni.showToast({ title: '加载更多失败', icon: 'none' })
} finally {
isFriendLoadingMore.value = false
}
}
// 加载更多群聊历史消息(上一页),并定位到原第一条消息
const loadMoreGroupMessages = async () => {
if (isGroupLoadingMore.value || !hasMoreGroupMessages.value || !currentSessionId.value) return
isGroupLoadingMore.value = true
try {
const nextPage = groupPageNumber.value + 1
const olderMessages = await getGroupMessages(currentSessionId.value, nextPage)
if (olderMessages && olderMessages.length > 0) {
groupPageNumber.value = nextPage
allmessages.value = [...olderMessages, ...allmessages.value]
await nextTick()
scrollToView.value = 'msg-' + olderMessages.length
} else {
hasMoreGroupMessages.value = false
}
} catch (e) {
console.error('加载更多群聊消息失败:', e)
uni.showToast({ title: '加载更多失败', icon: 'none' })
} finally {
isGroupLoadingMore.value = false
}
}
// 滑动到底部
const scrollToBottom = async () => {
await nextTick();

View File

@@ -30,6 +30,7 @@ export const useSocketStore = defineStore('socket', () => {
const maxLogCount = ref(20)
const authFailReason = ref('')
const pcOffline = ref(false)
// ==================== 计算属性 ====================
const isConnected = computed(() => connectionStatus.value === 'connected')
@@ -66,6 +67,7 @@ export const useSocketStore = defineStore('socket', () => {
...config.value,
...options
}
pcOffline.value = false // 每次连接时重置 PC 离线标记
addLog('info',
`准备连接WebSocket。Token:${config.value.token || '未设置'}。ConversationId: ${config.value.conversationId || '未设置'}`
)
@@ -182,6 +184,7 @@ export const useSocketStore = defineStore('socket', () => {
break
case 'pc_offline':
pcOffline.value = true
addLog('warn', 'PC 端已离线')
break
@@ -287,6 +290,7 @@ export const useSocketStore = defineStore('socket', () => {
logs,
config,
authFailReason,
pcOffline,
// 计算属性
isConnected,

File diff suppressed because it is too large Load Diff

View File

@@ -1096,6 +1096,171 @@ to { opacity: 1; transform: translateY(0) scale(1);
.ncd-intelligence .ncd-opt-icon[data-v-5eb7b895] {
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}
/* ========== 智能体选择弹窗 ========== */
.agent-modal-mask[data-v-5eb7b895] {
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[data-v-5eb7b895] {
width: 85%;
max-height: 70%;
background-color: #ffffff;
border-radius: 0.75rem;
overflow: hidden;
display: flex;
flex-direction: column;
box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.12);
}
.agent-modal-header[data-v-5eb7b895] {
display: flex;
justify-content: center;
align-items: center;
padding: 0.9375rem 0.9375rem 0.625rem;
position: relative;
border-bottom: 0.0625rem solid #f0f0f0;
}
.agent-modal-title[data-v-5eb7b895] {
font-size: 1.0625rem;
font-weight: 700;
color: #1a1a2e;
}
.agent-modal-close[data-v-5eb7b895] {
position: absolute;
right: 0.75rem;
top: 50%;
transform: translateY(-50%);
padding: 0.3125rem;
}
.agent-list[data-v-5eb7b895] {
box-sizing: border-box;
flex: 1;
padding: 0.625rem 0.75rem;
max-height: 18.75rem;
}
.agent-loading[data-v-5eb7b895] {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1.875rem 0;
}
.agent-loading-text[data-v-5eb7b895] {
margin-top: 0.5rem;
font-size: 0.8125rem;
color: #999;
}
.agent-empty[data-v-5eb7b895] {
display: flex;
align-items: center;
justify-content: center;
padding: 2.5rem 0;
}
.agent-empty-text[data-v-5eb7b895] {
font-size: 0.875rem;
color: #999;
}
.agent-card[data-v-5eb7b895] {
box-sizing: border-box;
width: 100%;
background: linear-gradient(135deg, #f8f5ff, #efe8ff);
border: 0.0625rem solid #c4b5fd;
border-radius: 0.625rem;
padding: 0.875rem 0.75rem;
margin-bottom: 0.625rem;
transition: all 0.2s ease;
overflow: hidden;
}
.agent-card[data-v-5eb7b895]:active {
transform: scale(0.98);
border-color: #a78bfa;
background: linear-gradient(135deg, #f3efff, #e8dcff);
}
.agent-card-header[data-v-5eb7b895] {
display: flex;
align-items: center;
margin-bottom: 0.5rem;
}
.agent-avatar[data-v-5eb7b895] {
width: 2.1875rem;
height: 2.1875rem;
border-radius: 0.625rem;
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.agent-card-info[data-v-5eb7b895] {
margin-left: 0.5rem;
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
}
.agent-card-title[data-v-5eb7b895] {
font-size: 0.9375rem;
font-weight: 600;
color: #1a1a2e;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.agent-card-category[data-v-5eb7b895] {
font-size: 0.6875rem;
color: #8b5cf6;
margin-top: 0.125rem;
}
.agent-card-desc[data-v-5eb7b895] {
font-size: 0.8125rem;
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[data-v-5eb7b895] {
font-size: 0.75rem;
color: #7c3aed;
margin-top: 0.375rem;
padding-top: 0.375rem;
border-top: 0.0625rem dashed #ddd6fe;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.agent-modal-footer[data-v-5eb7b895] {
padding: 0.625rem 0.9375rem 0.9375rem;
border-top: 0.0625rem solid #f0f0f0;
display: flex;
justify-content: flex-end;
}
.agent-modal-btn[data-v-5eb7b895] {
padding: 0.5625rem 1.5rem;
border-radius: 0.5rem;
font-size: 0.875rem;
font-weight: 500;
}
.agent-modal-btn-cancel[data-v-5eb7b895] {
background: #f0f0f0;
color: #666;
}
.agent-modal-btn-cancel[data-v-5eb7b895]:active {
background: #e0e0e0;
}
/* ==========新建聊天列表相关====== */
.close-option-card[data-v-5eb7b895] {
width: 100%;
@@ -1188,6 +1353,9 @@ to { opacity: 1; transform: translateY(0) scale(1);
.head-btn .iconfont[data-v-5eb7b895] {
font-size: 1.5rem;
}
.chat-btn-group .head-btn[data-v-5eb7b895]:nth-child(4) {
/* 刷新按钮 */
}
.log-out[data-v-5eb7b895] {
/* background: #ffd4d4; */
}
@@ -1709,45 +1877,57 @@ to { opacity: 1; transform: translateY(0);
/* 气泡内容字体:确保 v-html 渲染的 markdown 内容使用系统字体栈 */
.chat-content {
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans", "MiSans", "Source Han Sans CN", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif !important;
font-size: 16px !important;
font-weight: 600 !important;
line-height: 1.6;
margin: 0.25rem 0;
font-size: 0.9375rem !important;
line-height: 1.5rem !important;
margin: 0.25rem 0 !important;
/* 普通正文 */
/* 粗体和斜体样式 */
/* 气泡内的内联链接(替代 <a> 标签,点击由 JS 拦截处理) */
/* 可下载文件链接 → 按钮卡片样式 */
}
.chat-content h1 {
font-size: 1.3125rem;
line-height: 1.4;
margin: 0.5rem 0 0.3125rem;
font-size: 1.0625rem !important;
font-weight: 600 !important;
line-height: 1.75rem !important;
margin: 0.6875rem 0 0.4375rem !important;
}
.chat-content h2 {
font-size: 1.1875rem;
line-height: 1.4;
margin: 0.4375rem 0 0.25rem;
font-size: 1rem !important;
font-weight: 600 !important;
line-height: 1.625rem !important;
margin: 0.5625rem 0 0.3125rem !important;
}
.chat-content h3 {
font-size: 1.125rem;
line-height: 1.4;
margin: 0.375rem 0 0.25rem;
font-size: 0.9375rem !important;
font-weight: 600 !important;
line-height: 1.5rem !important;
margin: 0.4375rem 0 0.1875rem !important;
}
.chat-content h4 {
font-size: 0.875rem !important;
font-weight: 600 !important;
line-height: 1.5rem !important;
margin: 0.4375rem 0 0.1875rem !important;
}
.chat-content h5 {
font-size: 0.8125rem !important;
font-weight: 600 !important;
line-height: 1.375rem !important;
margin: 0.3125rem 0 0.125rem !important;
}
.chat-content h4,
.chat-content h5,
.chat-content h6 {
font-size: 1.0625rem;
line-height: 1.5;
margin: 0.3125rem 0 0.1875rem;
font-size: 0.75rem !important;
font-weight: 600 !important;
line-height: 1.25rem !important;
margin: 0.3125rem 0 0.125rem !important;
}
.chat-content p,
.chat-content uni-text,
.chat-content span {
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans", "MiSans", "Source Han Sans CN", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif !important;
font-size: 1.1875rem !important;
font-weight: 400 !important;
line-height: 1.6;
margin: 0.25rem 0;
font-size: 0.9375rem !important;
line-height: 1.5rem !important;
margin: 0.25rem 0 !important;
}
.chat-content strong,
.chat-content b {

View File

@@ -1096,6 +1096,171 @@ to { opacity: 1; transform: translateY(0) scale(1);
.ncd-intelligence .ncd-opt-icon[data-v-fdf84df1] {
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}
/* ========== 智能体选择弹窗 ========== */
.agent-modal-mask[data-v-fdf84df1] {
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[data-v-fdf84df1] {
width: 85%;
max-height: 70%;
background-color: #ffffff;
border-radius: 0.75rem;
overflow: hidden;
display: flex;
flex-direction: column;
box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.12);
}
.agent-modal-header[data-v-fdf84df1] {
display: flex;
justify-content: center;
align-items: center;
padding: 0.9375rem 0.9375rem 0.625rem;
position: relative;
border-bottom: 0.0625rem solid #f0f0f0;
}
.agent-modal-title[data-v-fdf84df1] {
font-size: 1.0625rem;
font-weight: 700;
color: #1a1a2e;
}
.agent-modal-close[data-v-fdf84df1] {
position: absolute;
right: 0.75rem;
top: 50%;
transform: translateY(-50%);
padding: 0.3125rem;
}
.agent-list[data-v-fdf84df1] {
box-sizing: border-box;
flex: 1;
padding: 0.625rem 0.75rem;
max-height: 18.75rem;
}
.agent-loading[data-v-fdf84df1] {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1.875rem 0;
}
.agent-loading-text[data-v-fdf84df1] {
margin-top: 0.5rem;
font-size: 0.8125rem;
color: #999;
}
.agent-empty[data-v-fdf84df1] {
display: flex;
align-items: center;
justify-content: center;
padding: 2.5rem 0;
}
.agent-empty-text[data-v-fdf84df1] {
font-size: 0.875rem;
color: #999;
}
.agent-card[data-v-fdf84df1] {
box-sizing: border-box;
width: 100%;
background: linear-gradient(135deg, #f8f5ff, #efe8ff);
border: 0.0625rem solid #c4b5fd;
border-radius: 0.625rem;
padding: 0.875rem 0.75rem;
margin-bottom: 0.625rem;
transition: all 0.2s ease;
overflow: hidden;
}
.agent-card[data-v-fdf84df1]:active {
transform: scale(0.98);
border-color: #a78bfa;
background: linear-gradient(135deg, #f3efff, #e8dcff);
}
.agent-card-header[data-v-fdf84df1] {
display: flex;
align-items: center;
margin-bottom: 0.5rem;
}
.agent-avatar[data-v-fdf84df1] {
width: 2.1875rem;
height: 2.1875rem;
border-radius: 0.625rem;
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.agent-card-info[data-v-fdf84df1] {
margin-left: 0.5rem;
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
}
.agent-card-title[data-v-fdf84df1] {
font-size: 0.9375rem;
font-weight: 600;
color: #1a1a2e;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.agent-card-category[data-v-fdf84df1] {
font-size: 0.6875rem;
color: #8b5cf6;
margin-top: 0.125rem;
}
.agent-card-desc[data-v-fdf84df1] {
font-size: 0.8125rem;
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[data-v-fdf84df1] {
font-size: 0.75rem;
color: #7c3aed;
margin-top: 0.375rem;
padding-top: 0.375rem;
border-top: 0.0625rem dashed #ddd6fe;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.agent-modal-footer[data-v-fdf84df1] {
padding: 0.625rem 0.9375rem 0.9375rem;
border-top: 0.0625rem solid #f0f0f0;
display: flex;
justify-content: flex-end;
}
.agent-modal-btn[data-v-fdf84df1] {
padding: 0.5625rem 1.5rem;
border-radius: 0.5rem;
font-size: 0.875rem;
font-weight: 500;
}
.agent-modal-btn-cancel[data-v-fdf84df1] {
background: #f0f0f0;
color: #666;
}
.agent-modal-btn-cancel[data-v-fdf84df1]:active {
background: #e0e0e0;
}
/* ==========新建聊天列表相关====== */
.close-option-card[data-v-fdf84df1] {
width: 100%;
@@ -1188,6 +1353,9 @@ to { opacity: 1; transform: translateY(0) scale(1);
.head-btn .iconfont[data-v-fdf84df1] {
font-size: 1.5rem;
}
.chat-btn-group .head-btn[data-v-fdf84df1]:nth-child(4) {
/* 刷新按钮 */
}
.log-out[data-v-fdf84df1] {
/* background: #ffd4d4; */
}

View File

@@ -29,7 +29,11 @@ export const login = async (username, password) => {
}
} else {
if (String(res.statusCode).startsWith('5')) {
reject({ serverError: true, code: res.statusCode, message: '服务器升级中,请稍后再试' })
reject({
serverError: true,
code: res.statusCode,
message: '服务器升级中,请稍后再试'
})
} else {
reject(`请求失败:${res.statusCode}`)
}
@@ -73,15 +77,16 @@ export const getUserConversations = async (token) => {
}
// 获取与AI的对话内容
export const getConversationMessages = async (token, conversatio_id) => {
export const getConversationMessages = async (token, conversation_id, size, page_number) => {
return new Promise((resolve, reject) => {
uni.request({
url: `${BASE_URL}/get_conversation_messages`,
method: 'POST',
data: {
"access_token": token,
"login_type": "phone",
"conversation_id": conversatio_id
"conversation_id": conversation_id,
"size": 20,
"current": page_number
},
header: {
'Content-Type': 'application/json'
@@ -90,14 +95,15 @@ export const getConversationMessages = async (token, conversatio_id) => {
if (res.statusCode === 200) {
const messagesInfo = res.data
if (messagesInfo) {
// console.log("返回数据为",messagesInfo);
console.log("工作区id为", messagesInfo.workspace_id || '(无)');
if (messagesInfo.workspace_id) {
uni.setStorageSync('workspace_id', messagesInfo.workspace_id)
}
const filtered = (messagesInfo.messages || []).filter(
m => m.role !== 'tool'
)
resolve(filtered)
m => m.role !== 'tool'
)
resolve(filtered)
} else {
const msg = res.data.error || '获取消息出错啦'
reject(msg)
@@ -556,9 +562,9 @@ export const workspaceUploadFileByURL = (token, workspacesId, urls, dirPath) =>
const failedItems = (respond.results || [])
.filter(r => !r.success)
.map(r => r.error || '未知错误');
const msg = failedItems.length > 0
? `上传失败 ${respond.failed_count}/${respond.total_files}${failedItems[0]}`
: (respond.summary || respond?.error || '上传文件到工作区出错啦');
const msg = failedItems.length > 0 ?
`上传失败 ${respond.failed_count}/${respond.total_files}${failedItems[0]}` :
(respond.summary || respond?.error || '上传文件到工作区出错啦');
reject(msg);
}
} else {
@@ -585,14 +591,19 @@ export const uploadFileToShortStorage = (workspacesId, files, filePath) => {
// 构建 files 数组供 uni.uploadFile 使用
const uploadFiles = fileList.map((file) => {
const fileUri = typeof file === 'string' ? file : (file.tempFilePath || file.path || file);
const fileUri = typeof file === 'string' ? file : (file.tempFilePath || file.path ||
file);
return {
name: 'files',
uri: fileUri
};
});
console.log('uploadFileToShortStorage 参数:', { workspacesId, fileCount: uploadFiles.length, filePath });
console.log('uploadFileToShortStorage 参数:', {
workspacesId,
fileCount: uploadFiles.length,
filePath
});
uni.uploadFile({
url: `${BASE_URL}/cloud_api/file/temp/upload`,
@@ -614,9 +625,13 @@ export const uploadFileToShortStorage = (workspacesId, files, filePath) => {
resolve(respond);
} else if (respond.success) {
// 兼容 { success: true, url: "..." } 格式
resolve([{ url: respond.url || respond.message, success: true }]);
resolve([{
url: respond.url || respond.message,
success: true
}]);
} else {
const msg = respond?.error || respond?.message || '上传文件到短存云端获取URL出错啦';
const msg = respond?.error || respond?.message ||
'上传文件到短存云端获取URL出错啦';
reject(msg);
}
} catch (e) {
@@ -1718,3 +1733,80 @@ 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}`)
}
},
fail: (err) => {
const msg = err.errMsg || '网络错误';
reject(msg);
}
})
})
}
// 创建智能体会话
export const addConversationAgent = (token, agent_id) => {
return new Promise((resolve, reject) => {
uni.request({
url: `${BASE_URL}/cloud_api/phone/conversation/agent/add`,
method: "POST",
header: {
"Content-Type": "application/json"
},
data: {
"access_token": token,
"agent_id": agent_id
},
success: (res) => {
if (res.statusCode === 200) {
const respond = res.data
// 返回格式: { success: true, title: "...", conversation_id: "...", workspace_id: "..." }
if (respond?.success && respond?.conversation_id) {
// // 保存 workspace_id 到本地存储
// if (respond.workspace_id) {
// uni.setStorageSync('workspace_id', respond.workspace_id)
// }
resolve({
conversation_id: respond.conversation_id,
workspace_id: respond.workspace_id,
title: respond.title || ''
})
} else {
const msg = respond?.error || '创建智能体会话出错啦'
reject(msg)
}
} else {
reject(`创建智能体会话失败:${res.statusCode}`)
}
},
fail: (err) => {
const msg = err.errMsg || '网络错误'
reject(msg)
}
})
})
}

View File

@@ -84,7 +84,7 @@ export const getGroup = async (sendId) => {
}
// 获取与好友的对话内容
export const getFriendMessages = async (sessionId, current = 1) => {
export const getFriendMessages = async (sessionId, size, current = 1) => {
console.log('请求的好友消息id', sessionId);
return new Promise((resolve, reject) => {
uni.request({
@@ -92,7 +92,7 @@ export const getFriendMessages = async (sessionId, current = 1) => {
method: 'POST',
data: {
"sessionId": sessionId,
"size": 100,
"size": size,
"current": current,
"beginTime": "",
"endTime": ""
@@ -130,7 +130,7 @@ export const getFriendMessages = async (sessionId, current = 1) => {
// 获取群聊的对话内容
export const getGroupMessages = async (groupId, current = 1) => {
export const getGroupMessages = async (groupId, size, current = 1) => {
console.log('请求的群聊消息id', groupId);
return new Promise((resolve, reject) => {
uni.request({
@@ -138,7 +138,7 @@ export const getGroupMessages = async (groupId, current = 1) => {
method: 'POST',
data: {
"current": current,
"size": 100,
"size": size,
"groupId": groupId,
"beginTime": "",
"endTime": ""