粗提取链接

This commit is contained in:
2026-07-17 14:28:52 +08:00
parent f53beabdf6
commit 3abf881437
3 changed files with 157 additions and 41 deletions

View File

@@ -43,6 +43,12 @@
</view>
<scroll-view class="message-detail-content" scroll-y>
<text>{{ detailMessageContent }}</text>
<view v-if="detailLinks.length" class="detail-links-section">
<view class="detail-links-title">链接 ({{ detailLinks.length }})</view>
<view v-for="(link, i) in detailLinks" :key="i" class="detail-link-item" @click="openLink(link)">
<text class="link-text">{{ link }}</text>
</view>
</view>
</scroll-view>
</view>
</view>
@@ -671,13 +677,29 @@
// 消息详情弹窗
const showMessageModal = ref(false)
const detailMessageContent = ref('')
const detailLinks = ref([])
const extractLinks = (text) => {
const regex = /https?:\/\/[^\s<>"{}|\\^`[\]]+/gi
const matches = text.match(regex)
return matches ? [...new Set(matches)] : []
}
const showMessageDetail = (message) => {
detailMessageContent.value = message.content || ''
detailLinks.value = extractLinks(detailMessageContent.value)
showMessageModal.value = true
}
const closeMessageDetail = () => {
showMessageModal.value = false
detailMessageContent.value = ''
detailLinks.value = []
}
const openLink = (url) => {
// #ifdef APP-PLUS
plus.runtime.openURL(url)
// #endif
// #ifdef H5
window.open(url, '_blank')
// #endif
}
const sendMessage = async () => {
@@ -1396,4 +1418,31 @@
transform: scale(1.1);
}
}
/* 消息详情弹窗 — 链接提取区域 */
.detail-links-section {
margin-top: 24rpx;
padding-top: 24rpx;
border-top: 1rpx solid #eee;
}
.detail-links-title {
font-size: 30rpx;
font-weight: 600;
color: #666;
margin-bottom: 16rpx;
}
.detail-link-item {
padding: 16rpx 20rpx;
background: #f5f7fa;
border-radius: 12rpx;
margin-bottom: 12rpx;
}
.link-text {
font-size: 28rpx;
color: #007aff;
word-break: break-all;
}
</style>

View File

