| | |
| | | </view> --> |
| | | </view> |
| | | <view class="message-info"> |
| | | <text class="message-time">{{ formatTime(message.send_time) }}</text> |
| | | <text class="message-time">{{ formatTime(message.send_time||message.create_time) }}</text> |
| | | </view> |
| | | </view> |
| | | </view> |
| | |
| | | |
| | | </view> |
| | | <view class="message-info"> |
| | | <text class="message-time">{{ formatTime(message.send_time) }}</text> |
| | | <text class="message-time">{{ formatTime(message.send_time||message.create_time) }}</text> |
| | | </view> |
| | | |
| | | </view> |
| | |
| | | if (!this.conversationId) { |
| | | // 初始化会话 |
| | | this.initConversation(); |
| | | }else{ |
| | | // 加载消息 |
| | | this.loadMessages(); |
| | | this.initWebSocket(); |
| | | } |
| | | // 加载消息 |
| | | this.loadMessages(); |
| | | |
| | | }, |
| | | onUnload() { |
| | | this.is_exit = true; |
| | |
| | | business_card_id: this.businessCardId |
| | | }, res => { |
| | | this.conversationId = res.data.conversation.conversation_id; |
| | | this.loadMessages(); |
| | | this.wsUrl = res.data.wsUrl; |
| | | // 初始化WebSocket连接 |
| | | this.initWebSocket(); |
| | |
| | | self.loadMore = false; |
| | | self.page++; |
| | | if (self.page == 2) { |
| | | console.log(res.data.heUser); |
| | | // 获取目标用户信息 |
| | | this.targetUser = res.data.heUser; |
| | | this.card = res.data.card; |
| | |
| | | let self = this; |
| | | if (!this.inputMessage.trim()) return; |
| | | const content = self.inputMessage.trim(); |
| | | console.log(content); |
| | | self.sendWebSocketMessage(content); |
| | | }, |
| | | |
| | |
| | | const currentUserId = this.currentUser.user_id; |
| | | |
| | | // 构建WebSocket连接URL - 使用名片聊天专用端口2349 |
| | | const wsUrl = `${this.wsUrl}:2349?user_id=${currentUserId}`; |
| | | const wsUrl = `${this.wsUrl}:2349?user_id=${currentUserId}&usertype=supplier `; |
| | | try { |
| | | // 创建WebSocket连接 |
| | | this.socketTask = uni.connectSocket({ |
| | |
| | | }); |
| | | console.log('所有未读消息已标记为已读'); |
| | | }, |
| | | |
| | | sendMessages(message){ |
| | | if(message==''){ |
| | | return |
| | | } |
| | | this._post('plus.business.chat.chat/sendMessage',{ |
| | | content:this.inputMessage, |
| | | conversation_id: this.conversationId, |
| | | business_card_id: this.businessCardId, |
| | | },res=>{ |
| | | // 添加消息到本地列表 |
| | | const localMessage = { |
| | | chat_id: Date.now(), |
| | | conversation_id: this.conversationId, |
| | | sender_id: this.currentUser.user_id, |
| | | content: this.inputMessage, |
| | | create_time: Math.floor(Date.now() / 1000), |
| | | send_time: (Date.now() / 1000), |
| | | is_read: false |
| | | }; |
| | | this.messages.push(localMessage); |
| | | this.inputMessage = ''; |
| | | }) |
| | | }, |
| | | // 发送WebSocket消息 |
| | | sendWebSocketMessage(message) { |
| | | let self = this; |
| | | if (!this.socketTask) { |
| | | self.initWebSocket(); |
| | | self.sendMessages(message); |
| | | // 等待连接建立后再发送消息 |
| | | setTimeout(() => { |
| | | self.sendWebSocketMessage(message); |
| | | self.sendWebSocketMessage(''); |
| | | }, 1000); |
| | | return; |
| | | } |
| | |
| | | user_id: this.currentUser.user_id, |
| | | to_user_id: this.targetUserId, |
| | | content: message, |
| | | conversation_id: this.conversationId, |
| | | business_card_id: this.businessCardId, |
| | | app_id: this.currentUser.grade.app_id |
| | | }; |
| | | |
| | |
| | | if (!this.isOnline) { |
| | | self.initWebSocket(); |
| | | // 等待连接建立后再发送消息 |
| | | self.sendMessages(message); |
| | | setTimeout(() => { |
| | | self.sendWebSocketMessage(message); |
| | | self.sendWebSocketMessage(''); |
| | | }, 1000); |
| | | return; |
| | | } |
| | | |
| | | if(message==''){ |
| | | return |
| | | } |
| | | try { |
| | | self.socketTask.send({ |
| | | data: JSON.stringify(wsMessage) |