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

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; flex-direction: column;
} }
/* ==========加载更多提示========== */
.load-more-tip {
text-align: center;
padding: 20rpx 0;
font-size: 24rpx;
color: #999;
}
/* ==========聊天对话展示部分========== */ /* ==========聊天对话展示部分========== */
.chat-messages { .chat-messages {
display: flex; display: flex;
@@ -603,6 +611,18 @@
box-shadow: none; 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 { .input-btn-group {
flex-shrink: 0; flex-shrink: 0;
display: flex; display: flex;

View File

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

View File

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

View File

@@ -80,9 +80,13 @@ if (uni.restoreGlobal) {
const msg = res.data.error || "检查用户名和密码"; const msg = res.data.error || "检查用户名和密码";
reject(msg); reject(msg);
} }
} else {
if (String(res.statusCode).startsWith("5")) {
reject({ serverError: true, code: res.statusCode, message: "服务器升级中,请稍后再试" });
} else { } else {
reject(`请求失败:${res.statusCode}`); reject(`请求失败:${res.statusCode}`);
} }
}
}, },
fail: (err) => { fail: (err) => {
const msg = err.errMsg || "网络错误"; const msg = err.errMsg || "网络错误";
@@ -134,11 +138,14 @@ if (uni.restoreGlobal) {
if (res.statusCode === 200) { if (res.statusCode === 200) {
const messagesInfo = res.data; const messagesInfo = res.data;
if (messagesInfo) { 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) { if (messagesInfo.workspace_id) {
uni.setStorageSync("workspace_id", 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 { } else {
const msg = res.data.error || "获取消息出错啦"; const msg = res.data.error || "获取消息出错啦";
reject(msg); reject(msg);
@@ -551,7 +558,7 @@ if (uni.restoreGlobal) {
uri: fileUri 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({ uni.uploadFile({
url: `${BASE_URL}/cloud_api/file/temp/upload`, url: `${BASE_URL}/cloud_api/file/temp/upload`,
method: "POST", method: "POST",
@@ -562,7 +569,7 @@ if (uni.restoreGlobal) {
}, },
files: uploadFiles, files: uploadFiles,
success: (res) => { 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) { if (res.statusCode === 200) {
try { try {
const respond = JSON.parse(res.data); const respond = JSON.parse(res.data);
@@ -1557,10 +1564,19 @@ if (uni.restoreGlobal) {
}); });
} catch (err) { } catch (err) {
formatAppLog("log", "at pages/Login/Login.vue:125", "登录失败", err); formatAppLog("log", "at pages/Login/Login.vue:125", "登录失败", err);
if (err && typeof err === "object" && err.serverError) {
uni.showModal({
title: "提示",
content: err.message,
showCancel: false,
confirmText: "知道了"
});
} else {
uni.showToast({ uni.showToast({
title: err || "失败", title: (err == null ? void 0 : err.message) || err || "失败",
icon: "error" icon: "error"
}); });
}
} finally { } finally {
loading.value = false; loading.value = false;
} }
@@ -1592,7 +1608,7 @@ if (uni.restoreGlobal) {
form.remember = loginInfo.remember ?? true; form.remember = loginInfo.remember ?? true;
} }
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Login/Login.vue:169", "读取登录信息失败", e2); formatAppLog("error", "at pages/Login/Login.vue:178", "读取登录信息失败", e2);
} }
}; };
vue.onMounted(() => { vue.onMounted(() => {
@@ -4479,12 +4495,12 @@ This will fail in production.`);
return; return;
} }
const msg = JSON.stringify(data); const msg = JSON.stringify(data);
formatAppLog("log", "at utils/socket.js:193", "发送的消息是:", msg); formatAppLog("log", "at utils/socket.js:199", "发送的消息是:", msg);
this.ws.send({ this.ws.send({
data: msg, data: msg,
success: () => resolve(), success: () => resolve(),
fail: (err) => { fail: (err) => {
formatAppLog("error", "at utils/socket.js:201", "发送消息失败:", err); formatAppLog("error", "at utils/socket.js:207", "发送消息失败:", err);
reject(err); reject(err);
} }
}); });
@@ -4498,7 +4514,7 @@ This will fail in production.`);
if (this.reconnectTimer) if (this.reconnectTimer)
return; return;
this.reconnectAttempts++; 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 = setTimeout(() => {
this.reconnectTimer = null; this.reconnectTimer = null;
if (!this.isManualClose) { if (!this.isManualClose) {
@@ -4517,7 +4533,7 @@ This will fail in production.`);
this.send({ this.send({
ws_event: "ping" ws_event: "ping"
}).catch(() => { }).catch(() => {
formatAppLog("log", "at utils/socket.js:249", "心跳发送失败,准备重连"); formatAppLog("log", "at utils/socket.js:255", "心跳发送失败,准备重连");
if (!this.reconnectTimer && !this.isManualClose) { if (!this.reconnectTimer && !this.isManualClose) {
this.reconnect(); this.reconnect();
} }
@@ -4542,7 +4558,7 @@ This will fail in production.`);
*/ */
handleError(error) { handleError(error) {
var _a, _b; 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); (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, error);
} }
/** /**
@@ -4568,7 +4584,7 @@ This will fail in production.`);
* 清理所有定时器、标记手动关闭、停止重连 * 清理所有定时器、标记手动关闭、停止重连
*/ */
close() { close() {
formatAppLog("log", "at utils/socket.js:313", "手动关闭 WebSocket 连接"); formatAppLog("log", "at utils/socket.js:319", "手动关闭 WebSocket 连接");
this.isManualClose = true; this.isManualClose = true;
this.stopHeartbeat(); this.stopHeartbeat();
if (this.reconnectTimer) { if (this.reconnectTimer) {
@@ -4586,11 +4602,11 @@ This will fail in production.`);
this.ws.onClose(null); this.ws.onClose(null);
try { try {
this.ws.close({ this.ws.close({
success: () => formatAppLog("log", "at utils/socket.js:335", "连接已关闭"), success: () => formatAppLog("log", "at utils/socket.js:341", "连接已关闭"),
fail: (err) => formatAppLog("error", "at utils/socket.js:336", "关闭失败:", err) fail: (err) => formatAppLog("error", "at utils/socket.js:342", "关闭失败:", err)
}); });
} catch (error) { } catch (error) {
formatAppLog("error", "at utils/socket.js:344", "关闭连接出错:", error); formatAppLog("error", "at utils/socket.js:350", "关闭连接出错:", error);
} }
this.ws = null; this.ws = null;
} }
@@ -4727,7 +4743,7 @@ This will fail in production.`);
message_id, message_id,
data data
} = messageData || {}; } = 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) { switch (type) {
case "auth_ok": case "auth_ok":
addLog("success", "连接成功"); addLog("success", "连接成功");
@@ -4744,6 +4760,9 @@ This will fail in production.`);
addLog("warn", "AI正在回复信息"); addLog("warn", "AI正在回复信息");
handleBusinessMessage(data); handleBusinessMessage(data);
break; break;
case "pc_offline":
addLog("warn", "PC 端已离线");
break;
default: default:
addLog("info", `未知事件类型: ${type}`); addLog("info", `未知事件类型: ${type}`);
} }
@@ -4757,14 +4776,14 @@ This will fail in production.`);
} }
function handleBusinessMessage(data) { function handleBusinessMessage(data) {
if (data === "exit") { if (data === "exit") {
formatAppLog("log", "at stores/socket.js:220", "ai结束思考"); formatAppLog("log", "at stores/socket.js:224", "ai结束思考");
isThinking.value = false; isThinking.value = false;
return; return;
} }
if (!data || typeof data !== "object") if (!data || typeof data !== "object")
return; return;
if (data.cmd === "event_callback" && data.info === "中断成功") { 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}`); addLog("warn", `中断确认: ${data.info}`);
isThinking.value = false; isThinking.value = false;
return; return;
@@ -4778,12 +4797,16 @@ This will fail in production.`);
task_call_id task_call_id
} = data; } = data;
if (!isThinking.value && (chunk || message_role === "assistant")) { 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 = ""; messageString.value = "";
isThinking.value = true; isThinking.value = true;
} }
if (chunk) { if (chunk) {
messageString.value += chunk; messageString.value += chunk;
if (!isThinking.value) {
formatAppLog("log", "at stores/socket.js:260", "修改状态为开始思考");
isThinking.value = true;
}
} }
} }
function getStatusText() { function getStatusText() {
@@ -5565,7 +5588,6 @@ This will fail in production.`);
const pkg = /* @__PURE__ */ initUTSPackageName(name, is_uni_modules); const pkg = /* @__PURE__ */ initUTSPackageName(name, is_uni_modules);
const cls = /* @__PURE__ */ initUTSIndexClassName(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 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 = { const _sfc_main$9 = {
__name: "Chat", __name: "Chat",
setup(__props, { expose: __expose }) { setup(__props, { expose: __expose }) {
@@ -5575,7 +5597,7 @@ This will fail in production.`);
if (friendSocketStore.isConnected) if (friendSocketStore.isConnected)
return; return;
if (!userToken.value || !UserId.value) { 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; return;
} }
friendSocketStore.connect({ friendSocketStore.connect({
@@ -5646,7 +5668,7 @@ This will fail in production.`);
const html = t(content); const html = t(content);
return html; return html;
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:405", "解析失败", e2); formatAppLog("error", "at pages/Chat/Chat.vue:408", "解析失败", e2);
return content; return content;
} }
}; };
@@ -5696,7 +5718,7 @@ This will fail in production.`);
const textContent = content.replace(match[0], "").trim(); const textContent = content.replace(match[0], "").trim();
return { textContent, files }; return { textContent, files };
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:473", "解析文件信息失败:", e2); formatAppLog("error", "at pages/Chat/Chat.vue:476", "解析文件信息失败:", e2);
return { textContent: content, files: [] }; return { textContent: content, files: [] };
} }
}; };
@@ -5730,7 +5752,7 @@ This will fail in production.`);
} }
takeUserConversations(); takeUserConversations();
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:515", "新建普通会话失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:518", "新建普通会话失败:", error);
uni.showToast({ uni.showToast({
title: "创建会话失败,请重试", title: "创建会话失败,请重试",
icon: "none" icon: "none"
@@ -5768,7 +5790,7 @@ This will fail in production.`);
}; };
const previewFileArray = vue.ref([]); const previewFileArray = vue.ref([]);
const uploadPhoto = () => { const uploadPhoto = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:564", "点击了拍照上传"); formatAppLog("log", "at pages/Chat/Chat.vue:567", "点击了拍照上传");
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
sourceType: ["camera", "album"], sourceType: ["camera", "album"],
@@ -5791,7 +5813,7 @@ This will fail in production.`);
}); });
}, },
fail: (err) => { 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 fileList = vue.ref([]);
const uploadFile = () => { const uploadFile = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:593", "点击了上传文件"); formatAppLog("log", "at pages/Chat/Chat.vue:596", "点击了上传文件");
chooseFile({ chooseFile({
count: 5, count: 5,
type: "all", type: "all",
success: (res) => { success: (res) => {
formatAppLog("log", "at pages/Chat/Chat.vue:598", "成功了"); formatAppLog("log", "at pages/Chat/Chat.vue:601", "成功了");
fileList.value = res.tempFiles; fileList.value = res.tempFiles;
previewFileArray.value.push(...res.tempFiles); previewFileArray.value.push(...res.tempFiles);
uni.showToast({ uni.showToast({
@@ -5814,7 +5836,7 @@ This will fail in production.`);
}); });
}, },
fail: (err) => { fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:609", "选择失败:", err); formatAppLog("error", "at pages/Chat/Chat.vue:612", "选择失败:", err);
uni.showToast({ uni.showToast({
title: "选择失败", title: "选择失败",
icon: "error" icon: "error"
@@ -5879,7 +5901,7 @@ This will fail in production.`);
previewFileArray.value = []; previewFileArray.value = [];
} catch (err) { } catch (err) {
uni.hideLoading(); uni.hideLoading();
formatAppLog("error", "at pages/Chat/Chat.vue:689", "文件上传失败:", err); formatAppLog("error", "at pages/Chat/Chat.vue:692", "文件上传失败:", err);
uni.showToast({ uni.showToast({
title: "文件上传失败,请重试", title: "文件上传失败,请重试",
icon: "error" icon: "error"
@@ -5973,7 +5995,6 @@ This will fail in production.`);
takeGroupMessages(); takeGroupMessages();
}, 1e3); }, 1e3);
}; };
let aiResponseTimer = null;
const sendAIMessage = async () => { const sendAIMessage = async () => {
try { try {
await handleConnect(); await handleConnect();
@@ -5991,16 +6012,6 @@ This will fail in production.`);
socketStore.send(data); socketStore.send(data);
isThinking.value = true; isThinking.value = true;
isSelfSent.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) { } catch (error) {
isThinking.value = false; isThinking.value = false;
uni.showToast({ uni.showToast({
@@ -6010,33 +6021,32 @@ This will fail in production.`);
} }
}; };
const stopConversation = async () => { 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 { try {
await socketStore.send({ await socketStore.send({
type: "stop", type: "stop",
conversation_id: currentSessionId.value conversation_id: currentSessionId.value
}); });
formatAppLog("log", "at pages/Chat/Chat.vue:859", "中断指令已发送成功"); formatAppLog("log", "at pages/Chat/Chat.vue:862", "中断指令已发送成功");
} catch (err) { } 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; isThinking.value = false;
socketStore.isThinking = false;
isSelfSent.value = false; isSelfSent.value = false;
textMessage.value = ""; textMessage.value = "";
uploadedFiles.value = []; uploadedFiles.value = [];
uni.showToast({ title: "已中断", icon: "none", duration: 1500 }); uni.showToast({ title: "已中断", icon: "none", duration: 1500 });
}; };
vue.watch(() => socketStore.isThinking, (newVal, oldVal) => { 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) { if (!oldVal && newVal) {
formatAppLog("log", "at pages/Chat/Chat.vue:878", "AI开始回复跨设备同步锁定输入框"); formatAppLog("log", "at pages/Chat/Chat.vue:882", "AI开始回复跨设备同步锁定输入框");
isThinking.value = true; isThinking.value = true;
return; return;
} }
if (oldVal && !newVal) { if (oldVal && !newVal) {
clearTimeout(aiResponseTimer); formatAppLog("log", "at pages/Chat/Chat.vue:889", "AI回复结束正常/中断),解锁并刷新消息列表");
formatAppLog("log", "at pages/Chat/Chat.vue:885", "AI回复结束正常/中断),解锁并刷新消息列表");
takeConversationMessages(); takeConversationMessages();
isThinking.value = false; isThinking.value = false;
isSelfSent.value = false; isSelfSent.value = false;
@@ -6071,15 +6081,15 @@ This will fail in production.`);
UserData.value = await getUserInfo(userToken.value); UserData.value = await getUserInfo(userToken.value);
UserId.value = UserData.value._id; UserId.value = UserData.value._id;
UserAvatar.value = UserData.value.avatar || ""; 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) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:930", "获取用户信息失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:934", "获取用户信息失败:", error);
} }
}; };
const takeUserConversations = async () => { const takeUserConversations = async () => {
try { try {
userToken.value = getToken(); 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) || []; UserConversations.value = await getUserConversations(userToken.value) || [];
const savedSessionId = getCurrentSessionId(); const savedSessionId = getCurrentSessionId();
if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) { if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) {
@@ -6089,7 +6099,7 @@ This will fail in production.`);
} else { } else {
currentSessionId.value = ""; 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); uni.setStorageSync("currentSessionId", currentSessionId.value);
} catch (error) { } catch (error) {
uni.showToast({ uni.showToast({
@@ -6101,17 +6111,17 @@ This will fail in production.`);
const FriendInfoList = vue.ref([]); const FriendInfoList = vue.ref([]);
const takeFriendList = async () => { const takeFriendList = async () => {
try { try {
formatAppLog("log", "at pages/Chat/Chat.vue:965", "开始获取好友列表"); formatAppLog("log", "at pages/Chat/Chat.vue:969", "开始获取好友列表");
const friendList = await getChatFriend(UserId.value); 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) { if (friendList && friendList.length) {
FriendInfoList.value = await takeUserAvatar(friendList); FriendInfoList.value = await takeUserAvatar(friendList);
} else { } else {
FriendInfoList.value = []; FriendInfoList.value = [];
formatAppLog("log", "at pages/Chat/Chat.vue:973", "好友列表为空"); formatAppLog("log", "at pages/Chat/Chat.vue:977", "好友列表为空");
} }
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:976", "获取好友列表失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:980", "获取好友列表失败:", error);
FriendInfoList.value = []; FriendInfoList.value = [];
} finally { } finally {
UserConversations.value = FriendInfoList.value; UserConversations.value = FriendInfoList.value;
@@ -6138,17 +6148,17 @@ This will fail in production.`);
}; };
}); });
} catch (err) { } catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1006", "获取好友头像失败", err); formatAppLog("error", "at pages/Chat/Chat.vue:1010", "获取好友头像失败", err);
return friendList; return friendList;
} }
}; };
const GroupList = vue.ref([]); const GroupList = vue.ref([]);
const takeGroupList = async () => { const takeGroupList = async () => {
try { try {
formatAppLog("log", "at pages/Chat/Chat.vue:1016", "开始获取群聊列表"); formatAppLog("log", "at pages/Chat/Chat.vue:1020", "开始获取群聊列表");
GroupList.value = await getGroup(UserId.value); GroupList.value = await getGroup(UserId.value);
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:1021", "获取群聊列表失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:1025", "获取群聊列表失败:", error);
GroupList.value = []; GroupList.value = [];
} finally { } finally {
UserConversations.value = GroupList.value; UserConversations.value = GroupList.value;
@@ -6160,22 +6170,22 @@ This will fail in production.`);
return []; return [];
try { try {
const memberIds = memberList.map((item) => item.groupContactId); 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); 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]) || []); 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) => { return memberList.map((member) => {
const memberId = member.groupContactId; const memberId = member.groupContactId;
const userInfo = userMap.get(memberId); 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 { return {
...member, ...member,
avatar: (userInfo == null ? void 0 : userInfo.avatar) || null avatar: (userInfo == null ? void 0 : userInfo.avatar) || null
}; };
}); });
} catch (err) { } catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1052", "获取群成员头像失败", err); formatAppLog("error", "at pages/Chat/Chat.vue:1056", "获取群成员头像失败", err);
return memberList; return memberList;
} }
}; };
@@ -6190,7 +6200,7 @@ This will fail in production.`);
const isLoadingMore = vue.ref(false); const isLoadingMore = vue.ref(false);
const currentPage = vue.ref(1); const currentPage = vue.ref(1);
const currentMessages = vue.computed(() => { const currentMessages = vue.computed(() => {
return allmessages.value.slice(-pageInfoNumber); return allmessages.value;
}); });
const takeConversationMessages = async () => { const takeConversationMessages = async () => {
try { try {
@@ -6206,7 +6216,7 @@ This will fail in production.`);
const takeFriendMessages = async () => { const takeFriendMessages = async () => {
try { try {
allmessages.value = await getFriendMessages(currentSessionId.value) || []; 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(); scrollToBottom();
} catch (error) { } catch (error) {
uni.showToast({ uni.showToast({
@@ -6218,12 +6228,12 @@ This will fail in production.`);
const takeGroupMessages = async () => { const takeGroupMessages = async () => {
try { try {
allmessages.value = await getGroupMessages(currentSessionId.value) || []; 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); 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) { if (memberList && memberList.length) {
groupMemberList.value = await takeGroupMemberAvatar(memberList); 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 { } else {
groupMemberList.value = []; 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 onScroll = (e2) => {
}; };
const scrollToBottom = async () => { const scrollToBottom = async () => {
@@ -6255,9 +6254,9 @@ This will fail in production.`);
} }
}; };
vue.watch(() => friendSocketStore.MessageReceived, (newId) => { vue.watch(() => friendSocketStore.MessageReceived, (newId) => {
formatAppLog("log", "at pages/Chat/Chat.vue:1159", "收到了好友消息"); formatAppLog("log", "at pages/Chat/Chat.vue:1164", "收到了好友消息");
if (newId) { 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) { switch (ChatType.value) {
case 0: case 0:
takeConversationMessages(); takeConversationMessages();
@@ -6272,7 +6271,7 @@ This will fail in production.`);
friendSocketStore.MessageReceived = false; friendSocketStore.MessageReceived = false;
break; break;
default: default:
formatAppLog("log", "at pages/Chat/Chat.vue:1177", "default 分支"); formatAppLog("log", "at pages/Chat/Chat.vue:1182", "default 分支");
friendSocketStore.MessageReceived = false; friendSocketStore.MessageReceived = false;
break; break;
} }
@@ -6334,11 +6333,7 @@ This will fail in production.`);
onUnload(() => { onUnload(() => {
socketStore.disconnect(); 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() { 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 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() {
return onShow; return onShow;
}, get onUnload() { }, get onUnload() {
return onUnload; return onUnload;
@@ -6581,7 +6576,6 @@ This will fail in production.`);
direction: "vertical", direction: "vertical",
"scroll-y": "", "scroll-y": "",
"scroll-into-view": $setup.scrollToView, "scroll-into-view": $setup.scrollToView,
onScrolltoupper: $setup.loadMoreMessages,
"upper-threshold": 0, "upper-threshold": 0,
"scroll-with-animation": true, "scroll-with-animation": true,
onScroll: $setup.onScroll onScroll: $setup.onScroll
@@ -6955,9 +6949,16 @@ This will fail in production.`);
}, null, 8, ["placeholder", "disabled"]), [ }, null, 8, ["placeholder", "disabled"]), [
[vue.vModelText, $setup.textMessage] [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", "view",
{ {
key: 1,
class: vue.normalizeClass(["input-btn-group send-message-btn", { disabled: $setup.isThinking }]), class: vue.normalizeClass(["input-btn-group send-message-btn", { disabled: $setup.isThinking }]),
onClick: _cache[9] || (_cache[9] = ($event) => !$setup.isThinking && $setup.sendMessage()) onClick: _cache[9] || (_cache[9] = ($event) => !$setup.isThinking && $setup.sendMessage())
}, },
@@ -6966,7 +6967,7 @@ This will fail in production.`);
], ],
2 2
/* CLASS */ /* CLASS */
) ))
], ],
2 2
/* CLASS */ /* CLASS */

