From 4e7b17a76c2bd67b6c9e409d99b3c479c9337d8e 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: Fri, 19 Dec 2025 17:03:22 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E8=88=AA=E9=97=AE?=
=?UTF-8?q?=E9=A2=98=EF=BC=8C=E5=AE=8C=E5=96=84=E8=81=8A=E5=A4=A9=E5=88=97?=
=?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=9B=B4=E6=96=B0=E8=81=8A?=
=?UTF-8?q?=E5=A4=A9=E8=AF=A6=E6=83=85=E9=A1=B5=E6=A0=87=E9=A2=98=E6=98=BE?=
=?UTF-8?q?=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/chat-detail/index.js | 69 +++++++++++++++++++++-
pages/chat-detail/index.wxml | 2 +-
pages/chat-detail/index.wxss | 3 +-
pages/chat/index.js | 65 +++++++++++++++++----
server-example/server-mysql.js | 102 +++++++++++++++++++++++++++++++++
5 files changed, 228 insertions(+), 13 deletions(-)
diff --git a/pages/chat-detail/index.js b/pages/chat-detail/index.js
index 29bad04..00009c8 100644
--- a/pages/chat-detail/index.js
+++ b/pages/chat-detail/index.js
@@ -1,10 +1,14 @@
// pages/chat-detail/index.js
+const API = require('../../utils/api.js');
+
Page({
data: {
chatId: null,
messages: [],
inputValue: '',
- loading: false
+ loading: false,
+ chatTitle: '聊天对象',
+ managerPhone: null
},
onLoad: function (options) {
@@ -12,10 +16,73 @@ Page({
this.setData({
chatId: options.id
});
+ // 获取聊天标题
+ this.loadChatTitle();
}
this.loadMessages();
},
+ // 加载聊天标题
+ loadChatTitle: function () {
+ // 从本地存储获取聊天列表
+ const users = wx.getStorageSync('users') || {};
+ const userId = wx.getStorageSync('userId');
+ let userPhone = null;
+
+ // 尝试从users中获取手机号
+ if (userId && users[userId]) {
+ if (users[userId].phoneNumber) {
+ userPhone = users[userId].phoneNumber;
+ } else if (users[userId].phone) {
+ userPhone = users[userId].phone;
+ }
+ }
+
+ // 如果还没有获取到,尝试从全局用户信息获取
+ if (!userPhone) {
+ const userInfo = wx.getStorageSync('userInfo');
+ if (userInfo) {
+ if (userInfo.phoneNumber) {
+ userPhone = userInfo.phoneNumber;
+ } else if (userInfo.phone) {
+ userPhone = userInfo.phone;
+ }
+ }
+ }
+
+ // 如果还没有获取到,尝试从直接存储获取
+ if (!userPhone) {
+ if (wx.getStorageSync('phoneNumber')) {
+ userPhone = wx.getStorageSync('phoneNumber');
+ } else if (wx.getStorageSync('phone')) {
+ userPhone = wx.getStorageSync('phone');
+ }
+ }
+
+ if (userPhone) {
+ // 获取聊天列表
+ API.getChatList(userPhone).then(chatList => {
+ if (Array.isArray(chatList)) {
+ // 找到当前聊天项
+ const currentChat = chatList.find(item => item.id === this.data.chatId);
+ if (currentChat && currentChat.manager_phone) {
+ this.setData({ managerPhone: currentChat.manager_phone });
+ // 获取业务员信息
+ API.getSalesPersonnelInfo(currentChat.manager_phone).then(personnelInfo => {
+ if (personnelInfo && personnelInfo.alias) {
+ this.setData({ chatTitle: personnelInfo.alias });
+ }
+ }).catch(error => {
+ console.error('获取业务员信息失败:', error);
+ });
+ }
+ }
+ }).catch(error => {
+ console.error('获取聊天列表失败:', error);
+ });
+ }
+ },
+
onBack: function () {
wx.navigateBack();
},
diff --git a/pages/chat-detail/index.wxml b/pages/chat-detail/index.wxml
index 009a123..308ea8e 100644
--- a/pages/chat-detail/index.wxml
+++ b/pages/chat-detail/index.wxml
@@ -4,7 +4,7 @@
←