|
|
|
@ -799,7 +799,69 @@ Page({ |
|
|
|
const userName = e.currentTarget.dataset.userName; |
|
|
|
const conversationId = e.currentTarget.dataset.conversationId; |
|
|
|
|
|
|
|
console.log('导航到聊天详情:', { userId, userName, conversationId }); |
|
|
|
// 关键修复:获取原始数据
|
|
|
|
const message = this.data.messages.find(item => |
|
|
|
item.id === userId || item.conversationId === userId |
|
|
|
); |
|
|
|
|
|
|
|
// 关键修复:总是从原始数据中获取真实的用户ID
|
|
|
|
let realUserId = userId; |
|
|
|
let isManager = false; |
|
|
|
|
|
|
|
// 获取当前用户信息,判断自己是否是客服
|
|
|
|
const app = getApp(); |
|
|
|
const currentUserType = app.globalData.userInfo?.userType || wx.getStorageSync('userType'); |
|
|
|
const currentManagerId = app.globalData.userInfo?.managerId || wx.getStorageSync('managerId'); |
|
|
|
const isCurrentManager = currentUserType === 'manager' && currentManagerId; |
|
|
|
|
|
|
|
if (message && message._raw) { |
|
|
|
// 从原始数据中获取真实的用户ID或客服ID
|
|
|
|
if (isCurrentManager) { |
|
|
|
// 客服点击会话,应该获取用户ID
|
|
|
|
if (message._raw.user_id) { |
|
|
|
realUserId = message._raw.user_id; |
|
|
|
console.log('客服模式:从原始数据中提取真实用户ID:', realUserId); |
|
|
|
} else if (message._raw.manager_id) { |
|
|
|
realUserId = message._raw.manager_id; |
|
|
|
isManager = true; |
|
|
|
console.log('客服模式:从原始数据中提取真实客服ID:', realUserId); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 用户点击会话,应该获取客服ID
|
|
|
|
if (message._raw.manager_id) { |
|
|
|
realUserId = message._raw.manager_id; |
|
|
|
isManager = true; |
|
|
|
console.log('用户模式:从原始数据中提取真实客服ID:', realUserId); |
|
|
|
} else if (message._raw.user_id) { |
|
|
|
realUserId = message._raw.user_id; |
|
|
|
console.log('用户模式:从原始数据中提取真实用户ID:', realUserId); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 直接检查userId格式
|
|
|
|
if (/^\d+$/.test(userId)) { |
|
|
|
// 如果userId是纯数字,很可能是客服ID
|
|
|
|
isManager = true; |
|
|
|
console.log('检测到纯数字客服ID:', userId); |
|
|
|
} else if (userId.startsWith('user_')) { |
|
|
|
// 如果是用户ID格式,直接使用
|
|
|
|
realUserId = userId; |
|
|
|
console.log('检测到用户ID格式,直接使用:', realUserId); |
|
|
|
} else if (userId.includes('-')) { |
|
|
|
// 会话ID格式,尝试从原始数据中获取
|
|
|
|
console.warn('无法从会话ID中提取真实用户ID,使用原始会话ID:', userId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
console.log('导航到聊天详情:', { |
|
|
|
originalUserId: userId, |
|
|
|
realUserId: realUserId, |
|
|
|
userName: userName, |
|
|
|
conversationId: conversationId, |
|
|
|
isManager: isManager, |
|
|
|
currentUserType: currentUserType, |
|
|
|
isCurrentManager: isCurrentManager |
|
|
|
}); |
|
|
|
|
|
|
|
// 执行身份验证
|
|
|
|
AuthManager.authenticate(() => { |
|
|
|
@ -822,9 +884,9 @@ Page({ |
|
|
|
this.markAsRead(userId); |
|
|
|
} |
|
|
|
|
|
|
|
// 关键修复:在URL中同时传递userId和conversationId,确保正确打开会话
|
|
|
|
// 关键修复:在URL中同时传递realUserId和conversationId,确保正确打开会话
|
|
|
|
wx.navigateTo({ |
|
|
|
url: `/pages/chat-detail/index?userId=${userId}&userName=${encodeURIComponent(userName)}${conversationId ? `&conversationId=${conversationId}` : ''}` |
|
|
|
url: `/pages/chat-detail/index?userId=${realUserId}&userName=${encodeURIComponent(userName)}&conversationId=${conversationId}&isManager=${isManager}` |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|