diff --git a/pages/chat-detail/index.js b/pages/chat-detail/index.js index 8ec16c8..aeb7d80 100644 --- a/pages/chat-detail/index.js +++ b/pages/chat-detail/index.js @@ -14,19 +14,26 @@ Page({ }, onLoad: function (options) { - if (options.id) { + // 支持两种参数传递方式: + // 1. 从聊天列表页传递的 id 参数 + // 2. 从客服列表页传递的 userId、userName、phone 参数 + let chatId = options.id || options.userId; + let managerPhone = options.phone; + + if (chatId) { this.setData({ - chatId: options.id, - managerPhone: options.id // 直接将chatId作为managerPhone使用,因为聊天列表页传递的是manager_phone + chatId: chatId, + managerPhone: managerPhone || options.id // 如果没有直接传递phone,则使用chatId作为fallback }); - // 如果有传递name参数,直接使用该名称作为聊天标题 - if (options.name) { + // 如果有传递name或userName参数,使用该名称作为聊天标题 + let chatTitle = options.name || options.userName; + if (chatTitle) { this.setData({ - chatTitle: decodeURIComponent(options.name) + chatTitle: decodeURIComponent(chatTitle) }); } else { - // 如果没有传递name参数,加载聊天标题 + // 如果没有传递名称参数,加载聊天标题 this.loadChatTitle(); } }