View File

@@ -1200,6 +1200,13 @@ to { opacity: 1; transform: translateY(0) scale(1);
width: 100%; width: 100%;
flex-direction: column; 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] { .chat-messages[data-v-5eb7b895] {
display: flex; display: flex;
@@ -1437,6 +1444,16 @@ to { opacity: 1; transform: translateY(0);
background: #c0c0d0; background: #c0c0d0;
box-shadow: none; 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] { .input-btn-group[data-v-5eb7b895] {
flex-shrink: 0; flex-shrink: 0;
display: flex; display: flex;

View File

@@ -27,9 +27,13 @@ export const login = async (username, password) => {
const msg = res.data.error || '检查用户名和密码' const msg = res.data.error || '检查用户名和密码'
reject(msg) reject(msg)
} }
} else {
if (String(res.statusCode).startsWith('5')) {
reject({ serverError: true, code: res.statusCode, message: '服务器升级中,请稍后再试' })
} else { } else {
reject(`请求失败:${res.statusCode}`) reject(`请求失败:${res.statusCode}`)
} }
}
}, },
fail: (err) => { fail: (err) => {
const msg = err.errMsg || '网络错误' const msg = err.errMsg || '网络错误'
@@ -90,7 +94,10 @@ export const getConversationMessages = async (token, conversatio_id) => {
if (messagesInfo.workspace_id) { if (messagesInfo.workspace_id) {
uni.setStorageSync('workspace_id', 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 { } else {
const msg = res.data.error || '获取消息出错啦' const msg = res.data.error || '获取消息出错啦'
reject(msg) reject(msg)

View File

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