同步聊天修复到根目录pages/utils(与副本工程结构一致)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
const app = getApp();
|
||||
import { formatDate } from '../../static/lib/utils';
|
||||
const { jianquanxian } = require('../../utils/imAuth/jianquanxian');
|
||||
import { enrichGroupConversation, isOrderGroupConversation } from '../../utils/group-chat.js';
|
||||
import { enrichGroupConversation, isOrderGroupConversation, sortConversations, recordConversationOpen } from '../../utils/group-chat.js';
|
||||
import { loadGroupMetaCache } from '../../utils/im-user.js';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -24,10 +25,33 @@ Page({
|
||||
this.calculateScrollHeight();
|
||||
const muted = wx.getStorageSync('notificationMuted') || false;
|
||||
this.setData({ notificationMuted: muted });
|
||||
loadGroupMetaCache(app);
|
||||
this._onGlobalConvUpdated = (result) => {
|
||||
const content = result?.content || result;
|
||||
if (content && content.conversations) {
|
||||
this.renderConversations(content);
|
||||
}
|
||||
};
|
||||
app.on('conversationsUpdated', this._onGlobalConvUpdated);
|
||||
app.on('unreadCountChanged', this._onGlobalConvUpdated);
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (this._onGlobalConvUpdated) {
|
||||
app.off('conversationsUpdated', this._onGlobalConvUpdated);
|
||||
app.off('unreadCountChanged', this._onGlobalConvUpdated);
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!this.checkLoginStatus()) return;
|
||||
loadGroupMetaCache(app);
|
||||
if (app.globalData.messageManager?.unreadTotal != null) {
|
||||
app.emitEvent('tabBarBadgeChanged', {
|
||||
badgeText: app.globalData.messageManager.unreadTotal > 0
|
||||
? String(app.globalData.messageManager.unreadTotal) : ''
|
||||
});
|
||||
}
|
||||
this.checkPermissionAndAutoConnect();
|
||||
},
|
||||
|
||||
@@ -194,11 +218,14 @@ Page({
|
||||
const meta = groupMeta[item.groupId];
|
||||
if (meta) {
|
||||
if (!item.data) item.data = {};
|
||||
if (meta.name) item.data.name = meta.name;
|
||||
if (meta.avatar) item.data.avatar = meta.avatar;
|
||||
if (meta.orderDesc) item.data.orderDesc = meta.orderDesc;
|
||||
if (meta.orderId) item.data.orderId = meta.orderId;
|
||||
if (meta.orderZhuangtai != null) item.data.orderZhuangtai = meta.orderZhuangtai;
|
||||
Object.assign(item.data, meta);
|
||||
}
|
||||
if (item.data && item.data.dashouGoEasyId) {
|
||||
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||
app.globalData.groupInfoMap[item.groupId] = {
|
||||
...app.globalData.groupInfoMap[item.groupId],
|
||||
...item.data,
|
||||
};
|
||||
}
|
||||
enrichGroupConversation(item, myGoEasyId, defaultAvatar, ossBase);
|
||||
} else if (item.data && item.data.avatar) {
|
||||
@@ -213,24 +240,23 @@ Page({
|
||||
}
|
||||
});
|
||||
|
||||
list.sort((a, b) => {
|
||||
if (a.top && !b.top) return -1;
|
||||
if (!a.top && b.top) return 1;
|
||||
if (a.unread > 0 && b.unread <= 0) return -1;
|
||||
if (a.unread <= 0 && b.unread > 0) return 1;
|
||||
return (b.lastMessage.timestamp || 0) - (a.lastMessage.timestamp || 0);
|
||||
});
|
||||
const openTimes = wx.getStorageSync('conversationOpenTimes') || {};
|
||||
sortConversations(list, openTimes);
|
||||
|
||||
const unreadTotal = content.unreadTotal !== undefined ? content.unreadTotal : list.reduce((sum, c) => sum + (c.unread || 0), 0);
|
||||
if (app.globalData.messageManager) {
|
||||
app.globalData.messageManager.unreadTotal = unreadTotal;
|
||||
}
|
||||
if (app && app.emitEvent) {
|
||||
app.emitEvent('tabBarBadgeChanged', { badgeText: unreadTotal > 0 ? String(unreadTotal) : '' });
|
||||
app.emitEvent('unreadCountChanged', { unreadTotal });
|
||||
}
|
||||
|
||||
this.setData({ allConversations: list, displayCount: 4 }, () => {
|
||||
this.applyFilter();
|
||||
});
|
||||
|
||||
const unreadTotal = content.unreadTotal !== undefined ? content.unreadTotal : list.reduce((sum, c) => sum + (c.unread || 0), 0);
|
||||
if (app && app.emitEvent) {
|
||||
app.emitEvent('tabBarBadgeChanged', { badgeText: unreadTotal > 0 ? String(unreadTotal) : '' });
|
||||
}
|
||||
|
||||
// ✅ 每次渲染会话后,无条件重新订阅所有群组,确保订阅关系始终有效
|
||||
// 群组订阅(不重复断开连接)
|
||||
this.subscribeGroupsIfNeeded(list);
|
||||
},
|
||||
|
||||
@@ -316,6 +342,7 @@ Page({
|
||||
chat(e) {
|
||||
const conversation = e.currentTarget.dataset.conversation;
|
||||
if (!conversation) return;
|
||||
recordConversationOpen(conversation);
|
||||
|
||||
if (conversation.type === 'private') {
|
||||
const param = {
|
||||
|
||||
@@ -37,6 +37,15 @@
|
||||
<text class="time">{{item.lastMessage.date}}</text>
|
||||
</view>
|
||||
<block wx:if="{{item.type === 'group'}}">
|
||||
<view class="user-meta-row" wx:if="{{item.data.counterpartYonghuid}}">
|
||||
<text class="user-meta">对方 {{item.data.counterpartYonghuid}} {{item.data.name}}</text>
|
||||
</view>
|
||||
<view class="user-meta-row" wx:if="{{item.data.dashouYonghuid}}">
|
||||
<text class="user-meta sub">打手 {{item.data.dashouYonghuid}} {{item.data.dashouNicheng}}</text>
|
||||
</view>
|
||||
<view class="user-meta-row" wx:if="{{item.data.partnerYonghuid}}">
|
||||
<text class="user-meta sub">{{item.data.partnerRoleLabel || '商家'}} {{item.data.partnerYonghuid}} {{item.data.partnerNicheng}}</text>
|
||||
</view>
|
||||
<view class="order-block" wx:if="{{item.data.orderId || item.data.orderDesc}}">
|
||||
<text class="order-id" wx:if="{{item.data.orderId}}">单号 {{item.data.orderId}}</text>
|
||||
<text class="order-desc" wx:if="{{item.data.orderDesc}}">{{item.data.orderDesc}}</text>
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
.top-line { display: flex; justify-content: space-between; margin-bottom: 8rpx; }
|
||||
.name { font-size: 30rpx; color: #1a1a1a; font-weight: 500; }
|
||||
.time { font-size: 22rpx; color: #999; flex-shrink: 0; margin-left: 12rpx; }
|
||||
.user-meta-row { margin-bottom: 4rpx; }
|
||||
.user-meta { font-size: 24rpx; color: #333; }
|
||||
.user-meta.sub { color: #666; font-size: 22rpx; }
|
||||
.order-block { background: #f7f8fa; border-radius: 12rpx; padding: 16rpx 18rpx; margin-bottom: 10rpx; }
|
||||
.order-id { display: block; font-size: 24rpx; color: #576b95; margin-bottom: 6rpx; }
|
||||
.order-desc { display: block; font-size: 26rpx; color: #333; line-height: 1.5; word-break: break-all; }
|
||||
|
||||
Reference in New Issue
Block a user