From 7d0c834ba5e679919d56499d47ea4f835668fda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Mon, 22 Dec 2025 11:16:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=A2=E6=9C=8D=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E5=8A=9F=E8=83=BD=EF=BC=9A=E6=94=B9=E8=BF=9B=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E4=BC=9A=E8=AF=9DID=E4=BC=A0=E9=80=92=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8=E5=AE=A2?= =?UTF-8?q?=E6=9C=8D=E6=89=8B=E6=9C=BA=E5=8F=B7=E4=BD=9C=E4=B8=BA=E8=81=8A?= =?UTF-8?q?=E5=A4=A9ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/chat-detail/index.js | 24 +++++++++++++++++++----- pages/customer-service/index.js | 19 ++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/pages/chat-detail/index.js b/pages/chat-detail/index.js index 81594f9..e862e0b 100644 --- a/pages/chat-detail/index.js +++ b/pages/chat-detail/index.js @@ -19,19 +19,29 @@ Page({ }, onLoad: function (options) { - if (options.id) { + console.log('聊天详情页面加载 - 传递的参数:', JSON.stringify(options, null, 2)); + // 同时支持id和userId参数,优先使用userId + const chatId = options.userId || options.id; + if (chatId) { + console.log('聊天详情页面 - 设置聊天ID:', chatId); this.setData({ - chatId: options.id, - managerPhone: options.id + chatId: chatId, + managerPhone: options.phone || chatId // 使用传递的phone作为managerPhone,否则使用chatId }); + console.log('聊天详情页面 - 设置客服手机号:', this.data.managerPhone); - if (options.name) { + if (options.name || options.userName) { + // 同时支持name和userName参数 + const chatTitle = decodeURIComponent(options.name || options.userName); + console.log('聊天详情页面 - 设置聊天标题:', chatTitle); this.setData({ - chatTitle: decodeURIComponent(options.name) + chatTitle: chatTitle }); } else { this.loadChatTitle(); } + } else { + console.error('聊天详情页面 - 未传递有效的聊天ID'); } this.loadMessages(); // 使用默认值true,首次进入页面时自动滚动到底部 this.startTimer(); @@ -119,9 +129,12 @@ Page({ return; } + console.log('加载聊天消息 - 聊天ID:', this.data.chatId, '用户手机号:', userPhone); // 获取聊天消息 API.getChatMessages(this.data.chatId, userPhone).then(res => { + console.log('加载聊天消息 - API返回:', JSON.stringify(res, null, 2)); if (Array.isArray(res)) { + console.log('加载聊天消息 - API返回消息数量:', res.length); // 处理消息并排序 const processedMessages = res.map(message => { const sender = (message.sender_phone === userPhone) ? 'me' : 'other'; @@ -185,6 +198,7 @@ Page({ } }); } else { + console.log('加载聊天消息 - API返回非数组数据:', res); this.setData({ messages: [], loading: false diff --git a/pages/customer-service/index.js b/pages/customer-service/index.js index 5e517c9..f89242e 100644 --- a/pages/customer-service/index.js +++ b/pages/customer-service/index.js @@ -335,17 +335,26 @@ Page({ // 调用API添加聊天记录 api.addChatRecord(userPhone, service.phoneNumber).then(res => { - console.log('添加聊天记录成功:', res); + console.log('添加聊天记录成功:', JSON.stringify(res, null, 2)); // 隐藏加载提示 wx.hideLoading(); - // 确保使用managerId作为聊天对象的唯一标识符 - const chatUserId = service?.managerId || id; + // 打印所有可能的chatSessionId来源 + console.log('聊天会话ID候选值:', { + res_data_chatSessionId: res?.data?.chatSessionId, + res_chatSessionId: res?.chatSessionId, + service_managerId: service?.managerId, + service_id: id, + service_phoneNumber: service?.phoneNumber + }); + + // 尝试从服务器响应中获取聊天会话ID,如果没有则使用客服手机号,再没有则使用managerId或id + const chatSessionId = res?.data?.chatSessionId || res?.chatSessionId || service?.phoneNumber || service?.managerId || id; // 跳转到聊天页面 wx.navigateTo({ - url: `/pages/chat-detail/index?userId=${chatUserId}&userName=${encodeURIComponent(service?.alias || '')}&phone=${service?.phoneNumber || ''}&isManager=true` + url: `/pages/chat-detail/index?userId=${chatSessionId}&userName=${encodeURIComponent(service?.alias || '')}&phone=${service?.phoneNumber || ''}&isManager=true` }); - console.log('跳转到聊天页面:', { chatUserId, userName: service?.alias }); + console.log('跳转到聊天页面:', { chatUserId: chatSessionId, userName: service?.alias, serverResponse: JSON.stringify(res, null, 2) }); }).catch(err => { console.error('添加聊天记录失败:', err); // 隐藏加载提示