已过滤工具类消息

This commit is contained in:
2026-07-06 09:34:55 +08:00
parent 879d2e350a
commit b8af01cc69
7 changed files with 171 additions and 144 deletions

View File

@@ -73,9 +73,9 @@
<uni-icons type="chat-filled" size="26" color="#007aff"></uni-icons>
</view>
<view v-if="chat.agent_id">
{{chat.agent_data.title}}
{{truncateText(chat.agent_data?.title) || "加载中"}}
</view>
<view v-else>{{chat.title}}</view>
<view v-else>{{truncateText(chat.title)}}</view>
</view>
<!-- 好友对话列表 -->
<view v-if="chatType === 1" v-for="chat in UserConversations" :key="chat.sessionId"
@@ -312,6 +312,12 @@
const UserAvatar = ref('')
const UserName = ref('')
// 文本截断方法超过20字符显示省略号
const truncateText = (text, maxLength = 20) => {
if (!text) return ''
return text.length > maxLength ? text.substring(0, maxLength) + '...' : text
}
onMounted(async () => {
UserToken.value = getToken()
const UserInfo = await getUserInfo(UserToken.value)

View File

@@ -84,8 +84,9 @@
@scrolltoupper="loadMoreMessages" :upper-threshold="0" :scroll-with-animation="true"
@scroll="onScroll">
<!-- 与AI的对话内容展示 -->
<view v-if="ChatType === 0" class="chat-message" v-for="(message, index) in currentMessages"
:key="index" :id="'msg-' + index" :class="{'message-user':message.role==='user'}">
<template v-for="(message, index) in currentMessages" :key="index">
<view v-if="ChatType === 0 && message.role !== 'tool'" class="chat-message"
:id="'msg-' + index" :class="{'message-user':message.role==='user'}">
<!-- <view class="chat-avatar" :class="{'chat-avatar-user':message.role==='user'}">
<image v-if="message.role === 'user' && UserData?.avatar" :src="UserData.avatar"
class="friend-avatar" mode="aspectFill"></image>
@@ -123,6 +124,7 @@
</view>
</view>
</view>
</template>
<!-- 与好友的对话内容展示 -->
<view v-if="ChatType === 1" class="chat-message" v-for="(message, index) in currentMessages"
:key="index" :id="'msg-' + index" :class="{'message-user':message.sender === UserId}">
@@ -1016,7 +1018,7 @@
const takeConversationMessages = async () => {
try {
allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || [];
// console.log("AI消息", JSON.stringify(allmessages.value) );
console.log("获取到的所有消息:", JSON.stringify(allmessages.value) );
// currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// 数据获取后执行滚动
scrollToBottom();

View File

@@ -116,6 +116,7 @@
try {
const token = await login(UsernameValue.value, PasswordValue.value)
// 登陆成功,保存登录数据到手机
console.log("有返回token", token);
saveLoginInfo();
uni.reLaunch({
url: '/pages/Chat/Chat'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -118,6 +118,7 @@ if (uni.restoreGlobal) {
method: "POST",
data: {
"access_token": token,
"login_type": "phone",
"conversation_id": conversatio_id
},
header: {
@@ -127,7 +128,7 @@ if (uni.restoreGlobal) {
if (res.statusCode === 200) {
const messagesInfo = res.data;
if (messagesInfo) {
formatAppLog("log", "at utils/cloud-api.js:88", "工作区id为", messagesInfo.workspace_id || "(无)");
formatAppLog("log", "at utils/cloud-api.js:89", "工作区id为", messagesInfo.workspace_id || "(无)");
if (messagesInfo.workspace_id) {
uni.setStorageSync("workspace_id", messagesInfo.workspace_id);
}
@@ -544,7 +545,7 @@ if (uni.restoreGlobal) {
uri: fileUri
};
});
formatAppLog("log", "at utils/cloud-api.js:587", "uploadFileToShortStorage 参数:", { workspacesId, fileCount: uploadFiles.length, filePath });
formatAppLog("log", "at utils/cloud-api.js:588", "uploadFileToShortStorage 参数:", { workspacesId, fileCount: uploadFiles.length, filePath });
uni.uploadFile({
url: `${BASE_URL}/cloud_api/file/temp/upload`,
method: "POST",
@@ -555,7 +556,7 @@ if (uni.restoreGlobal) {
},
files: uploadFiles,
success: (res) => {
formatAppLog("log", "at utils/cloud-api.js:599", "uploadFileToShortStorage 响应状态:", res.statusCode, "数据:", res.data);
formatAppLog("log", "at utils/cloud-api.js:600", "uploadFileToShortStorage 响应状态:", res.statusCode, "数据:", res.data);
if (res.statusCode === 200) {
try {
const respond = JSON.parse(res.data);
@@ -1543,12 +1544,13 @@ if (uni.restoreGlobal) {
loading.value = true;
try {
const token = await login(UsernameValue.value, PasswordValue.value);
formatAppLog("log", "at pages/Login/Login.vue:119", "有返回token", token);
saveLoginInfo();
uni.reLaunch({
url: "/pages/Chat/Chat"
});
} catch (err) {
formatAppLog("log", "at pages/Login/Login.vue:124", "登录失败", err);
formatAppLog("log", "at pages/Login/Login.vue:125", "登录失败", err);
uni.showToast({
title: err || "失败",
icon: "error"
@@ -1584,7 +1586,7 @@ if (uni.restoreGlobal) {
form.remember = loginInfo.remember ?? true;
}
} catch (e2) {
formatAppLog("error", "at pages/Login/Login.vue:168", "读取登录信息失败", e2);
formatAppLog("error", "at pages/Login/Login.vue:169", "读取登录信息失败", e2);
}
};
vue.onMounted(() => {
@@ -2588,14 +2590,19 @@ if (uni.restoreGlobal) {
const UserToken = vue.ref("");
const UserAvatar = vue.ref("");
const UserName = vue.ref("");
const truncateText = (text, maxLength = 20) => {
if (!text)
return "";
return text.length > maxLength ? text.substring(0, maxLength) + "..." : text;
};
vue.onMounted(async () => {
UserToken.value = getToken();
const UserInfo = await getUserInfo(UserToken.value);
UserAvatar.value = UserInfo.avatar || "";
UserName.value = UserInfo.username || "";
formatAppLog("log", "at components/ChatSidebar.vue:320", "菜单收到的会话列表:", UserConversations.value);
formatAppLog("log", "at components/ChatSidebar.vue:326", "菜单收到的会话列表:", UserConversations.value);
});
const __returned__ = { props, emit, UserConversations, showNewChatModal, chatType, openUserCardVisible, isSelectMode, selectedHistoryIds, deleteConversations, clearAllConversations, isAllHistorySelected, currentChatId, selectChat, openNewChatModal, goContactPages, chatHistoryQuery, isHistorySearchFocused, toggleSelectMode, toggleHistorySelect, toggleSelectAllHistory, UserToken, UserAvatar, UserName, computed: vue.computed, onMounted: vue.onMounted, onUnmounted: vue.onUnmounted, ref: vue.ref, toRef: vue.toRef, get deleteConversation() {
const __returned__ = { props, emit, UserConversations, showNewChatModal, chatType, openUserCardVisible, isSelectMode, selectedHistoryIds, deleteConversations, clearAllConversations, isAllHistorySelected, currentChatId, selectChat, openNewChatModal, goContactPages, chatHistoryQuery, isHistorySearchFocused, toggleSelectMode, toggleHistorySelect, toggleSelectAllHistory, UserToken, UserAvatar, UserName, truncateText, computed: vue.computed, onMounted: vue.onMounted, onUnmounted: vue.onUnmounted, ref: vue.ref, toRef: vue.toRef, get deleteConversation() {
return deleteConversation;
}, get getToken() {
return getToken;
@@ -2749,6 +2756,7 @@ if (uni.restoreGlobal) {
vue.Fragment,
{ key: 0 },
vue.renderList($setup.UserConversations, (chat) => {
var _a;
return vue.openBlock(), vue.createElementBlock("view", {
key: chat._id,
"data-chat-id": chat._id,
@@ -2776,13 +2784,13 @@ if (uni.restoreGlobal) {
chat.agent_id ? (vue.openBlock(), vue.createElementBlock(
"view",
{ key: 1 },
vue.toDisplayString(chat.agent_data.title),
vue.toDisplayString($setup.truncateText((_a = chat.agent_data) == null ? void 0 : _a.title) || "加载中"),
1
/* TEXT */
)) : (vue.openBlock(), vue.createElementBlock(
"view",
{ key: 2 },
vue.toDisplayString(chat.title),
vue.toDisplayString($setup.truncateText(chat.title)),
1
/* TEXT */
))
@@ -5548,7 +5556,7 @@ This will fail in production.`);
if (friendSocketStore.isConnected)
return;
if (!userToken.value || !UserId.value) {
formatAppLog("warn", "at pages/Chat/Chat.vue:290", "Token或UserId未准备好");
formatAppLog("warn", "at pages/Chat/Chat.vue:292", "Token或UserId未准备好");
return;
}
friendSocketStore.connect({
@@ -5619,7 +5627,7 @@ This will fail in production.`);
const html = t(content);
return html;
} catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:388", "解析失败", e2);
formatAppLog("error", "at pages/Chat/Chat.vue:390", "解析失败", e2);
return content;
}
};
@@ -5669,7 +5677,7 @@ This will fail in production.`);
const textContent = content.replace(match[0], "").trim();
return { textContent, files };
} catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:456", "解析文件信息失败:", e2);
formatAppLog("error", "at pages/Chat/Chat.vue:458", "解析文件信息失败:", e2);
return { textContent: content, files: [] };
}
};
@@ -5703,7 +5711,7 @@ This will fail in production.`);
}
takeUserConversations();
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:498", "新建普通会话失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:500", "新建普通会话失败:", error);
uni.showToast({
title: "创建会话失败,请重试",
icon: "none"
@@ -5741,7 +5749,7 @@ This will fail in production.`);
};
const previewFileArray = vue.ref([]);
const uploadPhoto = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:547", "点击了拍照上传");
formatAppLog("log", "at pages/Chat/Chat.vue:549", "点击了拍照上传");
uni.chooseImage({
count: 1,
sourceType: ["camera", "album"],
@@ -5764,7 +5772,7 @@ This will fail in production.`);
});
},
fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:565", "选择图片失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:567", "选择图片失败", err);
}
});
};
@@ -5785,12 +5793,12 @@ This will fail in production.`);
};
const fileList = vue.ref([]);
const uploadFile = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:588", "点击了上传文件");
formatAppLog("log", "at pages/Chat/Chat.vue:590", "点击了上传文件");
chooseFile({
count: 5,
type: "all",
success: (res) => {
formatAppLog("log", "at pages/Chat/Chat.vue:593", "成功了");
formatAppLog("log", "at pages/Chat/Chat.vue:595", "成功了");
fileList.value = res.tempFiles;
previewFileArray.value.push(...res.tempFiles);
uni.showToast({
@@ -5799,7 +5807,7 @@ This will fail in production.`);
});
},
fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:604", "选择失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:606", "选择失败:", err);
uni.showToast({
title: "选择失败",
icon: "error"
@@ -5853,7 +5861,7 @@ This will fail in production.`);
previewFileArray.value = [];
} catch (err) {
uni.hideLoading();
formatAppLog("error", "at pages/Chat/Chat.vue:671", "文件上传失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:673", "文件上传失败:", err);
uni.showToast({
title: "文件上传失败,请重试",
icon: "error"
@@ -5982,11 +5990,11 @@ This will fail in production.`);
}
};
vue.watch(() => socketStore.isThinking, (newVal, oldVal) => {
formatAppLog("log", "at pages/Chat/Chat.vue:833", "isThinking 变化:", oldVal, "→", newVal);
formatAppLog("log", "at pages/Chat/Chat.vue:835", "isThinking 变化:", oldVal, "→", newVal);
if (oldVal && !newVal && socketStore.messageString) {
clearTimeout(aiResponseTimer);
formatAppLog("log", "at pages/Chat/Chat.vue:837", "ai返回的消息", socketStore.messageString);
formatAppLog("log", "at pages/Chat/Chat.vue:838", "AI回复结束刷新消息列表");
formatAppLog("log", "at pages/Chat/Chat.vue:839", "ai返回的消息", socketStore.messageString);
formatAppLog("log", "at pages/Chat/Chat.vue:840", "AI回复结束刷新消息列表");
takeConversationMessages();
isThinking.value = false;
textMessage.value = "";
@@ -6006,15 +6014,15 @@ This will fail in production.`);
UserData.value = await getUserInfo(userToken.value);
UserId.value = UserData.value._id;
UserAvatar.value = UserData.value.avatar || "";
formatAppLog("log", "at pages/Chat/Chat.vue:864", "用户信息已加载:", UserId.value, UserAvatar.value);
formatAppLog("log", "at pages/Chat/Chat.vue:866", "用户信息已加载:", UserId.value, UserAvatar.value);
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:866", "获取用户信息失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:868", "获取用户信息失败:", error);
}
};
const takeUserConversations = async () => {
try {
userToken.value = getToken();
formatAppLog("log", "at pages/Chat/Chat.vue:874", "token:", userToken.value);
formatAppLog("log", "at pages/Chat/Chat.vue:876", "token:", userToken.value);
UserConversations.value = await getUserConversations(userToken.value) || [];
const savedSessionId = getCurrentSessionId();
if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) {
@@ -6024,7 +6032,7 @@ This will fail in production.`);
} else {
currentSessionId.value = "";
}
formatAppLog("log", "at pages/Chat/Chat.vue:886", "保存会话id", currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:888", "保存会话id", currentSessionId.value);
uni.setStorageSync("currentSessionId", currentSessionId.value);
} catch (error) {
uni.showToast({
@@ -6036,17 +6044,17 @@ This will fail in production.`);
const FriendInfoList = vue.ref([]);
const takeFriendList = async () => {
try {
formatAppLog("log", "at pages/Chat/Chat.vue:901", "开始获取好友列表");
formatAppLog("log", "at pages/Chat/Chat.vue:903", "开始获取好友列表");
const friendList = await getChatFriend(UserId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:904", "friendList:", friendList);
formatAppLog("log", "at pages/Chat/Chat.vue:906", "friendList:", friendList);
if (friendList && friendList.length) {
FriendInfoList.value = await takeUserAvatar(friendList);
} else {
FriendInfoList.value = [];
formatAppLog("log", "at pages/Chat/Chat.vue:909", "好友列表为空");
formatAppLog("log", "at pages/Chat/Chat.vue:911", "好友列表为空");
}
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:912", "获取好友列表失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:914", "获取好友列表失败:", error);
FriendInfoList.value = [];
} finally {
UserConversations.value = FriendInfoList.value;
@@ -6073,17 +6081,17 @@ This will fail in production.`);
};
});
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:942", "获取好友头像失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:944", "获取好友头像失败", err);
return friendList;
}
};
const GroupList = vue.ref([]);
const takeGroupList = async () => {
try {
formatAppLog("log", "at pages/Chat/Chat.vue:952", "开始获取群聊列表");
formatAppLog("log", "at pages/Chat/Chat.vue:954", "开始获取群聊列表");
GroupList.value = await getGroup(UserId.value);
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:957", "获取群聊列表失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:959", "获取群聊列表失败:", error);
GroupList.value = [];
} finally {
UserConversations.value = GroupList.value;
@@ -6095,22 +6103,22 @@ This will fail in production.`);
return [];
try {
const memberIds = memberList.map((item) => item.groupContactId);
formatAppLog("log", "at pages/Chat/Chat.vue:971", "请求头像的ID列表:", memberIds);
formatAppLog("log", "at pages/Chat/Chat.vue:973", "请求头像的ID列表:", memberIds);
const memberAvatarList = await getUserAvatar(userToken.value, memberIds);
formatAppLog("log", "at pages/Chat/Chat.vue:973", "头像接口返回数据:", memberAvatarList);
formatAppLog("log", "at pages/Chat/Chat.vue:975", "头像接口返回数据:", memberAvatarList);
const userMap = new Map(memberAvatarList.map((user) => [user.user_id, user]) || []);
formatAppLog("log", "at pages/Chat/Chat.vue:976", "userMap的keys:", Array.from(userMap.keys()));
formatAppLog("log", "at pages/Chat/Chat.vue:978", "userMap的keys:", Array.from(userMap.keys()));
return memberList.map((member) => {
const memberId = member.groupContactId;
const userInfo = userMap.get(memberId);
formatAppLog("log", "at pages/Chat/Chat.vue:981", `查找 ${memberId} 的头像:`, userInfo);
formatAppLog("log", "at pages/Chat/Chat.vue:983", `查找 ${memberId} 的头像:`, userInfo);
return {
...member,
avatar: (userInfo == null ? void 0 : userInfo.avatar) || null
};
});
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:988", "获取群成员头像失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:990", "获取群成员头像失败", err);
return memberList;
}
};
@@ -6130,6 +6138,7 @@ This will fail in production.`);
const takeConversationMessages = async () => {
try {
allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || [];
formatAppLog("log", "at pages/Chat/Chat.vue:1021", "获取到的所有消息:", JSON.stringify(allmessages.value));
scrollToBottom();
} catch (error) {
uni.showToast({
@@ -6141,7 +6150,7 @@ This will fail in production.`);
const takeFriendMessages = async () => {
try {
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
formatAppLog("log", "at pages/Chat/Chat.vue:1033", "好友消息:", JSON.stringify(allmessages.value));
formatAppLog("log", "at pages/Chat/Chat.vue:1035", "好友消息:", JSON.stringify(allmessages.value));
scrollToBottom();
} catch (error) {
uni.showToast({
@@ -6153,12 +6162,12 @@ This will fail in production.`);
const takeGroupMessages = async () => {
try {
allmessages.value = await getGroupMessages(currentSessionId.value) || [];
formatAppLog("log", "at pages/Chat/Chat.vue:1046", "群聊消息:", allmessages.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1048", "群聊消息:", allmessages.value);
const memberList = await getGroupMemberList(currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1049", "获取到的群成员列表:", memberList);
formatAppLog("log", "at pages/Chat/Chat.vue:1051", "获取到的群成员列表:", memberList);
if (memberList && memberList.length) {
groupMemberList.value = await takeGroupMemberAvatar(memberList);
formatAppLog("log", "at pages/Chat/Chat.vue:1052", "群成员列表(带头像):", groupMemberList.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1054", "群成员列表(带头像):", groupMemberList.value);
} else {
groupMemberList.value = [];
}
@@ -6171,7 +6180,7 @@ This will fail in production.`);
}
};
const loadMoreMessages = async () => {
formatAppLog("log", "at pages/Chat/Chat.vue:1067", "加载更多信息");
formatAppLog("log", "at pages/Chat/Chat.vue:1069", "加载更多信息");
if (allmessages.value.length > pageInfoNumber * currentPage.value) {
currentPage.value += 1;
const newMessages = allmessages.value.slice(-pageInfoNumber * currentPage.value);
@@ -6190,9 +6199,9 @@ This will fail in production.`);
}
};
vue.watch(() => friendSocketStore.MessageReceived, (newId) => {
formatAppLog("log", "at pages/Chat/Chat.vue:1095", "收到了好友消息");
formatAppLog("log", "at pages/Chat/Chat.vue:1097", "收到了好友消息");
if (newId) {
formatAppLog("log", "at pages/Chat/Chat.vue:1097", "ChatType:", ChatType.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1099", "ChatType:", ChatType.value);
switch (ChatType.value) {
case 0:
takeConversationMessages();
@@ -6207,7 +6216,7 @@ This will fail in production.`);
friendSocketStore.MessageReceived = false;
break;
default:
formatAppLog("log", "at pages/Chat/Chat.vue:1113", "default 分支");
formatAppLog("log", "at pages/Chat/Chat.vue:1115", "default 分支");
friendSocketStore.MessageReceived = false;
break;
}
@@ -6475,14 +6484,18 @@ This will fail in production.`);
"scroll-with-animation": true,
onScroll: $setup.onScroll
}, [
$setup.ChatType === 0 ? (vue.openBlock(true), vue.createElementBlock(
(vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
{ key: 0 },
null,
vue.renderList($setup.currentMessages, (message, index) => {
var _a;
return vue.openBlock(), vue.createElementBlock("view", {
return vue.openBlock(), vue.createElementBlock(
vue.Fragment,
{ key: index },
[
$setup.ChatType === 0 && message.role !== "tool" ? (vue.openBlock(), vue.createElementBlock("view", {
key: 0,
class: vue.normalizeClass(["chat-message", { "message-user": message.role === "user" }]),
key: index,
id: "msg-" + index
}, [
message.role === "user" ? (vue.openBlock(), vue.createElementBlock(
@@ -6565,14 +6578,18 @@ This will fail in production.`);
2
/* CLASS */
)) : vue.createCommentVNode("v-if", true)
], 10, ["id"]);
], 10, ["id"])) : vue.createCommentVNode("v-if", true)
],
64
/* STABLE_FRAGMENT */
);
}),
128
/* KEYED_FRAGMENT */
)) : vue.createCommentVNode("v-if", true),
)),
$setup.ChatType === 1 ? (vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
{ key: 1 },
{ key: 0 },
vue.renderList($setup.currentMessages, (message, index) => {
var _a;
return vue.openBlock(), vue.createElementBlock("view", {
@@ -6670,7 +6687,7 @@ This will fail in production.`);
)) : vue.createCommentVNode("v-if", true),
$setup.ChatType === 2 ? (vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
{ key: 2 },
{ key: 1 },
vue.renderList($setup.currentMessages, (message, index) => {
var _a;
return vue.openBlock(), vue.createElementBlock("view", {

View File

@@ -76,6 +76,7 @@ export const getConversationMessages = async (token, conversatio_id) => {
method: 'POST',
data: {
"access_token": token,
"login_type": "phone",
"conversation_id": conversatio_id
},
header: {