添加中断,修复电脑手机运行时信号

This commit is contained in:
2026-07-11 16:56:48 +08:00
parent 9910269733
commit d6437419b1
8 changed files with 211 additions and 138 deletions

View File

@@ -334,6 +334,14 @@
flex-direction: column;
}
/* ==========加载更多提示========== */
.load-more-tip {
text-align: center;
padding: 20rpx 0;
font-size: 24rpx;
color: #999;
}
/* ==========聊天对话展示部分========== */
.chat-messages {
display: flex;
@@ -603,6 +611,18 @@
box-shadow: none;
}
/* PC端中断发送按钮 */
.stop-message-btn {
background: linear-gradient(135deg, #ff4d4f, #ff6b6b);
box-shadow: 0 4rpx 12rpx rgba(255, 77, 79, 0.35);
animation: pulseStop 1.8s ease-in-out infinite;
}
.stop-message-btn:active {
transform: scale(0.92);
box-shadow: 0 2rpx 6rpx rgba(255, 77, 79, 0.25);
}
.input-btn-group {
flex-shrink: 0;
display: flex;

View File

@@ -97,7 +97,7 @@
</view>
<view class="main-chat">
<scroll-view class="chat-messages" direction="vertical" scroll-y :scroll-into-view="scrollToView"
@scrolltoupper="loadMoreMessages" :upper-threshold="0" :scroll-with-animation="true"
:upper-threshold="0" :scroll-with-animation="true"
@scroll="onScroll">
<!-- 与AI的对话内容展示 -->
<template v-for="(message, index) in currentMessages" :key="index">
@@ -235,9 +235,12 @@
<view class="chat-input-container" :class="{ 'input-disabled': isThinking }">
<textarea class="message-input" :placeholder="isThinking ? (isSelfSent ? 'AI 正在回复中...' : '电脑正在运行,请稍后') : '输入消息...'" :disabled="isThinking"
v-model="textMessage" auto-height></textarea>
<view class="input-btn-group send-message-btn" :class="{ disabled: isThinking }" @click="!isThinking && sendMessage()">
<view class="iconfont icon-fasong"></view>
</view>
<view v-if="isThinking && !isSelfSent" class="input-btn-group stop-message-btn" @click="stopConversation">
<view class="iconfont icon-tingzhi"></view>
</view>
<view v-else class="input-btn-group send-message-btn" :class="{ disabled: isThinking }" @click="!isThinking && sendMessage()">
<view class="iconfont icon-fasong"></view>
</view>
</view>
</view>
</view>
@@ -807,7 +810,7 @@
// }
// }
// AI 回复超时定时器
let aiResponseTimer = null
// let aiResponseTimer = null
// 发送AI消息
const sendAIMessage = async () => {
@@ -828,17 +831,17 @@
socketStore.send(data)
isThinking.value = true
isSelfSent.value = true // 标记为当前设备发起
// 10分钟超时
aiResponseTimer = setTimeout(() => {
uni.showToast({
title: 'AI回复超时请重试',
icon: 'none'
})
isThinking.value = false
isSelfSent.value = false
textMessage.value = ''
uploadedFiles.value = []
}, 600000)
// // 10分钟超时
// aiResponseTimer = setTimeout(() => {
// uni.showToast({
// title: 'AI回复超时请重试',
// icon: 'none'
// })
// isThinking.value = false
// isSelfSent.value = false
// textMessage.value = ''
// uploadedFiles.value = []
// }, 600000)
} catch (error) {
isThinking.value = false
uni.showToast({
@@ -861,12 +864,13 @@
console.error('中断指令发送失败:', err)
}
// 立即关闭弹窗,清除超时
clearTimeout(aiResponseTimer)
// clearTimeout(aiResponseTimer)
isThinking.value = false
socketStore.isThinking = false
isSelfSent.value = false
textMessage.value = ''
uploadedFiles.value = []
// socketStore.isThinking 和 takeConversationMessages 由后端中断确认驱动(见 handleBusinessMessage
// takeConversationMessages 由后端中断确认驱动(见 handleBusinessMessage
uni.showToast({ title: '已中断', icon: 'none', duration: 1500 })
}
@@ -881,7 +885,7 @@
}
// true → falseAI 回复结束或中断,解锁输入框并刷新消息列表
if (oldVal && !newVal) {
clearTimeout(aiResponseTimer)
// clearTimeout(aiResponseTimer)
console.log('AI回复结束正常/中断),解锁并刷新消息列表');
takeConversationMessages()
isThinking.value = false
@@ -1064,7 +1068,7 @@
// 当前会话的消息
// const currentMessages = ref([])
const allmessages = ref([])
const pageInfoNumber = 100;
// const pageInfoNumber = 10;
const scrollToView = ref('')
// 加载状态和分页相关变量
@@ -1072,7 +1076,8 @@
const currentPage = ref(1) // 当前页码(如果后端支持分页)
// 计算属性:自动根据 allmessages 和 currentPage 计算显示消息
const currentMessages = computed(() => {
return allmessages.value.slice(-pageInfoNumber);
// return allmessages.value.slice(-pageInfoNumber);
return allmessages.value;
})
@@ -1126,21 +1131,21 @@
})
}
}
// 加载更多消息
const loadMoreMessages = async () => {
console.log('加载更多信息');
if (allmessages.value.length > pageInfoNumber * currentPage.value) {
currentPage.value += 1;
const newMessages = allmessages.value.slice(-pageInfoNumber * currentPage.value);
const addMessage = newMessages.length - currentMessages.value.length
currentMessages.value = newMessages
// 等待DOM更新
await nextTick()
scrollToView.value = 'msg-' + (addMessage + 1);
// // 加载更多消息
// const loadMoreMessages = async () => {
// console.log('加载更多信息');
// if (allmessages.value.length > pageInfoNumber * currentPage.value) {
// currentPage.value += 1;
// const newMessages = allmessages.value.slice(-pageInfoNumber * currentPage.value);
// const addMessage = newMessages.length - currentMessages.value.length
// currentMessages.value = newMessages
// // 等待DOM更新
// await nextTick()
// scrollToView.value = 'msg-' + (addMessage + 1);
}
// currentMessages.value = allmessages.value.slice(-pageInfoNumber);
}
// }
// // currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// }