@@ -5597,7 +5597,7 @@ This will fail in production.`);
if (friendSocketStore.isConnected)
return;
if (!userToken.value || !UserId.value) {
formatAppLog("warn", "at pages/Chat/Chat.vue:308", "Token或UserId未准备好");
formatAppLog("warn", "at pages/Chat/Chat.vue:314", "Token或UserId未准备好");
return;
}
friendSocketStore.connect({
@@ -5668,7 +5668,7 @@ This will fail in production.`);
const html = t(content);
return html;
} catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:407", "解析失败", e2);
formatAppLog("error", "at pages/Chat/Chat.vue:413", "解析失败", e2);
return content;
}
};
@@ -5727,7 +5727,7 @@ This will fail in production.`);
files
};
} catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:484", "解析文件信息失败:", e2);
formatAppLog("error", "at pages/Chat/Chat.vue:490", "解析文件信息失败:", e2);
return {
textContent: content,
files: []
@@ -5764,7 +5764,7 @@ This will fail in production.`);
}
takeUserConversations();
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:529", "新建普通会话失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:535", "新建普通会话失败:", error);
uni.showToast({
title: "创建会话失败,请重试",
icon: "none"
@@ -5802,7 +5802,7 @@ This will fail in production.`);
};
const previewFileArray = vue.ref([]);
const uploadPhoto = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:578", "点击了拍照上传");
formatAppLog("log", "at pages/Chat/Chat.vue:584", "点击了拍照上传");
uni.chooseImage({
count: 1,
sourceType: ["camera", "album"],
@@ -5825,7 +5825,7 @@ This will fail in production.`);
});
},
fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:596", "选择图片失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:602", "选择图片失败", err);
}
});
};
@@ -5834,12 +5834,12 @@ This will fail in production.`);
};
const fileList = vue.ref([]);
const uploadFile = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:607", "点击了上传文件");
formatAppLog("log", "at pages/Chat/Chat.vue:613", "点击了上传文件");
chooseFile({
count: 5,
type: "all",
success: (res) => {
formatAppLog("log", "at pages/Chat/Chat.vue:612", "成功了");
formatAppLog("log", "at pages/Chat/Chat.vue:618", "成功了");
fileList.value = res.tempFiles;
previewFileArray.value.push(...res.tempFiles);
uni.showToast({
@@ -5848,7 +5848,7 @@ This will fail in production.`);
});
},
fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:623", "选择失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:629", "选择失败:", err);
uni.showToast({
title: "选择失败",
icon: "error"
@@ -5886,13 +5886,24 @@ This will fail in production.`);
const streamingMessageId = vue.ref(null);
const showMessageModal = vue.ref(false);
const detailMessageContent = vue.ref("");
const detailLinks = vue.ref([]);
const extractLinks = (text) => {
const regex = /https?:\/\/[^\s<>"{}|\\^`[\]]+/gi;
const matches = text.match(regex);
return matches ? [...new Set(matches)] : [];
};
const showMessageDetail = (message) => {
detailMessageContent.value = message.content || "";
detailLinks.value = extractLinks(detailMessageContent.value);
showMessageModal.value = true;
};
const closeMessageDetail = () => {
showMessageModal.value = false;
detailMessageContent.value = "";
detailLinks.value = [];
};
const openLink = (url) => {
plus.runtime.openURL(url);
};
const sendMessage = async () => {
const message = textMessage.value.trim();
@@ -5914,7 +5925,7 @@ This will fail in production.`);
previewFileArray.value = [];
} catch (err) {
uni.hideLoading();
formatAppLog("error", "at pages/Chat/Chat.vue:704", "文件上传失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:726", "文件上传失败:", err);
uni.showToast({
title: "文件上传失败,请重试",
icon: "error"
@@ -6048,15 +6059,15 @@ This will fail in production.`);
}
};
const stopConversation = async () => {
formatAppLog("log", "at pages/Chat/Chat.vue:873", "中断对话 - 当前会话ID:", currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:895", "中断对话 - 当前会话ID:", currentSessionId.value);
try {
await socketStore.send({
type: "stop",
conversation_id: currentSessionId.value
});
formatAppLog("log", "at pages/Chat/Chat.vue:879", "中断指令已发送成功");
formatAppLog("log", "at pages/Chat/Chat.vue:901", "中断指令已发送成功");
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:881", "中断指令发送失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:903", "中断指令发送失败:", err);
}
if (streamingMessageId.value) {
allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value);
@@ -6074,9 +6085,9 @@ This will fail in production.`);
});
};
vue.watch(() => socketStore.isThinking, (newVal, oldVal) => {
formatAppLog("log", "at pages/Chat/Chat.vue:905", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
formatAppLog("log", "at pages/Chat/Chat.vue:927", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
if (!oldVal && newVal) {
formatAppLog("log", "at pages/Chat/Chat.vue:908", "AI开始回复跨设备同步锁定输入框");
formatAppLog("log", "at pages/Chat/Chat.vue:930", "AI开始回复跨设备同步锁定输入框");
isThinking.value = true;
if (!streamingMessageId.value) {
streamingMessageId.value = "streaming-" + Date.now();
@@ -6090,7 +6101,7 @@ This will fail in production.`);
return;
}
if (oldVal && !newVal) {
formatAppLog("log", "at pages/Chat/Chat.vue:924", "AI回复结束正常/中断),解锁并刷新消息列表");
formatAppLog("log", "at pages/Chat/Chat.vue:946", "AI回复结束正常/中断),解锁并刷新消息列表");
if (streamingMessageId.value) {
allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value);
streamingMessageId.value = null;
@@ -6142,15 +6153,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:988", "用户信息已加载:", UserId.value, UserAvatar.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1010", "用户信息已加载:", UserId.value, UserAvatar.value);
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:990", "获取用户信息失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:1012", "获取用户信息失败:", error);
}
};
const takeUserConversations = async () => {
try {
userToken.value = getToken();
formatAppLog("log", "at pages/Chat/Chat.vue:998", "token:", userToken.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1020", "token:", userToken.value);
UserConversations.value = await getUserConversations(userToken.value) || [];
const savedSessionId = getCurrentSessionId();
if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) {
@@ -6160,7 +6171,7 @@ This will fail in production.`);
} else {
currentSessionId.value = "";
}
formatAppLog("log", "at pages/Chat/Chat.vue:1010", "保存会话id", currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1032", "保存会话id", currentSessionId.value);
uni.setStorageSync("currentSessionId", currentSessionId.value);
} catch (error) {
uni.showToast({
@@ -6172,17 +6183,17 @@ This will fail in production.`);
const FriendInfoList = vue.ref([]);
const takeFriendList = async () => {
try {
formatAppLog("log", "at pages/Chat/Chat.vue:1025", "开始获取好友列表");
formatAppLog("log", "at pages/Chat/Chat.vue:1047", "开始获取好友列表");
const friendList = await getChatFriend(UserId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1028", "friendList:", friendList);
formatAppLog("log", "at pages/Chat/Chat.vue:1050", "friendList:", friendList);
if (friendList && friendList.length) {
FriendInfoList.value = await takeUserAvatar(friendList);
} else {
FriendInfoList.value = [];
formatAppLog("log", "at pages/Chat/Chat.vue:1033", "好友列表为空");
formatAppLog("log", "at pages/Chat/Chat.vue:1055", "好友列表为空");
}
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:1036", "获取好友列表失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:1058", "获取好友列表失败:", error);
FriendInfoList.value = [];
} finally {
UserConversations.value = FriendInfoList.value;
@@ -6209,17 +6220,17 @@ This will fail in production.`);
};
});
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1066", "获取好友头像失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:1088", "获取好友头像失败", err);
return friendList;
}
};
const GroupList = vue.ref([]);
const takeGroupList = async () => {
try {
formatAppLog("log", "at pages/Chat/Chat.vue:1076", "开始获取群聊列表");
formatAppLog("log", "at pages/Chat/Chat.vue:1098", "开始获取群聊列表");
GroupList.value = await getGroup(UserId.value);
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:1081", "获取群聊列表失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:1103", "获取群聊列表失败:", error);
GroupList.value = [];
} finally {
UserConversations.value = GroupList.value;
@@ -6231,22 +6242,22 @@ This will fail in production.`);
return [];
try {
const memberIds = memberList.map((item) => item.groupContactId);
formatAppLog("log", "at pages/Chat/Chat.vue:1095", "请求头像的ID列表:", memberIds);
formatAppLog("log", "at pages/Chat/Chat.vue:1117", "请求头像的ID列表:", memberIds);
const memberAvatarList = await getUserAvatar(userToken.value, memberIds);
formatAppLog("log", "at pages/Chat/Chat.vue:1097", "头像接口返回数据:", memberAvatarList);
formatAppLog("log", "at pages/Chat/Chat.vue:1119", "头像接口返回数据:", memberAvatarList);
const userMap = new Map(memberAvatarList.map((user) => [user.user_id, user]) || []);
formatAppLog("log", "at pages/Chat/Chat.vue:1100", "userMap的keys:", Array.from(userMap.keys()));
formatAppLog("log", "at pages/Chat/Chat.vue:1122", "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:1105", `查找 ${memberId} 的头像:`, userInfo);
formatAppLog("log", "at pages/Chat/Chat.vue:1127", `查找 ${memberId} 的头像:`, userInfo);
return {
...member,
avatar: (userInfo == null ? void 0 : userInfo.avatar) || null
};
});
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1112", "获取群成员头像失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:1134", "获取群成员头像失败", err);
return memberList;
}
};
@@ -6278,7 +6289,7 @@ This will fail in production.`);
const takeFriendMessages = async () => {
try {
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
formatAppLog("log", "at pages/Chat/Chat.vue:1159", "好友消息:", JSON.stringify(allmessages.value));
formatAppLog("log", "at pages/Chat/Chat.vue:1181", "好友消息:", JSON.stringify(allmessages.value));
scrollToBottom();
} catch (error) {
uni.showToast({
@@ -6290,12 +6301,12 @@ This will fail in production.`);
const takeGroupMessages = async () => {
try {
allmessages.value = await getGroupMessages(currentSessionId.value) || [];
formatAppLog("log", "at pages/Chat/Chat.vue:1172", "群聊消息:", allmessages.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1194", "群聊消息:", allmessages.value);
const memberList = await getGroupMemberList(currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1175", "获取到的群成员列表:", memberList);
formatAppLog("log", "at pages/Chat/Chat.vue:1197", "获取到的群成员列表:", memberList);
if (memberList && memberList.length) {
groupMemberList.value = await takeGroupMemberAvatar(memberList);
formatAppLog("log", "at pages/Chat/Chat.vue:1178", "群成员列表(带头像):", groupMemberList.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1200", "群成员列表(带头像):", groupMemberList.value);
} else {
groupMemberList.value = [];
}
@@ -6317,9 +6328,9 @@ This will fail in production.`);
}
};
vue.watch(() => friendSocketStore.MessageReceived, (newId) => {
formatAppLog("log", "at pages/Chat/Chat.vue:1223", "收到了好友消息");
formatAppLog("log", "at pages/Chat/Chat.vue:1245", "收到了好友消息");
if (newId) {
formatAppLog("log", "at pages/Chat/Chat.vue:1225", "ChatType:", ChatType.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1247", "ChatType:", ChatType.value);
switch (ChatType.value) {
case 0:
takeConversationMessages();
@@ -6334,7 +6345,7 @@ This will fail in production.`);
friendSocketStore.MessageReceived = false;
break;
default:
formatAppLog("log", "at pages/Chat/Chat.vue:1241", "default 分支");
formatAppLog("log", "at pages/Chat/Chat.vue:1263", "default 分支");
friendSocketStore.MessageReceived = false;
break;
}
@@ -6396,7 +6407,7 @@ This will fail in production.`);
onUnload(() => {
socketStore.disconnect();
});
const __returned__ = { friendSocketStore, handleFriendConnect, socketStore, ChatType, convertMarkdownTable, renderTable, pareseMarkdown, sanitizeContent, previewImage, openFile, formatFileSize, parseFileInfo, selectNormalChat, showNewChatModal, closeNewChatModal, isChatSidebar, handleChatSidebar, goWorkSpace, goCloudDatabase, logOut, previewFileArray, uploadPhoto, deleteImage, fileList, uploadFile, handleConnect, isThinking, isSelfSent, isUploading, uploadedFiles, streamingMessageId, showMessageModal, detailMessageContent, showMessageDetail, closeMessageDetail, sendMessage, sendFriendMessage, sendGroupMessage, sendAIMessage, stopConversation, textMessage, UserConversations, currentSessionId, userToken, UserId, UserAvatar, UserData, takeUserInfo, takeUserConversations, FriendInfoList, takeFriendList, takeTalkUserAvatar, takeUserAvatar, GroupList, takeGroupList, groupMemberList, takeGroupMemberAvatar, getGroupMemberAvatarById, allmessages, scrollToView, bottomToggle, isLoadingMore, currentPage, currentMessages, takeConversationMessages, takeFriendMessages, takeGroupMessages, onScroll, scrollToBottom, computed: vue.computed, getCurrentInstance: vue.getCurrentInstance, nextTick: vue.nextTick, onMounted: vue.onMounted, ref: vue.ref, watch: vue.watch, get onShow() {
const __returned__ = { friendSocketStore, handleFriendConnect, socketStore, ChatType, convertMarkdownTable, renderTable, pareseMarkdown, sanitizeContent, previewImage, openFile, formatFileSize, parseFileInfo, selectNormalChat, showNewChatModal, closeNewChatModal, isChatSidebar, handleChatSidebar, goWorkSpace, goCloudDatabase, logOut, previewFileArray, uploadPhoto, deleteImage, fileList, uploadFile, handleConnect, isThinking, isSelfSent, isUploading, uploadedFiles, streamingMessageId, showMessageModal, detailMessageContent, detailLinks, extractLinks, showMessageDetail, closeMessageDetail, openLink, sendMessage, sendFriendMessage, sendGroupMessage, sendAIMessage, stopConversation, textMessage, UserConversations, currentSessionId, userToken, UserId, UserAvatar, UserData, takeUserInfo, takeUserConversations, FriendInfoList, takeFriendList, takeTalkUserAvatar, takeUserAvatar, GroupList, takeGroupList, groupMemberList, takeGroupMemberAvatar, getGroupMemberAvatarById, allmessages, scrollToView, bottomToggle, isLoadingMore, currentPage, currentMessages, takeConversationMessages, takeFriendMessages, takeGroupMessages, onScroll, scrollToBottom, computed: vue.computed, getCurrentInstance: vue.getCurrentInstance, nextTick: vue.nextTick, onMounted: vue.onMounted, ref: vue.ref, watch: vue.watch, get onShow() {
return onShow;
}, get onUnload() {
return onUnload;
@@ -6551,7 +6562,40 @@ This will fail in production.`);
vue.toDisplayString($setup.detailMessageContent),
1
/* TEXT */
)
),
$setup.detailLinks.length ? (vue.openBlock(), vue.createElementBlock("view", {
key: 0,
class: "detail-links-section"
}, [
vue.createElementVNode(
"view",
{ class: "detail-links-title" },
"链接 (" + vue.toDisplayString($setup.detailLinks.length) + ")",
1
/* TEXT */
),
(vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
null,
vue.renderList($setup.detailLinks, (link, i) => {
return vue.openBlock(), vue.createElementBlock("view", {
key: i,
class: "detail-link-item",
onClick: ($event) => $setup.openLink(link)
}, [
vue.createElementVNode(
"text",
{ class: "link-text" },
vue.toDisplayString(link),
1
/* TEXT */
)
], 8, ["onClick"]);
}),
128
/* KEYED_FRAGMENT */
))
])) : vue.createCommentVNode("v-if", true)
])
])
])) : vue.createCommentVNode("v-if", true),

View File

@@ -1716,4 +1716,27 @@ to { opacity: 1; transform: translateY(0);
opacity: 1;
transform: scale(1.1);
}
}
/* 消息详情弹窗 — 链接提取区域 */
.detail-links-section {
margin-top: 0.75rem;
padding-top: 0.75rem;
border-top: 0.03125rem solid #eee;
}
.detail-links-title {
font-size: 0.9375rem;
font-weight: 600;
color: #666;
margin-bottom: 0.5rem;
}
.detail-link-item {
padding: 0.5rem 0.625rem;
background: #f5f7fa;
border-radius: 0.375rem;
margin-bottom: 0.375rem;
}
.link-text {
font-size: 0.875rem;
color: #007aff;
word-break: break-all;
}