refactor(im): 对齐文赫电竞消息系统(配对群ID+稳定监听)
This commit is contained in:
35
app.js
35
app.js
@@ -81,6 +81,8 @@ App({
|
|||||||
xshenfen: 1,
|
xshenfen: 1,
|
||||||
|
|
||||||
goEasyConfig: null,
|
goEasyConfig: null,
|
||||||
|
chatEnabled: false,
|
||||||
|
groupInfoMap: {},
|
||||||
kefuConfig: {
|
kefuConfig: {
|
||||||
link: '',
|
link: '',
|
||||||
enterpriseId: ''
|
enterpriseId: ''
|
||||||
@@ -152,6 +154,7 @@ App({
|
|||||||
pageState: {
|
pageState: {
|
||||||
currentPage: '',
|
currentPage: '',
|
||||||
isInChatPage: false,
|
isInChatPage: false,
|
||||||
|
isInGroupChat: false,
|
||||||
currentChatId: '',
|
currentChatId: '',
|
||||||
lastPageUpdate: 0
|
lastPageUpdate: 0
|
||||||
},
|
},
|
||||||
@@ -222,13 +225,11 @@ App({
|
|||||||
this.emitEvent('staffContextChanged', {});
|
this.emitEvent('staffContextChanged', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ⑤ 建立连接
|
// ⑤ 建立连接(文赫式:全局监听,不反复 disconnect)
|
||||||
const saved = this.getSavedConnection();
|
|
||||||
console.log('【启动】缓存身份:', saved ? saved.identityType : '无',
|
|
||||||
'userId:', saved ? saved.userId : '无');
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.startImWhenReady) this.startImWhenReady();
|
if (this.globalData.chatEnabled && this.ensureConnection) {
|
||||||
else if (this.ensureConnection) this.ensureConnection();
|
this.ensureConnection();
|
||||||
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
// ⑥ 获取远程配置
|
// ⑥ 获取远程配置
|
||||||
@@ -243,8 +244,9 @@ App({
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
this.initGoEasyWithConfig();
|
this.initGoEasyWithConfig();
|
||||||
this.initCurrentUser();
|
this.initCurrentUser();
|
||||||
if (this.startImWhenReady) this.startImWhenReady();
|
if (this.globalData.chatEnabled && this.ensureConnection) {
|
||||||
else if (this.connectForCurrentRole) this.connectForCurrentRole();
|
this.ensureConnection();
|
||||||
|
}
|
||||||
console.log('远程配置更新完成');
|
console.log('远程配置更新完成');
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
@@ -252,10 +254,20 @@ App({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 从后台切回前台时再次向后端校验 */
|
/** 从后台切回前台时再次向后端校验,并维持 IM 连接 */
|
||||||
async onShow() {
|
async onShow() {
|
||||||
if (!wx.getStorageSync('token')) return;
|
if (!wx.getStorageSync('token')) return;
|
||||||
await ensurePhoneAuth({ redirect: true });
|
await ensurePhoneAuth({ redirect: true });
|
||||||
|
if (this.globalData.chatEnabled && typeof this.ensureConnection === 'function') {
|
||||||
|
this.globalData.goEasyConnection.autoReconnect = true;
|
||||||
|
this.ensureConnection();
|
||||||
|
if (typeof this.syncConnectionStatus === 'function') {
|
||||||
|
setTimeout(() => this.syncConnectionStatus(), 800);
|
||||||
|
}
|
||||||
|
if (typeof this.loadConversations === 'function') {
|
||||||
|
setTimeout(() => this.loadConversations(), 300);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 连接管理方法
|
// 连接管理方法
|
||||||
@@ -397,9 +409,10 @@ App({
|
|||||||
modules: ['im', 'pubsub']
|
modules: ['im', 'pubsub']
|
||||||
});
|
});
|
||||||
wx.GoEasy = GoEasy;
|
wx.GoEasy = GoEasy;
|
||||||
|
this.globalData.chatEnabled = true;
|
||||||
console.log('GoEasy 初始化成功');
|
console.log('GoEasy 初始化成功');
|
||||||
if (this.startImWhenReady && wx.getStorageSync('uid')) {
|
if (this.ensureConnection && wx.getStorageSync('uid')) {
|
||||||
setTimeout(() => this.startImWhenReady(), 100);
|
setTimeout(() => this.ensureConnection(), 100);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('GoEasy 初始化失败:', error);
|
console.error('GoEasy 初始化失败:', error);
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ Page({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// ===== 联系老板(订单群 groupId = 订单号) =====
|
// ===== 联系老板/商家(配对群 group_Ds{打手}_Sj/Boss{对方}) =====
|
||||||
goToChatWithBoss() {
|
goToChatWithBoss() {
|
||||||
const uid = wx.getStorageSync('uid')
|
const uid = wx.getStorageSync('uid')
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
@@ -299,10 +299,17 @@ Page({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fadanPingtai = this.data.jibenShuju.fadanpingtai || 0
|
||||||
|
const partnerUid = fadanPingtai === 2
|
||||||
|
? (this.data.xiangxiShuju.shangjia_id || '')
|
||||||
|
: (this.data.xiangxiShuju.laoban_id || '')
|
||||||
|
|
||||||
connectionManager.connectToGroupChat({
|
connectionManager.connectToGroupChat({
|
||||||
identityType: 'dashou',
|
identityType: 'dashou',
|
||||||
userId: 'Ds' + uid,
|
userId: 'Ds' + uid,
|
||||||
orderId: orderId,
|
orderId: orderId,
|
||||||
|
partnerUid,
|
||||||
|
fadanPingtai,
|
||||||
groupName: (this.data.jibenShuju.nicheng || '订单') + '的订单群',
|
groupName: (this.data.jibenShuju.nicheng || '订单') + '的订单群',
|
||||||
isCross: this.data.jibenShuju.fadanpingtai || 0,
|
isCross: this.data.jibenShuju.fadanpingtai || 0,
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
|||||||
@@ -350,6 +350,8 @@ Page({
|
|||||||
identityType: 'shangjia',
|
identityType: 'shangjia',
|
||||||
userId: 'Sj' + uid,
|
userId: 'Sj' + uid,
|
||||||
orderId: orderId,
|
orderId: orderId,
|
||||||
|
partnerUid: dashouUid,
|
||||||
|
fadanPingtai: this.data.jibenShuju.fadanpingtai || 0,
|
||||||
groupName,
|
groupName,
|
||||||
isCross,
|
isCross,
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
const app = getApp();
|
const app = getApp();
|
||||||
import { formatDate } from '../../static/lib/utils';
|
import { formatDate } from '../../static/lib/utils';
|
||||||
import { resolveAvatarUrl, getDefaultAvatarUrl, resolveAvatarFromStorage } from '../../utils/avatar.js';
|
import { resolveAvatarUrl, getDefaultAvatarUrl, resolveAvatarFromStorage } from '../../utils/avatar.js';
|
||||||
import { getLocalImUserId } from '../../utils/im-user.js';
|
import { getLocalImUserId, getLocalImIdentity, getImUserIdForRole, loadGroupMetaCache, getDefaultAvatar } from '../../utils/im-user.js';
|
||||||
import { normalizeConversationsList } from '../../utils/conversation-display.js';
|
import { enrichGroupConversation, isOrderGroupConversation, sortConversations, recordConversationOpen } from '../../utils/group-chat.js';
|
||||||
import { reconnectForRole } from '../../utils/role-tab-bar.js';
|
import { reconnectForRole } from '../../utils/role-tab-bar.js';
|
||||||
import { getPrimaryRole } from '../../utils/primary-role.js';
|
import { getPrimaryRole } from '../../utils/primary-role.js';
|
||||||
|
import { isStaffMode } from '../../utils/staff-api.js';
|
||||||
import { createPage } from '../../utils/base-page.js';
|
import { createPage } from '../../utils/base-page.js';
|
||||||
const { jianquanxian } = require('../../utils/imAuth/jianquanxian');
|
const { jianquanxian } = require('../../utils/imAuth/jianquanxian');
|
||||||
|
|
||||||
@@ -30,18 +31,51 @@ Page(createPage({
|
|||||||
this.calculateScrollHeight();
|
this.calculateScrollHeight();
|
||||||
const muted = wx.getStorageSync('notificationMuted') || false;
|
const muted = wx.getStorageSync('notificationMuted') || false;
|
||||||
this.setData({ notificationMuted: muted });
|
this.setData({ notificationMuted: muted });
|
||||||
|
if (app.globalData.messageManager) {
|
||||||
|
app.globalData.messageManager.notificationMuted = muted;
|
||||||
|
}
|
||||||
|
loadGroupMetaCache(app);
|
||||||
|
this._onGlobalConvUpdated = (content) => {
|
||||||
|
if (content && content.conversations) {
|
||||||
|
this.renderConversations(content);
|
||||||
|
} else if (app.loadConversations) {
|
||||||
|
app.loadConversations();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
app.on('conversationsUpdated', this._onGlobalConvUpdated);
|
||||||
|
},
|
||||||
|
|
||||||
|
onUnload() {
|
||||||
|
if (this._onGlobalConvUpdated) {
|
||||||
|
app.off('conversationsUpdated', this._onGlobalConvUpdated);
|
||||||
|
}
|
||||||
|
if (this.conversationsUpdatedListener && wx.goEasy?.im) {
|
||||||
|
wx.goEasy.im.off(wx.GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, this.conversationsUpdatedListener);
|
||||||
|
this.conversationsUpdatedListener = null;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
if (!this.checkLoginStatus()) return;
|
if (!this.checkLoginStatus()) return;
|
||||||
|
loadGroupMetaCache(app);
|
||||||
this.registerNotificationComponent();
|
this.registerNotificationComponent();
|
||||||
|
if (app.globalData.messageManager?.unreadTotal != null && app.emitEvent) {
|
||||||
|
app.emitEvent('tabBarBadgeChanged', {
|
||||||
|
badgeText: app.globalData.messageManager.unreadTotal > 0
|
||||||
|
? String(app.globalData.messageManager.unreadTotal) : '',
|
||||||
|
});
|
||||||
|
}
|
||||||
this.checkPermissionAndAutoConnect();
|
this.checkPermissionAndAutoConnect();
|
||||||
|
if (app.ensureConnection) app.ensureConnection();
|
||||||
|
this.setupConversationListener();
|
||||||
|
setTimeout(() => {
|
||||||
|
if (app.loadConversations) app.loadConversations();
|
||||||
|
else if (wx.goEasy?.im) this.loadConversations();
|
||||||
|
}, 200);
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide() {},
|
onHide() {},
|
||||||
|
|
||||||
onUnload() {},
|
|
||||||
|
|
||||||
// ========== ==== ================ ==== ================ 鉴权检查 ==========
|
// ========== ==== ================ ==== ================ 鉴权检查 ==========
|
||||||
async checkPermissionAndAutoConnect() {
|
async checkPermissionAndAutoConnect() {
|
||||||
const seq = ++this._permissionSeq;
|
const seq = ++this._permissionSeq;
|
||||||
@@ -90,26 +124,40 @@ Page(createPage({
|
|||||||
},
|
},
|
||||||
|
|
||||||
autoConnect() {
|
autoConnect() {
|
||||||
const targetUserId = getLocalImUserId(app);
|
const role = isStaffMode() ? 'shangjia' : (getLocalImIdentity(app) || app.globalData.currentRole || 'normal');
|
||||||
|
const uid = wx.getStorageSync('uid');
|
||||||
|
const targetUserId = getImUserIdForRole(role, uid);
|
||||||
if (!targetUserId) return;
|
if (!targetUserId) return;
|
||||||
|
|
||||||
if (app.ensureConnection) app.ensureConnection();
|
const onReady = () => {
|
||||||
reconnectForRole(getPrimaryRole(app));
|
this.setupConversationListener();
|
||||||
|
if (app.loadConversations) app.loadConversations();
|
||||||
|
else this.loadConversations();
|
||||||
|
};
|
||||||
|
|
||||||
const status = wx.goEasy.getConnectionStatus ? wx.goEasy.getConnectionStatus() : 'disconnected';
|
const status = wx.goEasy?.getConnectionStatus?.() || 'disconnected';
|
||||||
if (status === 'connected' || status === 'reconnected') {
|
const currentUserId = wx.goEasy?.im?.userId;
|
||||||
const currentUserId = wx.goEasy.im ? wx.goEasy.im.userId : null;
|
if ((status === 'connected' || status === 'reconnected') && currentUserId === targetUserId) {
|
||||||
if (currentUserId === targetUserId) {
|
onReady();
|
||||||
this.setupConversationListener();
|
return;
|
||||||
this.loadConversations();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
wx.goEasy.disconnect();
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connectGoEasy(targetUserId);
|
const tryConnect = async () => {
|
||||||
|
try {
|
||||||
|
if (app.ensureImForRole) {
|
||||||
|
await app.ensureImForRole(role);
|
||||||
|
} else if (app.connectWithIdentity) {
|
||||||
|
await app.connectWithIdentity(role, targetUserId, true);
|
||||||
|
} else if (app.ensureConnection) {
|
||||||
|
app.ensureConnection();
|
||||||
|
}
|
||||||
|
onReady();
|
||||||
|
} catch (e) {
|
||||||
|
const s = wx.goEasy?.getConnectionStatus?.();
|
||||||
|
if (s === 'connected' || s === 'reconnected') onReady();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tryConnect();
|
||||||
},
|
},
|
||||||
|
|
||||||
connectGoEasy(userId) {
|
connectGoEasy(userId) {
|
||||||
@@ -178,7 +226,21 @@ Page(createPage({
|
|||||||
this.setData({ allConversations: [] }, () => this.applyFilter());
|
this.setData({ allConversations: [] }, () => this.applyFilter());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let list = normalizeConversationsList(conversations, app, this._peerProfileCache);
|
const myGoEasyId = wx.goEasy?.im?.userId || getLocalImUserId(app);
|
||||||
|
const defaultAvatar = getDefaultAvatar(app);
|
||||||
|
const ossBase = app.globalData.ossImageUrl || '';
|
||||||
|
|
||||||
|
let list = conversations.map((item) => {
|
||||||
|
if (item.type === 'group') {
|
||||||
|
return enrichGroupConversation(item, myGoEasyId, defaultAvatar, ossBase);
|
||||||
|
}
|
||||||
|
if (!item.data) item.data = {};
|
||||||
|
if (item.data.avatar) {
|
||||||
|
item.data.avatar = resolveAvatarUrl(item.data.avatar, app);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
|
||||||
list.forEach(item => {
|
list.forEach(item => {
|
||||||
if (!item.lastMessage) {
|
if (!item.lastMessage) {
|
||||||
item.lastMessage = { type: 'text', payload: { text: '' }, timestamp: 0 };
|
item.lastMessage = { type: 'text', payload: { text: '' }, timestamp: 0 };
|
||||||
@@ -186,17 +248,13 @@ Page(createPage({
|
|||||||
if (item.lastMessage.timestamp) {
|
if (item.lastMessage.timestamp) {
|
||||||
item.lastMessage.date = formatDate(item.lastMessage.timestamp);
|
item.lastMessage.date = formatDate(item.lastMessage.timestamp);
|
||||||
}
|
}
|
||||||
|
if (item.type === 'group' && item.displayLastMsg) {
|
||||||
|
item.lastMessage.preview = item.displayLastMsg;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
list.sort((a, b) => {
|
const openTimes = wx.getStorageSync('conversationOpenTimes') || {};
|
||||||
if (a.top && !b.top) return -1;
|
list = sortConversations(list, openTimes);
|
||||||
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;
|
|
||||||
const ta = (a.lastMessage && a.lastMessage.timestamp) || 0;
|
|
||||||
const tb = (b.lastMessage && b.lastMessage.timestamp) || 0;
|
|
||||||
return tb - ta;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setData({ allConversations: list, displayCount: 10 }, () => {
|
this.setData({ allConversations: list, displayCount: 10 }, () => {
|
||||||
this.applyFilter();
|
this.applyFilter();
|
||||||
@@ -244,7 +302,7 @@ Page(createPage({
|
|||||||
const { allConversations, activeTab, searchKeyword } = this.data;
|
const { allConversations, activeTab, searchKeyword } = this.data;
|
||||||
let filtered = [];
|
let filtered = [];
|
||||||
if (activeTab === 0) {
|
if (activeTab === 0) {
|
||||||
filtered = allConversations.filter(c => c.type === 'group' && c.data && c.data.orderId);
|
filtered = allConversations.filter(c => isOrderGroupConversation(c));
|
||||||
} else if (activeTab === 1) {
|
} else if (activeTab === 1) {
|
||||||
filtered = allConversations.filter(c => c.type === 'private');
|
filtered = allConversations.filter(c => c.type === 'private');
|
||||||
} else if (activeTab === 2) {
|
} else if (activeTab === 2) {
|
||||||
@@ -263,7 +321,7 @@ Page(createPage({
|
|||||||
|
|
||||||
const tabUnread = [0, 0, 0];
|
const tabUnread = [0, 0, 0];
|
||||||
allConversations.forEach(c => {
|
allConversations.forEach(c => {
|
||||||
if (c.type === 'group' && c.data && c.data.orderId) tabUnread[0] += c.unread || 0;
|
if (isOrderGroupConversation(c)) tabUnread[0] += c.unread || 0;
|
||||||
else if (c.type === 'private') tabUnread[1] += c.unread || 0;
|
else if (c.type === 'private') tabUnread[1] += c.unread || 0;
|
||||||
else if (c.type === 'cs') tabUnread[2] += c.unread || 0;
|
else if (c.type === 'cs') tabUnread[2] += c.unread || 0;
|
||||||
});
|
});
|
||||||
@@ -294,6 +352,7 @@ Page(createPage({
|
|||||||
chat(e) {
|
chat(e) {
|
||||||
const conversation = e.currentTarget.dataset.conversation;
|
const conversation = e.currentTarget.dataset.conversation;
|
||||||
if (!conversation) return;
|
if (!conversation) return;
|
||||||
|
recordConversationOpen(conversation);
|
||||||
|
|
||||||
if (conversation.type === 'private') {
|
if (conversation.type === 'private') {
|
||||||
const param = {
|
const param = {
|
||||||
@@ -303,12 +362,16 @@ Page(createPage({
|
|||||||
};
|
};
|
||||||
wx.navigateTo({ url: '/pages/chat/chat?data=' + encodeURIComponent(JSON.stringify(param)) });
|
wx.navigateTo({ url: '/pages/chat/chat?data=' + encodeURIComponent(JSON.stringify(param)) });
|
||||||
} else if (conversation.type === 'group') {
|
} else if (conversation.type === 'group') {
|
||||||
|
const d = conversation.data || {};
|
||||||
const param = {
|
const param = {
|
||||||
groupId: conversation.groupId,
|
groupId: conversation.groupId,
|
||||||
orderId: conversation.data.orderId || '',
|
orderId: d.orderId || '',
|
||||||
groupName: conversation.data.name,
|
groupName: d.name || '订单群聊',
|
||||||
groupAvatar: conversation.data.avatar,
|
groupAvatar: d.avatar,
|
||||||
isCross: conversation.data.isCross || 0
|
isCross: d.isCross || 0,
|
||||||
|
orderZhuangtai: d.orderZhuangtai,
|
||||||
|
orderJine: d.orderJine,
|
||||||
|
orderDesc: d.orderDesc || d.orderJieshao || '',
|
||||||
};
|
};
|
||||||
wx.navigateTo({ url: '/pages/group-chat/group-chat?data=' + encodeURIComponent(JSON.stringify(param)) });
|
wx.navigateTo({ url: '/pages/group-chat/group-chat?data=' + encodeURIComponent(JSON.stringify(param)) });
|
||||||
} else if (conversation.type === 'cs') {
|
} else if (conversation.type === 'cs') {
|
||||||
|
|||||||
@@ -211,6 +211,8 @@ Page({
|
|||||||
identityType: 'normal',
|
identityType: 'normal',
|
||||||
userId: 'Boss' + uid,
|
userId: 'Boss' + uid,
|
||||||
orderId: dingdanId,
|
orderId: dingdanId,
|
||||||
|
partnerUid: this.data.xiangxiShuju.dashou || '',
|
||||||
|
fadanPingtai: this.data.jibenShuju.fadanpingtai || 0,
|
||||||
groupName: this.data.jibenShuju.nicheng + '的订单群',
|
groupName: this.data.jibenShuju.nicheng + '的订单群',
|
||||||
isCross: 0
|
isCross: 0
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import GoEasy from '../static/lib/goeasy-2.13.24.esm.min';
|
import GoEasy from '../static/lib/goeasy-2.13.24.esm.min';
|
||||||
import { jianquanxian } from './imAuth/jianquanxian';
|
import { jianquanxian } from './imAuth/jianquanxian';
|
||||||
import { parseOrderCardText } from './group-chat.js';
|
import { parseOrderCardText } from './group-chat.js';
|
||||||
import { persistGroupMeta, getFreshImUser, getImUserIdForRole } from './im-user.js';
|
import { persistGroupMeta, getFreshImUser, getImUserIdForRole, getLocalImUserId, getLocalImIdentity } from './im-user.js';
|
||||||
|
|
||||||
let _globalPrivateHandler = null;
|
let _globalPrivateHandler = null;
|
||||||
let _globalGroupHandler = null;
|
let _globalGroupHandler = null;
|
||||||
@@ -82,9 +82,11 @@ function getCurrentGoEasyUserId() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getExpectedImUserId(app) {
|
function getExpectedImUserId(app) {
|
||||||
|
const fromLocal = getLocalImUserId(app);
|
||||||
|
if (fromLocal) return fromLocal;
|
||||||
const uid = wx.getStorageSync('uid');
|
const uid = wx.getStorageSync('uid');
|
||||||
if (!uid) return '';
|
if (!uid) return '';
|
||||||
const role = app.globalData.currentRole || 'normal';
|
const role = app.globalData.currentRole || getLocalImIdentity(app) || 'normal';
|
||||||
return getImUserIdForRole(role, uid);
|
return getImUserIdForRole(role, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { getPrimaryRole } from './primary-role.js';
|
import { getPrimaryRole } from './primary-role.js';
|
||||||
import { resolveAvatarUrl } from './avatar.js';
|
import { resolveAvatarUrl } from './avatar.js';
|
||||||
import { ensureRoleOnCenterPage } from './role-tab-bar.js';
|
import { ensureRoleOnCenterPage } from './role-tab-bar.js';
|
||||||
|
import { isStaffMode } from './staff-api.js';
|
||||||
|
|
||||||
/** 联系对象前缀:管事/组长/考核官已废弃独立前缀,统一 Ds */
|
/** 联系对象前缀:管事/组长/考核官已废弃独立前缀,统一 Ds */
|
||||||
const PEER_PREFIX = {
|
const PEER_PREFIX = {
|
||||||
@@ -14,15 +15,37 @@ const PEER_PREFIX = {
|
|||||||
kaoheguan: 'Ds',
|
kaoheguan: 'Ds',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const IM_ROLE_PREFIX = {
|
||||||
|
normal: 'Boss',
|
||||||
|
dashou: 'Ds',
|
||||||
|
shangjia: 'Sj',
|
||||||
|
guanshi: 'Ds',
|
||||||
|
zuzhang: 'Ds',
|
||||||
|
kaoheguan: 'Ds',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getDefaultAvatar(app) {
|
||||||
|
const oss = app.globalData.ossImageUrl || '';
|
||||||
|
return oss + (app.globalData.morentouxiang || '');
|
||||||
|
}
|
||||||
|
|
||||||
export function getImPrefixForRole(role) {
|
export function getImPrefixForRole(role) {
|
||||||
|
if (isStaffMode()) return 'Sj';
|
||||||
return PEER_PREFIX[role] || 'Ds';
|
return PEER_PREFIX[role] || 'Ds';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 当前端连接 GoEasy 用的 userId */
|
export function getImUserIdForRole(role, uid) {
|
||||||
|
if (!uid) return '';
|
||||||
|
const prefix = getImPrefixForRole(role);
|
||||||
|
return prefix + uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 当前端连接 GoEasy 用的 userId(子客服仍用 Sj) */
|
||||||
export function getLocalImUserId(app) {
|
export function getLocalImUserId(app) {
|
||||||
app = app || getApp();
|
app = app || getApp();
|
||||||
const uid = wx.getStorageSync('uid') || '';
|
const uid = wx.getStorageSync('uid') || '';
|
||||||
if (!uid) return '';
|
if (!uid) return '';
|
||||||
|
if (isStaffMode()) return 'Sj' + uid;
|
||||||
const primary = getPrimaryRole(app);
|
const primary = getPrimaryRole(app);
|
||||||
if (primary === 'dashou') return 'Ds' + uid;
|
if (primary === 'dashou') return 'Ds' + uid;
|
||||||
if (primary === 'shangjia') return 'Sj' + uid;
|
if (primary === 'shangjia') return 'Sj' + uid;
|
||||||
@@ -31,15 +54,43 @@ export function getLocalImUserId(app) {
|
|||||||
|
|
||||||
export function getLocalImIdentity(app) {
|
export function getLocalImIdentity(app) {
|
||||||
app = app || getApp();
|
app = app || getApp();
|
||||||
|
if (isStaffMode()) return 'shangjia';
|
||||||
return getPrimaryRole(app) || 'normal';
|
return getPrimaryRole(app) || 'normal';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFreshImUser(app, role, uid) {
|
||||||
|
const effectiveRole = isStaffMode() ? 'shangjia' : role;
|
||||||
|
const id = getImUserIdForRole(effectiveRole, uid);
|
||||||
|
const touxiang = wx.getStorageSync('touxiang') || '';
|
||||||
|
const avatar = resolveAvatarUrl(touxiang, app);
|
||||||
|
const name = app.globalData.currentUser?.name || `用户${(uid || '').slice(-6)}`;
|
||||||
|
return { id, name, avatar };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function persistGroupMeta(app, groupId, meta) {
|
||||||
|
if (!groupId || !meta) return;
|
||||||
|
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||||
|
app.globalData.groupInfoMap[groupId] = { ...app.globalData.groupInfoMap[groupId], ...meta };
|
||||||
|
try {
|
||||||
|
const cache = wx.getStorageSync('pairGroupMetaCache') || {};
|
||||||
|
cache[groupId] = app.globalData.groupInfoMap[groupId];
|
||||||
|
wx.setStorageSync('pairGroupMetaCache', cache);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadGroupMetaCache(app) {
|
||||||
|
try {
|
||||||
|
const cache = wx.getStorageSync('pairGroupMetaCache') || {};
|
||||||
|
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||||
|
Object.assign(app.globalData.groupInfoMap, cache);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
export function buildPeerImUserId(uid, role = 'dashou') {
|
export function buildPeerImUserId(uid, role = 'dashou') {
|
||||||
if (!uid) return '';
|
if (!uid) return '';
|
||||||
return getImPrefixForRole(role) + uid;
|
return getImPrefixForRole(role) + uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 联系邀请人/管事/组长:统一 Ds 前缀 */
|
|
||||||
export function buildGuanshiPeerId(uid) {
|
export function buildGuanshiPeerId(uid) {
|
||||||
return buildDashouPeerId(uid);
|
return buildDashouPeerId(uid);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user