View File

@@ -123,10 +123,19 @@
})
} catch(err) {
console.log('登录失败',err);
uni.showToast({
title:err || '失败',
icon:'error'
})
if (err && typeof err === 'object' && err.serverError) {
uni.showModal({
title: '提示',
content: err.message,
showCancel: false,
confirmText: '知道了'
})
} else {
uni.showToast({
title: err?.message || err || '失败',
icon: 'error'
})
}
}finally {
loading.value = false
}

View File

@@ -159,7 +159,7 @@ export const useSocketStore = defineStore('socket', () => {
} = messageData || {}
// 调试日志:明确输出 type 和 data
console.log('[handleMessage] type =', type, ', data =', JSON.stringify(data));
console.log(`[handleMessage] type = ${type}, data = ${JSON.stringify(data)}`);
switch (type) {
case 'auth_ok':
@@ -180,6 +180,10 @@ export const useSocketStore = defineStore('socket', () => {
addLog('warn', 'AI正在回复信息')
handleBusinessMessage(data)
break
case 'pc_offline':
addLog('warn', 'PC 端已离线')
break
default:
addLog('info', `未知事件类型: ${type}`)
@@ -252,6 +256,10 @@ export const useSocketStore = defineStore('socket', () => {
if (chunk) {
// 拼接 ai 回复的内容
messageString.value += chunk
if (!isThinking.value) {
console.log("修改状态为开始思考");
isThinking.value = true
}
}
}

View File

@@ -81,7 +81,11 @@ if (uni.restoreGlobal) {
reject(msg);
}
} else {
reject(`请求失败:${res.statusCode}`);
if (String(res.statusCode).startsWith("5")) {
reject({ serverError: true, code: res.statusCode, message: "服务器升级中,请稍后再试" });
} else {
reject(`请求失败:${res.statusCode}`);
}
}
},
fail: (err) => {
@@ -134,11 +138,14 @@ if (uni.restoreGlobal) {
if (res.statusCode === 200) {
const messagesInfo = res.data;
if (messagesInfo) {
formatAppLog("log", "at utils/cloud-api.js:89", "工作区id为", messagesInfo.workspace_id || "(无)");
formatAppLog("log", "at utils/cloud-api.js:93", "工作区id为", messagesInfo.workspace_id || "(无)");
if (messagesInfo.workspace_id) {
uni.setStorageSync("workspace_id", messagesInfo.workspace_id);
}
resolve(messagesInfo.messages);
const filtered = (messagesInfo.messages || []).filter(
(m) => m.role !== "tool"
);
resolve(filtered);
} else {
const msg = res.data.error || "获取消息出错啦";
reject(msg);
@@ -551,7 +558,7 @@ if (uni.restoreGlobal) {
uri: fileUri
};
});
formatAppLog("log", "at utils/cloud-api.js:588", "uploadFileToShortStorage 参数:", { workspacesId, fileCount: uploadFiles.length, filePath });
formatAppLog("log", "at utils/cloud-api.js:595", "uploadFileToShortStorage 参数:", { workspacesId, fileCount: uploadFiles.length, filePath });
uni.uploadFile({
url: `${BASE_URL}/cloud_api/file/temp/upload`,
method: "POST",
@@ -562,7 +569,7 @@ if (uni.restoreGlobal) {
},
files: uploadFiles,
success: (res) => {
formatAppLog("log", "at utils/cloud-api.js:600", "uploadFileToShortStorage 响应状态:", res.statusCode, "数据:", res.data);
formatAppLog("log", "at utils/cloud-api.js:607", "uploadFileToShortStorage 响应状态:", res.statusCode, "数据:", res.data);
if (res.statusCode === 200) {
try {
const respond = JSON.parse(res.data);
@@ -1557,10 +1564,19 @@ if (uni.restoreGlobal) {
});
} catch (err) {
formatAppLog("log", "at pages/Login/Login.vue:125", "登录失败", err);
uni.showToast({
title: err || "失败",
icon: "error"
});
if (err && typeof err === "object" && err.serverError) {
uni.showModal({
title: "提示",
content: err.message,
showCancel: false,
confirmText: "知道了"
});
} else {
uni.showToast({
title: (err == null ? void 0 : err.message) || err || "失败",
icon: "error"
});
}
} finally {
loading.value = false;
}
@@ -1592,7 +1608,7 @@ if (uni.restoreGlobal) {
form.remember = loginInfo.remember ?? true;
}
} catch (e2) {
formatAppLog("error", "at pages/Login/Login.vue:169", "读取登录信息失败", e2);
formatAppLog("error", "at pages/Login/Login.vue:178", "读取登录信息失败", e2);
}
};
vue.onMounted(() => {
@@ -4479,12 +4495,12 @@ This will fail in production.`);
return;
}
const msg = JSON.stringify(data);
formatAppLog("log", "at utils/socket.js:193", "发送的消息是:", msg);
formatAppLog("log", "at utils/socket.js:199", "发送的消息是:", msg);
this.ws.send({
data: msg,
success: () => resolve(),
fail: (err) => {
formatAppLog("error", "at utils/socket.js:201", "发送消息失败:", err);
formatAppLog("error", "at utils/socket.js:207", "发送消息失败:", err);
reject(err);
}
});
@@ -4498,7 +4514,7 @@ This will fail in production.`);
if (this.reconnectTimer)
return;
this.reconnectAttempts++;
formatAppLog("log", "at utils/socket.js:227", `尝试重连 (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`);
formatAppLog("log", "at utils/socket.js:233", `尝试重连 (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`);
this.reconnectTimer = setTimeout(() => {
this.reconnectTimer = null;
if (!this.isManualClose) {
@@ -4517,7 +4533,7 @@ This will fail in production.`);
this.send({
ws_event: "ping"
}).catch(() => {
formatAppLog("log", "at utils/socket.js:249", "心跳发送失败,准备重连");
formatAppLog("log", "at utils/socket.js:255", "心跳发送失败,准备重连");
if (!this.reconnectTimer && !this.isManualClose) {
this.reconnect();
}
@@ -4542,7 +4558,7 @@ This will fail in production.`);
*/
handleError(error) {
var _a, _b;
formatAppLog("error", "at utils/socket.js:277", "WebSocket 错误处理:", JSON.stringify(error));
formatAppLog("error", "at utils/socket.js:283", "WebSocket 错误处理:", JSON.stringify(error));
(_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, error);
}
/**
@@ -4568,7 +4584,7 @@ This will fail in production.`);
* 清理所有定时器、标记手动关闭、停止重连
*/
close() {
formatAppLog("log", "at utils/socket.js:313", "手动关闭 WebSocket 连接");
formatAppLog("log", "at utils/socket.js:319", "手动关闭 WebSocket 连接");
this.isManualClose = true;
this.stopHeartbeat();
if (this.reconnectTimer) {
@@ -4586,11 +4602,11 @@ This will fail in production.`);
this.ws.onClose(null);
try {
this.ws.close({
success: () => formatAppLog("log", "at utils/socket.js:335", "连接已关闭"),
fail: (err) => formatAppLog("error", "at utils/socket.js:336", "关闭失败:", err)
success: () => formatAppLog("log", "at utils/socket.js:341", "连接已关闭"),
fail: (err) => formatAppLog("error", "at utils/socket.js:342", "关闭失败:", err)
});
} catch (error) {
formatAppLog("error", "at utils/socket.js:344", "关闭连接出错:", error);
formatAppLog("error", "at utils/socket.js:350", "关闭连接出错:", error);
}
this.ws = null;
}
@@ -4727,7 +4743,7 @@ This will fail in production.`);
message_id,
data
} = messageData || {};
formatAppLog("log", "at stores/socket.js:162", "[handleMessage] type =", type, ", data =", JSON.stringify(data));
formatAppLog("log", "at stores/socket.js:162", `[handleMessage] type = ${type}, data = ${JSON.stringify(data)}`);
switch (type) {
case "auth_ok":
addLog("success", "连接成功");
@@ -4744,6 +4760,9 @@ This will fail in production.`);
addLog("warn", "AI正在回复信息");
handleBusinessMessage(data);
break;
case "pc_offline":
addLog("warn", "PC 端已离线");
break;
default:
addLog("info", `未知事件类型: ${type}`);
}
@@ -4757,14 +4776,14 @@ This will fail in production.`);
}
function handleBusinessMessage(data) {
if (data === "exit") {
formatAppLog("log", "at stores/socket.js:220", "ai结束思考");
formatAppLog("log", "at stores/socket.js:224", "ai结束思考");
isThinking.value = false;
return;
}
if (!data || typeof data !== "object")
return;
if (data.cmd === "event_callback" && data.info === "中断成功") {
formatAppLog("log", "at stores/socket.js:230", "后端确认中断成功");
formatAppLog("log", "at stores/socket.js:234", "后端确认中断成功");
addLog("warn", `中断确认: ${data.info}`);
isThinking.value = false;
return;
@@ -4778,12 +4797,16 @@ This will fail in production.`);
task_call_id
} = data;
if (!isThinking.value && (chunk || message_role === "assistant")) {
formatAppLog("log", "at stores/socket.js:247", "ai开始思考");
formatAppLog("log", "at stores/socket.js:251", "ai开始思考");
messageString.value = "";
isThinking.value = true;
}
if (chunk) {
messageString.value += chunk;
if (!isThinking.value) {
formatAppLog("log", "at stores/socket.js:260", "修改状态为开始思考");
isThinking.value = true;
}
}
}
function getStatusText() {
@@ -5565,7 +5588,6 @@ This will fail in production.`);
const pkg = /* @__PURE__ */ initUTSPackageName(name, is_uni_modules);
const cls = /* @__PURE__ */ initUTSIndexClassName(name, is_uni_modules);
const chooseFile = /* @__PURE__ */ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: "chooseFileByJs", keepAlive: false, params: [{ "name": "options", "type": "UTSSDKModulesLimeChooseFileChooseFileOptionJSONObject" }], return: "" });
const pageInfoNumber = 100;
const _sfc_main$9 = {
__name: "Chat",
setup(__props, { expose: __expose }) {
@@ -5575,7 +5597,7 @@ This will fail in production.`);
if (friendSocketStore.isConnected)
return;
if (!userToken.value || !UserId.value) {
formatAppLog("warn", "at pages/Chat/Chat.vue:307", "Token或UserId未准备好");
formatAppLog("warn", "at pages/Chat/Chat.vue:310", "Token或UserId未准备好");
return;
}
friendSocketStore.connect({
@@ -5646,7 +5668,7 @@ This will fail in production.`);
const html = t(content);
return html;
} catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:405", "解析失败", e2);
formatAppLog("error", "at pages/Chat/Chat.vue:408", "解析失败", e2);
return content;
}
};
@@ -5696,7 +5718,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:473", "解析文件信息失败:", e2);
formatAppLog("error", "at pages/Chat/Chat.vue:476", "解析文件信息失败:", e2);
return { textContent: content, files: [] };
}
};
@@ -5730,7 +5752,7 @@ This will fail in production.`);
}
takeUserConversations();
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:515", "新建普通会话失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:518", "新建普通会话失败:", error);
uni.showToast({
title: "创建会话失败,请重试",
icon: "none"
@@ -5768,7 +5790,7 @@ This will fail in production.`);
};
const previewFileArray = vue.ref([]);
const uploadPhoto = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:564", "点击了拍照上传");
formatAppLog("log", "at pages/Chat/Chat.vue:567", "点击了拍照上传");
uni.chooseImage({
count: 1,
sourceType: ["camera", "album"],
@@ -5791,7 +5813,7 @@ This will fail in production.`);
});
},
fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:582", "选择图片失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:585", "选择图片失败", err);
}
});
};
@@ -5800,12 +5822,12 @@ This will fail in production.`);
};
const fileList = vue.ref([]);
const uploadFile = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:593", "点击了上传文件");
formatAppLog("log", "at pages/Chat/Chat.vue:596", "点击了上传文件");
chooseFile({
count: 5,
type: "all",
success: (res) => {
formatAppLog("log", "at pages/Chat/Chat.vue:598", "成功了");
formatAppLog("log", "at pages/Chat/Chat.vue:601", "成功了");
fileList.value = res.tempFiles;
previewFileArray.value.push(...res.tempFiles);
uni.showToast({
@@ -5814,7 +5836,7 @@ This will fail in production.`);
});
},
fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:609", "选择失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:612", "选择失败:", err);
uni.showToast({
title: "选择失败",
icon: "error"
@@ -5879,7 +5901,7 @@ This will fail in production.`);
previewFileArray.value = [];
} catch (err) {
uni.hideLoading();
formatAppLog("error", "at pages/Chat/Chat.vue:689", "文件上传失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:692", "文件上传失败:", err);
uni.showToast({
title: "文件上传失败,请重试",
icon: "error"
@@ -5973,7 +5995,6 @@ This will fail in production.`);
takeGroupMessages();
}, 1e3);
};
let aiResponseTimer = null;
const sendAIMessage = async () => {
try {
await handleConnect();
@@ -5991,16 +6012,6 @@ This will fail in production.`);
socketStore.send(data);
isThinking.value = true;
isSelfSent.value = true;
aiResponseTimer = setTimeout(() => {
uni.showToast({
title: "AI回复超时请重试",
icon: "none"
});
isThinking.value = false;
isSelfSent.value = false;
textMessage.value = "";
uploadedFiles.value = [];
}, 6e5);
} catch (error) {
isThinking.value = false;
uni.showToast({
@@ -6010,33 +6021,32 @@ This will fail in production.`);
}
};
const stopConversation = async () => {
formatAppLog("log", "at pages/Chat/Chat.vue:853", "中断对话 - 当前会话ID:", currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:856", "中断对话 - 当前会话ID:", currentSessionId.value);
try {
await socketStore.send({
type: "stop",
conversation_id: currentSessionId.value
});
formatAppLog("log", "at pages/Chat/Chat.vue:859", "中断指令已发送成功");
formatAppLog("log", "at pages/Chat/Chat.vue:862", "中断指令已发送成功");
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:861", "中断指令发送失败:", err);
formatAppLog("error", "at pages/Chat/Chat.vue:864", "中断指令发送失败:", err);
}
clearTimeout(aiResponseTimer);
isThinking.value = false;
socketStore.isThinking = false;
isSelfSent.value = false;
textMessage.value = "";
uploadedFiles.value = [];
uni.showToast({ title: "已中断", icon: "none", duration: 1500 });
};
vue.watch(() => socketStore.isThinking, (newVal, oldVal) => {
formatAppLog("log", "at pages/Chat/Chat.vue:875", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
formatAppLog("log", "at pages/Chat/Chat.vue:879", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
if (!oldVal && newVal) {
formatAppLog("log", "at pages/Chat/Chat.vue:878", "AI开始回复跨设备同步锁定输入框");
formatAppLog("log", "at pages/Chat/Chat.vue:882", "AI开始回复跨设备同步锁定输入框");
isThinking.value = true;
return;
}
if (oldVal && !newVal) {
clearTimeout(aiResponseTimer);
formatAppLog("log", "at pages/Chat/Chat.vue:885", "AI回复结束正常/中断),解锁并刷新消息列表");
formatAppLog("log", "at pages/Chat/Chat.vue:889", "AI回复结束正常/中断),解锁并刷新消息列表");
takeConversationMessages();
isThinking.value = false;
isSelfSent.value = false;
@@ -6071,15 +6081,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:928", "用户信息已加载:", UserId.value, UserAvatar.value);
formatAppLog("log", "at pages/Chat/Chat.vue:932", "用户信息已加载:", UserId.value, UserAvatar.value);
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:930", "获取用户信息失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:934", "获取用户信息失败:", error);
}
};
const takeUserConversations = async () => {
try {
userToken.value = getToken();
formatAppLog("log", "at pages/Chat/Chat.vue:938", "token:", userToken.value);
formatAppLog("log", "at pages/Chat/Chat.vue:942", "token:", userToken.value);
UserConversations.value = await getUserConversations(userToken.value) || [];
const savedSessionId = getCurrentSessionId();
if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) {
@@ -6089,7 +6099,7 @@ This will fail in production.`);
} else {
currentSessionId.value = "";
}
formatAppLog("log", "at pages/Chat/Chat.vue:950", "保存会话id", currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:954", "保存会话id", currentSessionId.value);
uni.setStorageSync("currentSessionId", currentSessionId.value);
} catch (error) {
uni.showToast({
@@ -6101,17 +6111,17 @@ This will fail in production.`);
const FriendInfoList = vue.ref([]);
const takeFriendList = async () => {
try {
formatAppLog("log", "at pages/Chat/Chat.vue:965", "开始获取好友列表");
formatAppLog("log", "at pages/Chat/Chat.vue:969", "开始获取好友列表");
const friendList = await getChatFriend(UserId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:968", "friendList:", friendList);
formatAppLog("log", "at pages/Chat/Chat.vue:972", "friendList:", friendList);
if (friendList && friendList.length) {
FriendInfoList.value = await takeUserAvatar(friendList);
} else {
FriendInfoList.value = [];
formatAppLog("log", "at pages/Chat/Chat.vue:973", "好友列表为空");
formatAppLog("log", "at pages/Chat/Chat.vue:977", "好友列表为空");
}
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:976", "获取好友列表失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:980", "获取好友列表失败:", error);
FriendInfoList.value = [];
} finally {
UserConversations.value = FriendInfoList.value;
@@ -6138,17 +6148,17 @@ This will fail in production.`);
};
});
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1006", "获取好友头像失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:1010", "获取好友头像失败", err);
return friendList;
}
};
const GroupList = vue.ref([]);
const takeGroupList = async () => {
try {
formatAppLog("log", "at pages/Chat/Chat.vue:1016", "开始获取群聊列表");
formatAppLog("log", "at pages/Chat/Chat.vue:1020", "开始获取群聊列表");
GroupList.value = await getGroup(UserId.value);
} catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:1021", "获取群聊列表失败:", error);
formatAppLog("error", "at pages/Chat/Chat.vue:1025", "获取群聊列表失败:", error);
GroupList.value = [];
} finally {
UserConversations.value = GroupList.value;
@@ -6160,22 +6170,22 @@ This will fail in production.`);
return [];
try {
const memberIds = memberList.map((item) => item.groupContactId);
formatAppLog("log", "at pages/Chat/Chat.vue:1035", "请求头像的ID列表:", memberIds);
formatAppLog("log", "at pages/Chat/Chat.vue:1039", "请求头像的ID列表:", memberIds);
const memberAvatarList = await getUserAvatar(userToken.value, memberIds);
formatAppLog("log", "at pages/Chat/Chat.vue:1037", "头像接口返回数据:", memberAvatarList);
formatAppLog("log", "at pages/Chat/Chat.vue:1041", "头像接口返回数据:", memberAvatarList);
const userMap = new Map(memberAvatarList.map((user) => [user.user_id, user]) || []);
formatAppLog("log", "at pages/Chat/Chat.vue:1040", "userMap的keys:", Array.from(userMap.keys()));
formatAppLog("log", "at pages/Chat/Chat.vue:1044", "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:1045", `查找 ${memberId} 的头像:`, userInfo);
formatAppLog("log", "at pages/Chat/Chat.vue:1049", `查找 ${memberId} 的头像:`, userInfo);
return {
...member,
avatar: (userInfo == null ? void 0 : userInfo.avatar) || null
};
});
} catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1052", "获取群成员头像失败", err);
formatAppLog("error", "at pages/Chat/Chat.vue:1056", "获取群成员头像失败", err);
return memberList;
}
};
@@ -6190,7 +6200,7 @@ This will fail in production.`);
const isLoadingMore = vue.ref(false);
const currentPage = vue.ref(1);
const currentMessages = vue.computed(() => {
return allmessages.value.slice(-pageInfoNumber);
return allmessages.value;
});
const takeConversationMessages = async () => {
try {
@@ -6206,7 +6216,7 @@ This will fail in production.`);
const takeFriendMessages = async () => {
try {
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
formatAppLog("log", "at pages/Chat/Chat.vue:1097", "好友消息:", JSON.stringify(allmessages.value));
formatAppLog("log", "at pages/Chat/Chat.vue:1102", "好友消息:", JSON.stringify(allmessages.value));
scrollToBottom();
} catch (error) {
uni.showToast({
@@ -6218,12 +6228,12 @@ This will fail in production.`);
const takeGroupMessages = async () => {
try {
allmessages.value = await getGroupMessages(currentSessionId.value) || [];
formatAppLog("log", "at pages/Chat/Chat.vue:1110", "群聊消息:", allmessages.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1115", "群聊消息:", allmessages.value);
const memberList = await getGroupMemberList(currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1113", "获取到的群成员列表:", memberList);
formatAppLog("log", "at pages/Chat/Chat.vue:1118", "获取到的群成员列表:", memberList);
if (memberList && memberList.length) {
groupMemberList.value = await takeGroupMemberAvatar(memberList);
formatAppLog("log", "at pages/Chat/Chat.vue:1116", "群成员列表(带头像):", groupMemberList.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1121", "群成员列表(带头像):", groupMemberList.value);
} else {
groupMemberList.value = [];
}
@@ -6235,17 +6245,6 @@ This will fail in production.`);
});
}
};
const loadMoreMessages = async () => {
formatAppLog("log", "at pages/Chat/Chat.vue:1131", "加载更多信息");
if (allmessages.value.length > pageInfoNumber * currentPage.value) {
currentPage.value += 1;
const newMessages = allmessages.value.slice(-pageInfoNumber * currentPage.value);
const addMessage = newMessages.length - currentMessages.value.length;
currentMessages.value = newMessages;
await vue.nextTick();
scrollToView.value = "msg-" + (addMessage + 1);
}
};
const onScroll = (e2) => {
};
const scrollToBottom = async () => {
@@ -6255,9 +6254,9 @@ This will fail in production.`);
}
};
vue.watch(() => friendSocketStore.MessageReceived, (newId) => {
formatAppLog("log", "at pages/Chat/Chat.vue:1159", "收到了好友消息");
formatAppLog("log", "at pages/Chat/Chat.vue:1164", "收到了好友消息");
if (newId) {
formatAppLog("log", "at pages/Chat/Chat.vue:1161", "ChatType:", ChatType.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1166", "ChatType:", ChatType.value);
switch (ChatType.value) {
case 0:
takeConversationMessages();
@@ -6272,7 +6271,7 @@ This will fail in production.`);
friendSocketStore.MessageReceived = false;
break;
default:
formatAppLog("log", "at pages/Chat/Chat.vue:1177", "default 分支");
formatAppLog("log", "at pages/Chat/Chat.vue:1182", "default 分支");
friendSocketStore.MessageReceived = false;
break;
}
@@ -6334,11 +6333,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, showMessageModal, detailMessageContent, showMessageDetail, closeMessageDetail, sendMessage, sendFriendMessage, sendGroupMessage, get aiResponseTimer() {
return aiResponseTimer;
}, set aiResponseTimer(v) {
aiResponseTimer = v;
}, sendAIMessage, stopConversation, textMessage, UserConversations, currentSessionId, userToken, UserId, UserAvatar, UserData, takeUserInfo, takeUserConversations, FriendInfoList, takeFriendList, takeTalkUserAvatar, takeUserAvatar, GroupList, takeGroupList, groupMemberList, takeGroupMemberAvatar, getGroupMemberAvatarById, allmessages, pageInfoNumber, scrollToView, isLoadingMore, currentPage, currentMessages, takeConversationMessages, takeFriendMessages, takeGroupMessages, loadMoreMessages, 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, 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, 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;
@@ -6581,7 +6576,6 @@ This will fail in production.`);
direction: "vertical",
"scroll-y": "",
"scroll-into-view": $setup.scrollToView,
onScrolltoupper: $setup.loadMoreMessages,
"upper-threshold": 0,
"scroll-with-animation": true,
onScroll: $setup.onScroll
@@ -6955,9 +6949,16 @@ This will fail in production.`);
}, null, 8, ["placeholder", "disabled"]), [
[vue.vModelText, $setup.textMessage]
]),
vue.createElementVNode(
$setup.isThinking && !$setup.isSelfSent ? (vue.openBlock(), vue.createElementBlock("view", {
key: 0,
class: "input-btn-group stop-message-btn",
onClick: $setup.stopConversation
}, [
vue.createElementVNode("view", { class: "iconfont icon-tingzhi" })
])) : (vue.openBlock(), vue.createElementBlock(
"view",
{
key: 1,
class: vue.normalizeClass(["input-btn-group send-message-btn", { disabled: $setup.isThinking }]),
onClick: _cache[9] || (_cache[9] = ($event) => !$setup.isThinking && $setup.sendMessage())
},
@@ -6966,7 +6967,7 @@ This will fail in production.`);
],
2
/* CLASS */
)
))
],
2
/* CLASS */

View File

@@ -1200,6 +1200,13 @@ to { opacity: 1; transform: translateY(0) scale(1);
width: 100%;
flex-direction: column;
}
/* ==========加载更多提示========== */
.load-more-tip[data-v-5eb7b895] {
text-align: center;
padding: 0.625rem 0;
font-size: 0.75rem;
color: #999;
}
/* ==========聊天对话展示部分========== */
.chat-messages[data-v-5eb7b895] {
display: flex;
@@ -1437,6 +1444,16 @@ to { opacity: 1; transform: translateY(0);
background: #c0c0d0;
box-shadow: none;
}
/* PC端中断发送按钮 */
.stop-message-btn[data-v-5eb7b895] {
background: linear-gradient(135deg, #ff4d4f, #ff6b6b);
box-shadow: 0 0.125rem 0.375rem rgba(255, 77, 79, 0.35);
animation: pulseStop-5eb7b895 1.8s ease-in-out infinite;
}
.stop-message-btn[data-v-5eb7b895]:active {
transform: scale(0.92);
box-shadow: 0 0.0625rem 0.1875rem rgba(255, 77, 79, 0.25);
}
.input-btn-group[data-v-5eb7b895] {
flex-shrink: 0;
display: flex;

View File

@@ -28,7 +28,11 @@ export const login = async (username, password) => {
reject(msg)
}
} else {
reject(`请求失败:${res.statusCode}`)
if (String(res.statusCode).startsWith('5')) {
reject({ serverError: true, code: res.statusCode, message: '服务器升级中,请稍后再试' })
} else {
reject(`请求失败:${res.statusCode}`)
}
}
},
fail: (err) => {
@@ -90,7 +94,10 @@ export const getConversationMessages = async (token, conversatio_id) => {
if (messagesInfo.workspace_id) {
uni.setStorageSync('workspace_id', messagesInfo.workspace_id)
}
resolve(messagesInfo.messages)
const filtered = (messagesInfo.messages || []).filter(
m => m.role !== 'tool'
)
resolve(filtered)
} else {
const msg = res.data.error || '获取消息出错啦'
reject(msg)

View File

@@ -172,6 +172,12 @@ class WebSocketManager {
this.close()
return
}
// if (type === 'pc offline') {
// console.log("pc端不在线不可聊天2");
// return
// }
}