聊天:订单状态实时展示、图片收发修复、联系打手跳转优化
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -15,7 +15,8 @@ Page({
|
|||||||
nicheng: '',
|
nicheng: '',
|
||||||
beizhu: '',
|
beizhu: '',
|
||||||
zhuangtai: 0,
|
zhuangtai: 0,
|
||||||
fadanpingtai: 0
|
fadanpingtai: 0,
|
||||||
|
is_cross: 0
|
||||||
},
|
},
|
||||||
xiangxiShuju: {
|
xiangxiShuju: {
|
||||||
shangjia_id: '',
|
shangjia_id: '',
|
||||||
@@ -181,7 +182,8 @@ Page({
|
|||||||
'jibenShuju.zhuangtai': data.zhuangtai || 0,
|
'jibenShuju.zhuangtai': data.zhuangtai || 0,
|
||||||
'jibenShuju.beizhu': data.beizhu || '',
|
'jibenShuju.beizhu': data.beizhu || '',
|
||||||
'liuyan': data.dashou_liuyan || '',
|
'liuyan': data.dashou_liuyan || '',
|
||||||
'jibenShuju.fadanpingtai': data.fadanpingtai || 0
|
'jibenShuju.fadanpingtai': data.fadanpingtai || 0,
|
||||||
|
'jibenShuju.is_cross': data.is_cross || 0,
|
||||||
})
|
})
|
||||||
const currentStatus = data.zhuangtai || 0
|
const currentStatus = data.zhuangtai || 0
|
||||||
const showRefund = [4,5,6].includes(currentStatus)
|
const showRefund = [4,5,6].includes(currentStatus)
|
||||||
@@ -301,12 +303,19 @@ goToChatWithBoss() {
|
|||||||
const identityType = 'dashou'
|
const identityType = 'dashou'
|
||||||
const userId = 'Ds' + uid
|
const userId = 'Ds' + uid
|
||||||
|
|
||||||
|
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,
|
identityType,
|
||||||
userId,
|
userId,
|
||||||
orderId,
|
orderId,
|
||||||
|
partnerUid,
|
||||||
|
fadanPingtai,
|
||||||
groupName: this.data.jibenShuju.nicheng + '的订单群',
|
groupName: this.data.jibenShuju.nicheng + '的订单群',
|
||||||
isCross: this.data.jibenShuju.fadanpingtai || 0
|
isCross: this.data.jibenShuju.is_cross || 0
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('跳转群聊失败', err)
|
console.error('跳转群聊失败', err)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const app = getApp();
|
const app = getApp();
|
||||||
import { formatDate } from '../../static/lib/utils';
|
import { formatDate, normalizeChatMessage, getChatImageUrl } from '../../static/lib/utils';
|
||||||
|
import { showConfirmByScene } from '../../utils/scriptService.js';
|
||||||
|
import { sendGoEasyImage } from '../../utils/chatImageSend.js';
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
@@ -21,6 +23,7 @@ Page({
|
|||||||
lastTapMsgId: '',
|
lastTapMsgId: '',
|
||||||
emojiList: ['😀','😁','😂','🤣','😃','😄','😅','😆','😉','😊','😋','😎','😍','😘','😗','😙','😚','🙂','🤗','🤩','🤔','🤨','😐','😑','😶','🙄','😏','😣','😥','😮','🤐','😯','😪','😫','😴','😌','😛','😜','😝','🤤','😒','😓','😔','😕','🙃','🤑','😲','☹','🙁','😖','😞','😟','😤','😢','😭','😦','😧','😨','😩','🤯','😬','😰','😱','🥵','🥶','😳','🤪','😵','😡','😠','🤬','😷','🤒','🤕','🤢','🤮','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','👺','💀','👻','👽','🤖','💩','😺','😸','😹','😻','😼','😽','🙀','😿','😾'],
|
emojiList: ['😀','😁','😂','🤣','😃','😄','😅','😆','😉','😊','😋','😎','😍','😘','😗','😙','😚','🙂','🤗','🤩','🤔','🤨','😐','😑','😶','🙄','😏','😣','😥','😮','🤐','😯','😪','😫','😴','😌','😛','😜','😝','🤤','😒','😓','😔','😕','🙃','🤑','😲','☹','🙁','😖','😞','😟','😤','😢','😭','😦','😧','😨','😩','🤯','😬','😰','😱','🥵','🥶','😳','🤪','😵','😡','😠','🤬','😷','🤒','🤕','🤢','🤮','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','👺','💀','👻','👽','🤖','💩','😺','😸','😹','😻','😼','😽','🙀','😿','😾'],
|
||||||
pendingImage: '',
|
pendingImage: '',
|
||||||
|
pendingImageFile: null,
|
||||||
keyboardHeight: 0,
|
keyboardHeight: 0,
|
||||||
bottomSafeHeight: 10
|
bottomSafeHeight: 10
|
||||||
},
|
},
|
||||||
@@ -29,7 +32,10 @@ Page({
|
|||||||
if (options.data) {
|
if (options.data) {
|
||||||
try {
|
try {
|
||||||
const p = JSON.parse(decodeURIComponent(options.data));
|
const p = JSON.parse(decodeURIComponent(options.data));
|
||||||
this.setData({ toUserId: p.toUserId || '', toName: p.toName || '聊天', toAvatar: p.toAvatar || '' });
|
const toId = p.toUserId || (p.to && p.to.id) || '';
|
||||||
|
const toName = p.toName || (p.to && p.to.name) || '聊天';
|
||||||
|
const toAvatar = p.toAvatar || (p.to && p.to.avatar) || '';
|
||||||
|
this.setData({ toUserId: toId, toName, toAvatar });
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
wx.setNavigationBarTitle({ title: this.data.toName });
|
wx.setNavigationBarTitle({ title: this.data.toName });
|
||||||
@@ -37,10 +43,14 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
|
app.globalData.pageState.isInChatPage = true;
|
||||||
|
app.globalData.pageState.currentChatId = this.data.toUserId;
|
||||||
this.autoConnect();
|
this.autoConnect();
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide() {
|
onHide() {
|
||||||
|
app.globalData.pageState.isInChatPage = false;
|
||||||
|
app.globalData.pageState.currentChatId = '';
|
||||||
this.clearAllListeners();
|
this.clearAllListeners();
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -142,6 +152,7 @@ Page({
|
|||||||
let list = res.content || [];
|
let list = res.content || [];
|
||||||
list.sort((a, b) => a.timestamp - b.timestamp);
|
list.sort((a, b) => a.timestamp - b.timestamp);
|
||||||
list.forEach((m, idx) => {
|
list.forEach((m, idx) => {
|
||||||
|
normalizeChatMessage(m);
|
||||||
m.formattedTime = formatDate(m.timestamp);
|
m.formattedTime = formatDate(m.timestamp);
|
||||||
if (idx === 0) m.showTime = true;
|
if (idx === 0) m.showTime = true;
|
||||||
else m.showTime = (m.timestamp - list[idx-1].timestamp) / 60000 > 5;
|
else m.showTime = (m.timestamp - list[idx-1].timestamp) / 60000 > 5;
|
||||||
@@ -180,6 +191,7 @@ Page({
|
|||||||
if (this._msgHandler) wx.goEasy.im.off(wx.GoEasy.IM_EVENT.PRIVATE_MESSAGE_RECEIVED, this._msgHandler);
|
if (this._msgHandler) wx.goEasy.im.off(wx.GoEasy.IM_EVENT.PRIVATE_MESSAGE_RECEIVED, this._msgHandler);
|
||||||
this._msgHandler = (msg) => {
|
this._msgHandler = (msg) => {
|
||||||
if (msg.receiverId !== this.data.currentUser.id && msg.senderId !== this.data.toUserId) return;
|
if (msg.receiverId !== this.data.currentUser.id && msg.senderId !== this.data.toUserId) return;
|
||||||
|
normalizeChatMessage(msg);
|
||||||
msg.formattedTime = formatDate(msg.timestamp);
|
msg.formattedTime = formatDate(msg.timestamp);
|
||||||
if (msg.senderId === this.data.currentUser.id) {
|
if (msg.senderId === this.data.currentUser.id) {
|
||||||
msg.senderData = { name: this.data.currentUser.name, avatar: this.data.currentUser.avatar };
|
msg.senderData = { name: this.data.currentUser.name, avatar: this.data.currentUser.avatar };
|
||||||
@@ -237,16 +249,42 @@ Page({
|
|||||||
onInput(e) { this.setData({ inputText: e.detail.value }); },
|
onInput(e) { this.setData({ inputText: e.detail.value }); },
|
||||||
chooseImage() {
|
chooseImage() {
|
||||||
const that = this;
|
const that = this;
|
||||||
|
const onPick = (file) => {
|
||||||
|
if (!file) return;
|
||||||
|
const path = typeof file === 'string' ? file : (file.tempFilePath || file.path);
|
||||||
|
if (!path) return;
|
||||||
|
that.setData({
|
||||||
|
pendingImage: path,
|
||||||
|
pendingImageFile: typeof file === 'string' ? { tempFilePath: path, path } : file,
|
||||||
|
showPlusPanel: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (wx.chooseMedia) {
|
||||||
|
wx.chooseMedia({
|
||||||
|
count: 1,
|
||||||
|
mediaType: ['image'],
|
||||||
|
sourceType: ['album', 'camera'],
|
||||||
|
sizeType: ['compressed'],
|
||||||
|
success(res) { onPick(res.tempFiles[0]); }
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
wx.chooseImage({
|
wx.chooseImage({
|
||||||
count: 1, sizeType: ['compressed'], sourceType: ['album', 'camera'],
|
count: 1, sizeType: ['compressed'], sourceType: ['album', 'camera'],
|
||||||
success(res) { that.setData({ pendingImage: res.tempFilePaths[0] }); }
|
success(res) {
|
||||||
|
const p = res.tempFilePaths[0];
|
||||||
|
onPick(res.tempFiles && res.tempFiles[0] || { tempFilePath: p, path: p });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
clearPendingImage() { this.setData({ pendingImage: '' }); },
|
clearPendingImage() { this.setData({ pendingImage: '', pendingImageFile: null }); },
|
||||||
sendMessage() {
|
sendMessage() {
|
||||||
if (this.data.pendingImage) {
|
if (this.data.pendingImage) {
|
||||||
this.sendImageMsg(this.data.pendingImage);
|
const file = this.data.pendingImageFile || this.data.pendingImage;
|
||||||
this.setData({ pendingImage: '' });
|
showConfirmByScene('chat_image_confirm', () => {
|
||||||
|
this.sendImageMsg(file);
|
||||||
|
this.setData({ pendingImage: '', pendingImageFile: null });
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const text = this.data.inputText.trim();
|
const text = this.data.inputText.trim();
|
||||||
@@ -280,19 +318,40 @@ Page({
|
|||||||
sendImageMsg(file) {
|
sendImageMsg(file) {
|
||||||
const { currentUser, toUserId } = this.data;
|
const { currentUser, toUserId } = this.data;
|
||||||
if (!toUserId || !currentUser) return;
|
if (!toUserId || !currentUser) return;
|
||||||
|
const preview = typeof file === 'string' ? file : (file.tempFilePath || file.path);
|
||||||
const id = 'img-'+Date.now();
|
const id = 'img-'+Date.now();
|
||||||
const local = {
|
const local = {
|
||||||
messageId:id, type:'image', timestamp:Date.now(),
|
messageId:id, type:'image', timestamp:Date.now(),
|
||||||
senderId:currentUser.id, receiverId:toUserId,
|
senderId:currentUser.id, receiverId:toUserId,
|
||||||
payload:{url:file}, status:'sending', read:false,
|
senderData: { name: currentUser.name, avatar: currentUser.avatar },
|
||||||
|
payload:{url:preview}, imageUrl:preview, status:'sending', read:false,
|
||||||
formattedTime:formatDate(Date.now()), showTime:this.needShow(Date.now())
|
formattedTime:formatDate(Date.now()), showTime:this.needShow(Date.now())
|
||||||
};
|
};
|
||||||
this.setData({ messages: [...this.data.messages, local], scrollToView: 'msg-bottom' });
|
this.setData({ messages: [...this.data.messages, local], scrollToView: 'msg-bottom' });
|
||||||
const imgMsg = wx.goEasy.im.createImageMessage({
|
const to = { type: wx.GoEasy.IM_SCENE.PRIVATE, id: toUserId, data: { avatar: currentUser.avatar, name: currentUser.name } };
|
||||||
|
sendGoEasyImage({
|
||||||
file,
|
file,
|
||||||
to:{ type:wx.GoEasy.IM_SCENE.PRIVATE, id:toUserId, data:{ avatar:currentUser.avatar, name:currentUser.name } }
|
to,
|
||||||
|
onSuccess: (sentMsg) => this.onImageSendSuccess(id, sentMsg, preview),
|
||||||
|
onFailed: () => this.updateMsg(id, 'failed'),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onImageSendSuccess(localId, sentMsg, localFile) {
|
||||||
|
const normalized = normalizeChatMessage(sentMsg || {});
|
||||||
|
const url = getChatImageUrl(normalized) || localFile;
|
||||||
|
this.setData({
|
||||||
|
messages: this.data.messages.map(m => {
|
||||||
|
if (m.messageId !== localId) return m;
|
||||||
|
return {
|
||||||
|
...m,
|
||||||
|
...normalized,
|
||||||
|
messageId: normalized.messageId || m.messageId,
|
||||||
|
payload: { ...(m.payload || {}), url },
|
||||||
|
imageUrl: url,
|
||||||
|
status: 'success'
|
||||||
|
};
|
||||||
|
})
|
||||||
});
|
});
|
||||||
wx.goEasy.im.sendMessage({ message:imgMsg, onSuccess:()=>this.updateMsg(id,'success'), onFailed:()=>{ this.updateMsg(id,'failed'); } });
|
|
||||||
},
|
},
|
||||||
updateMsg(id, status) { this.setData({ messages: this.data.messages.map(m => m.messageId === id ? { ...m, status } : m) }); },
|
updateMsg(id, status) { this.setData({ messages: this.data.messages.map(m => m.messageId === id ? { ...m, status } : m) }); },
|
||||||
needShow(ts) { const ms = this.data.messages; if (!ms.length) return true; const last = ms[ms.length-1]; return (ts - last.timestamp) / 60000 > 5; },
|
needShow(ts) { const ms = this.data.messages; if (!ms.length) return true; const last = ms[ms.length-1]; return (ts - last.timestamp) / 60000 > 5; },
|
||||||
@@ -361,7 +420,15 @@ Page({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
previewImage(e) { wx.previewImage({ urls: [e.currentTarget.dataset.url], current: e.currentTarget.dataset.url }); },
|
previewImage(e) {
|
||||||
|
const url = e.currentTarget.dataset.url;
|
||||||
|
if (!url) return;
|
||||||
|
const urls = this.data.messages
|
||||||
|
.filter(m => m.type === 'image')
|
||||||
|
.map(m => m.imageUrl || getChatImageUrl(m))
|
||||||
|
.filter(Boolean);
|
||||||
|
wx.previewImage({ urls: urls.length ? urls : [url], current: url });
|
||||||
|
},
|
||||||
|
|
||||||
togglePlusPanel() { this.setData({ showPlusPanel: !this.data.showPlusPanel, showEmojiPanel: false }); },
|
togglePlusPanel() { this.setData({ showPlusPanel: !this.data.showPlusPanel, showEmojiPanel: false }); },
|
||||||
closePlusPanel() { this.setData({ showPlusPanel: false }); },
|
closePlusPanel() { this.setData({ showPlusPanel: false }); },
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ const app = getApp();
|
|||||||
import { formatDate } from '../../static/lib/utils';
|
import { formatDate } from '../../static/lib/utils';
|
||||||
import { sendGroupMessage } from '../../utils/message-sender';
|
import { sendGroupMessage } from '../../utils/message-sender';
|
||||||
import { showConfirmByScene } from '../../utils/scriptService.js';
|
import { showConfirmByScene } from '../../utils/scriptService.js';
|
||||||
import { normalizeGroupMessage } from '../../utils/group-chat.js';
|
import { normalizeGroupMessage, getZhuangtaiText } from '../../utils/group-chat.js';
|
||||||
|
import { persistGroupMeta } from '../../utils/im-user.js';
|
||||||
import { getFreshImUser } from '../../utils/im-user.js';
|
import { getFreshImUser } from '../../utils/im-user.js';
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -12,6 +13,10 @@ Page({
|
|||||||
groupAvatar: '',
|
groupAvatar: '',
|
||||||
orderId: '',
|
orderId: '',
|
||||||
isCross: 0,
|
isCross: 0,
|
||||||
|
orderZhuangtai: null,
|
||||||
|
orderZhuangtaiText: '',
|
||||||
|
orderJine: '',
|
||||||
|
orderJieshao: '',
|
||||||
currentUser: null,
|
currentUser: null,
|
||||||
messages: [],
|
messages: [],
|
||||||
inputText: '',
|
inputText: '',
|
||||||
@@ -61,33 +66,101 @@ Page({
|
|||||||
} else {
|
} else {
|
||||||
this.initCurrentUser();
|
this.initCurrentUser();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
const meta = (app.globalData.groupInfoMap && app.globalData.groupInfoMap[p.groupId]) || {};
|
||||||
/*onLoad(options) {
|
const initZt = p.orderZhuangtai != null ? p.orderZhuangtai : meta.orderZhuangtai;
|
||||||
if (options.data) {
|
if (initZt != null) {
|
||||||
try {
|
this.applyOrderStatus(initZt, {
|
||||||
const p = JSON.parse(decodeURIComponent(options.data));
|
orderId: p.orderId || meta.orderId,
|
||||||
this.setData({
|
jine: p.orderJine || meta.orderJine,
|
||||||
groupId: p.groupId || '',
|
jieshao: p.orderDesc || meta.orderDesc,
|
||||||
groupName: p.groupName || '订单群聊',
|
});
|
||||||
groupAvatar: p.groupAvatar || '',
|
|
||||||
orderId: p.orderId || '',
|
|
||||||
isCross: p.isCross || 0
|
|
||||||
});
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
wx.setNavigationBarTitle({ title: this.data.groupName });
|
},
|
||||||
this.initCurrentUser();
|
|
||||||
},*/
|
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
|
app.globalData.pageState.isInChatPage = true;
|
||||||
|
app.globalData.pageState.currentChatId = this.data.groupId;
|
||||||
|
app.globalData.pageState.isInGroupChat = true;
|
||||||
this.ensureChatConnection();
|
this.ensureChatConnection();
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide() {
|
onHide() {
|
||||||
|
app.globalData.pageState.isInChatPage = false;
|
||||||
|
app.globalData.pageState.currentChatId = '';
|
||||||
|
app.globalData.pageState.isInGroupChat = false;
|
||||||
this.clearPageListeners();
|
this.clearPageListeners();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
applyOrderStatus(zhuangtai, extra) {
|
||||||
|
if (zhuangtai == null && zhuangtai !== 0) return;
|
||||||
|
const patch = {
|
||||||
|
orderZhuangtai: zhuangtai,
|
||||||
|
orderZhuangtaiText: getZhuangtaiText(zhuangtai),
|
||||||
|
};
|
||||||
|
if (extra) {
|
||||||
|
if (extra.jine) patch.orderJine = extra.jine;
|
||||||
|
if (extra.jieshao) patch.orderJieshao = extra.jieshao;
|
||||||
|
if (extra.orderId) patch.orderId = extra.orderId;
|
||||||
|
}
|
||||||
|
this.setData(patch);
|
||||||
|
|
||||||
|
const groupId = this.data.groupId;
|
||||||
|
if (!groupId) return;
|
||||||
|
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||||
|
const meta = { ...(app.globalData.groupInfoMap[groupId] || {}), orderZhuangtai: zhuangtai };
|
||||||
|
if (extra && extra.orderId) meta.orderId = extra.orderId;
|
||||||
|
app.globalData.groupInfoMap[groupId] = meta;
|
||||||
|
persistGroupMeta(app, groupId, meta);
|
||||||
|
},
|
||||||
|
|
||||||
|
applyOrderCardPayload(payload) {
|
||||||
|
if (!payload) return;
|
||||||
|
const zt = payload.zhuangtai != null ? payload.zhuangtai : this.data.orderZhuangtai;
|
||||||
|
payload.zhuangtaiText = getZhuangtaiText(zt);
|
||||||
|
this.applyOrderStatus(zt, {
|
||||||
|
orderId: payload.orderId || payload.dingdan_id || this.data.orderId,
|
||||||
|
jine: payload.jine,
|
||||||
|
jieshao: payload.jieshao,
|
||||||
|
});
|
||||||
|
this.updateOrderBubblesInList(payload);
|
||||||
|
},
|
||||||
|
|
||||||
|
updateOrderBubblesInList(payload) {
|
||||||
|
if (!payload) return;
|
||||||
|
const orderId = payload.orderId || payload.dingdan_id;
|
||||||
|
if (!orderId) return;
|
||||||
|
const messages = this.data.messages.map((m) => {
|
||||||
|
if (m.type !== 'order' || !m.payload) return m;
|
||||||
|
const oid = m.payload.orderId || m.payload.dingdan_id;
|
||||||
|
if (oid !== orderId) return m;
|
||||||
|
return { ...m, payload: { ...m.payload, ...payload, orderId: oid } };
|
||||||
|
});
|
||||||
|
this.setData({ messages });
|
||||||
|
},
|
||||||
|
|
||||||
|
mergeServerMessage(localId, status, serverMsg) {
|
||||||
|
if (!serverMsg) {
|
||||||
|
this.updateMsg(localId, status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
normalizeGroupMessage(serverMsg);
|
||||||
|
serverMsg.formattedTime = formatDate(serverMsg.timestamp);
|
||||||
|
if (serverMsg.type === 'order') {
|
||||||
|
this.applyOrderCardPayload(serverMsg.payload);
|
||||||
|
}
|
||||||
|
const msgs = this.data.messages.map((m) => {
|
||||||
|
if (m.messageId !== localId) return m;
|
||||||
|
return {
|
||||||
|
...serverMsg,
|
||||||
|
showTime: m.showTime,
|
||||||
|
status: status || 'success',
|
||||||
|
formattedTime: serverMsg.formattedTime || m.formattedTime,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
this.setData({ messages: msgs });
|
||||||
|
},
|
||||||
|
|
||||||
ensureChatConnection() {
|
ensureChatConnection() {
|
||||||
const role = app.globalData.currentRole || 'normal';
|
const role = app.globalData.currentRole || 'normal';
|
||||||
const uid = wx.getStorageSync('uid');
|
const uid = wx.getStorageSync('uid');
|
||||||
@@ -100,10 +173,11 @@ Page({
|
|||||||
this.loadHistory(true).then(() => this.markGroupMessageAsRead());
|
this.loadHistory(true).then(() => this.markGroupMessageAsRead());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const connectedId = app.globalData?.goEasyConnection?.userId || wx.goEasy?.im?.userId;
|
||||||
const status = wx.goEasy?.getConnectionStatus?.() || 'disconnected';
|
const status = wx.goEasy?.getConnectionStatus?.() || 'disconnected';
|
||||||
const currentUserId = wx.goEasy?.im?.userId;
|
const imOk = status === 'connected' || status === 'reconnected';
|
||||||
|
|
||||||
if ((status === 'connected' || status === 'reconnected') && currentUserId === targetUserId) {
|
if (imOk && connectedId === targetUserId) {
|
||||||
onReady();
|
onReady();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -219,6 +293,9 @@ Page({
|
|||||||
if (idx === 0) m.showTime = true;
|
if (idx === 0) m.showTime = true;
|
||||||
else m.showTime = (m.timestamp - list[idx-1].timestamp) / 60000 > 5;
|
else m.showTime = (m.timestamp - list[idx-1].timestamp) / 60000 > 5;
|
||||||
if (!m.senderData) m.senderData = { name: '未知用户', avatar: '' };
|
if (!m.senderData) m.senderData = { name: '未知用户', avatar: '' };
|
||||||
|
if (m.type === 'order' && m.payload) {
|
||||||
|
this.applyOrderCardPayload(m.payload);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let final = refresh ? list : [...list, ...this.data.messages];
|
let final = refresh ? list : [...list, ...this.data.messages];
|
||||||
if (!refresh) {
|
if (!refresh) {
|
||||||
@@ -249,10 +326,14 @@ Page({
|
|||||||
if (this._msgHandler) wx.goEasy.im.off(wx.GoEasy.IM_EVENT.GROUP_MESSAGE_RECEIVED, this._msgHandler);
|
if (this._msgHandler) wx.goEasy.im.off(wx.GoEasy.IM_EVENT.GROUP_MESSAGE_RECEIVED, this._msgHandler);
|
||||||
this._msgHandler = (msg) => {
|
this._msgHandler = (msg) => {
|
||||||
if (msg.groupId !== this.data.groupId) return;
|
if (msg.groupId !== this.data.groupId) return;
|
||||||
if (msg.senderId === this.data.currentUser.id) return;
|
|
||||||
normalizeGroupMessage(msg);
|
normalizeGroupMessage(msg);
|
||||||
|
if (msg.type === 'order' && msg.payload) {
|
||||||
|
this.applyOrderCardPayload(msg.payload);
|
||||||
|
}
|
||||||
|
if (msg.senderId === this.data.currentUser.id && msg.type !== 'order') return;
|
||||||
msg.formattedTime = formatDate(msg.timestamp);
|
msg.formattedTime = formatDate(msg.timestamp);
|
||||||
const msgs = this.data.messages;
|
const msgs = this.data.messages;
|
||||||
|
if (msgs.some((m) => m.messageId === msg.messageId)) return;
|
||||||
const last = msgs.length ? msgs[msgs.length-1] : null;
|
const last = msgs.length ? msgs[msgs.length-1] : null;
|
||||||
msg.showTime = last ? (msg.timestamp - last.timestamp) / 60000 > 5 : true;
|
msg.showTime = last ? (msg.timestamp - last.timestamp) / 60000 > 5 : true;
|
||||||
this.setData({ messages: [...msgs, msg], scrollToView: 'msg-bottom' });
|
this.setData({ messages: [...msgs, msg], scrollToView: 'msg-bottom' });
|
||||||
@@ -339,8 +420,8 @@ Page({
|
|||||||
}
|
}
|
||||||
that.setData({ messages: [...msgs, localMsg], scrollToView: 'msg-bottom' });
|
that.setData({ messages: [...msgs, localMsg], scrollToView: 'msg-bottom' });
|
||||||
},
|
},
|
||||||
onSuccess: (messageId, status) => {
|
onSuccess: (messageId, status, serverMsg) => {
|
||||||
that.updateMsg(messageId, status);
|
that.mergeServerMessage(messageId, status, serverMsg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -367,8 +448,8 @@ Page({
|
|||||||
}
|
}
|
||||||
that.setData({ messages: [...msgs, localMsg], scrollToView: 'msg-bottom' });
|
that.setData({ messages: [...msgs, localMsg], scrollToView: 'msg-bottom' });
|
||||||
},
|
},
|
||||||
onSuccess: (messageId, status) => {
|
onSuccess: (messageId, status, serverMsg) => {
|
||||||
that.updateMsg(messageId, status);
|
that.mergeServerMessage(messageId, status, serverMsg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -403,7 +484,7 @@ Page({
|
|||||||
const msgId = e.currentTarget.dataset.messageid;
|
const msgId = e.currentTarget.dataset.messageid;
|
||||||
if (!msgId) return;
|
if (!msgId) return;
|
||||||
const msg = this.data.messages.find(m => m.messageId === msgId);
|
const msg = this.data.messages.find(m => m.messageId === msgId);
|
||||||
if (!msg || msg.messageId.startsWith('local-')) return;
|
if (!msg || String(msg.messageId).startsWith('local-')) return;
|
||||||
const itemList = ['复制'];
|
const itemList = ['复制'];
|
||||||
if (msg.senderId === this.data.currentUser.id && (Date.now() - msg.timestamp < 120000) && !msg.recalled) {
|
if (msg.senderId === this.data.currentUser.id && (Date.now() - msg.timestamp < 120000) && !msg.recalled) {
|
||||||
itemList.push('撤回');
|
itemList.push('撤回');
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
<view class="chat-page">
|
<view class="chat-page">
|
||||||
|
<view class="order-status-bar" wx:if="{{orderId}}">
|
||||||
|
<view class="order-status-main">
|
||||||
|
<text class="order-status-id">订单 {{orderId}}</text>
|
||||||
|
<text class="order-status-tag" wx:if="{{orderZhuangtaiText}}">{{orderZhuangtaiText}}</text>
|
||||||
|
</view>
|
||||||
|
<text class="order-status-desc" wx:if="{{orderJieshao}}">{{orderJieshao}}</text>
|
||||||
|
</view>
|
||||||
<scroll-view class="msg-list" scroll-y="true"
|
<scroll-view class="msg-list" scroll-y="true"
|
||||||
scroll-into-view="{{scrollToView}}"
|
scroll-into-view="{{scrollToView}}"
|
||||||
refresher-enabled="{{true}}"
|
refresher-enabled="{{true}}"
|
||||||
@@ -15,16 +22,16 @@
|
|||||||
<image class="avatar" src="{{item.senderData.avatar || '/images/default-avatar.png'}}" mode="aspectFill" />
|
<image class="avatar" src="{{item.senderData.avatar || '/images/default-avatar.png'}}" mode="aspectFill" />
|
||||||
<text class="sender-name">{{item.senderData.name || item.senderId}}</text>
|
<text class="sender-name">{{item.senderData.name || item.senderId}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="bubble {{item.senderId === currentUser.id ? 'bubble-right' : 'bubble-left'}}"
|
<view class="bubble {{item.senderId === currentUser.id ? 'bubble-right' : 'bubble-left'}} {{item.type === 'image' ? 'bubble-image' : ''}}"
|
||||||
data-messageid="{{item.messageId}}"
|
data-messageid="{{item.messageId}}"
|
||||||
data-text="{{item.type==='text' ? item.payload.text : ''}}"
|
data-text="{{item.type==='text' ? item.payload.text : ''}}"
|
||||||
bindtap="{{item.type==='text' ? 'onBubbleTap' : (item.type==='image' ? 'previewImage' : '')}}"
|
bindtap="{{item.type==='text' ? 'onBubbleTap' : ''}}">
|
||||||
data-url="{{item.type==='image' ? item.payload.url : ''}}">
|
|
||||||
<text wx:if="{{item.type === 'text'}}" class="msg-text">{{item.payload.text}}</text>
|
<text wx:if="{{item.type === 'text'}}" class="msg-text">{{item.payload.text}}</text>
|
||||||
<image wx:elif="{{item.type === 'image'}}" class="msg-image" src="{{item.payload.url}}" mode="widthFix" />
|
<image wx:elif="{{item.type === 'image'}}" class="msg-image" src="{{item.imageUrl || item.payload.url}}" mode="widthFix" catchtap="previewImage" data-url="{{item.imageUrl || item.payload.url}}" />
|
||||||
<view wx:elif="{{item.type === 'order'}}" class="order-bubble" data-payload="{{item.payload}}" bindtap="viewOrderDetail">
|
<view wx:elif="{{item.type === 'order'}}" class="order-bubble" data-payload="{{item.payload}}" bindtap="viewOrderDetail">
|
||||||
<text class="order-label">[订单]</text>
|
<text class="order-label">[订单]</text>
|
||||||
<text class="order-info">ID: {{item.payload.orderId}}</text>
|
<text class="order-info">ID: {{item.payload.orderId}}</text>
|
||||||
|
<text class="order-info order-status-inline" wx:if="{{item.payload.zhuangtaiText || item.payload.zhuangtai}}">状态: {{item.payload.zhuangtaiText || item.payload.zhuangtai}}</text>
|
||||||
<text class="order-info">内容: {{item.payload.jieshao}}</text>
|
<text class="order-info">内容: {{item.payload.jieshao}}</text>
|
||||||
<text class="order-info">金额: ¥{{item.payload.jine}}</text>
|
<text class="order-info">金额: ¥{{item.payload.jine}}</text>
|
||||||
<view class="order-detail-link">点击查看详情</view>
|
<view class="order-detail-link">点击查看详情</view>
|
||||||
|
|||||||
@@ -1,8 +1,29 @@
|
|||||||
.chat-page { width:100%; height:100vh; background:#f5f5f5; }
|
.chat-page { width:100%; height:100vh; background:#f5f5f5; }
|
||||||
|
|
||||||
|
.order-status-bar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0; left: 0; right: 0;
|
||||||
|
z-index: 11;
|
||||||
|
background: #fff;
|
||||||
|
padding: 16rpx 24rpx;
|
||||||
|
border-bottom: 1rpx solid #e8e8e8;
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.04);
|
||||||
|
}
|
||||||
|
.order-status-main { display: flex; align-items: center; justify-content: space-between; }
|
||||||
|
.order-status-id { font-size: 26rpx; color: #333; font-weight: 600; }
|
||||||
|
.order-status-tag {
|
||||||
|
font-size: 22rpx; color: #07c160; background: #e8f8ee;
|
||||||
|
padding: 4rpx 16rpx; border-radius: 20rpx;
|
||||||
|
}
|
||||||
|
.order-status-desc {
|
||||||
|
font-size: 24rpx; color: #888; margin-top: 8rpx;
|
||||||
|
display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.msg-list {
|
.msg-list {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left:0; right:0;
|
left:0; right:0;
|
||||||
|
top: 100rpx;
|
||||||
padding: 0 20rpx;
|
padding: 0 20rpx;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
@@ -18,12 +39,15 @@
|
|||||||
.bubble { max-width:70%; padding:16rpx 20rpx; border-radius:16rpx; position:relative; word-break:break-all; font-size:30rpx; line-height:1.5; }
|
.bubble { max-width:70%; padding:16rpx 20rpx; border-radius:16rpx; position:relative; word-break:break-all; font-size:30rpx; line-height:1.5; }
|
||||||
.bubble-left { background:#fff; border-top-left-radius:4rpx; }
|
.bubble-left { background:#fff; border-top-left-radius:4rpx; }
|
||||||
.bubble-right { background:#00aaff; color:#fff; border-top-right-radius:4rpx; }
|
.bubble-right { background:#00aaff; color:#fff; border-top-right-radius:4rpx; }
|
||||||
|
.bubble-image { padding:0; background:transparent !important; overflow:hidden; }
|
||||||
|
.bubble-image.bubble-right { color:inherit; }
|
||||||
.msg-text { color:inherit; }
|
.msg-text { color:inherit; }
|
||||||
.msg-image { max-width:240rpx; border-radius:10rpx; }
|
.msg-image { max-width:360rpx; min-width:120rpx; display:block; border-radius:10rpx; }
|
||||||
|
|
||||||
.order-bubble { background:#fff7e0; padding:12rpx; border-radius:8rpx; }
|
.order-bubble { background:#fff7e0; padding:12rpx; border-radius:8rpx; }
|
||||||
.order-label { font-size:24rpx; color:#e6a23c; font-weight:600; }
|
.order-label { font-size:24rpx; color:#e6a23c; font-weight:600; }
|
||||||
.order-info { font-size:24rpx; color:#333; margin:6rpx 0; }
|
.order-info { font-size:24rpx; color:#333; margin:6rpx 0; }
|
||||||
|
.order-status-inline { color: #07c160; font-weight: 600; }
|
||||||
.order-detail-link { color:#007aff; font-size:24rpx; margin-top:8rpx; }
|
.order-detail-link { color:#007aff; font-size:24rpx; margin-top:8rpx; }
|
||||||
|
|
||||||
.input-area {
|
.input-area {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Page({
|
|||||||
data: {
|
data: {
|
||||||
jibenShuju: {
|
jibenShuju: {
|
||||||
dingdan_id: '', tupian: '', jieshao: '', create_time: '',
|
dingdan_id: '', tupian: '', jieshao: '', create_time: '',
|
||||||
jine: '', nicheng: '', beizhu: '', zhuangtai: 0, fadanpingtai: 0
|
jine: '', nicheng: '', beizhu: '', zhuangtai: 0, fadanpingtai: 0, is_cross: 0
|
||||||
},
|
},
|
||||||
dashouInfo: { yonghuid: '', nicheng: '', avatar: '' },
|
dashouInfo: { yonghuid: '', nicheng: '', avatar: '' },
|
||||||
xiangxiShuju: {
|
xiangxiShuju: {
|
||||||
@@ -131,6 +131,7 @@ Page({
|
|||||||
'jibenShuju.beizhu': dingdanData.beizhu || '',
|
'jibenShuju.beizhu': dingdanData.beizhu || '',
|
||||||
'jibenShuju.zhuangtai': dingdanData.zhuangtai || 0,
|
'jibenShuju.zhuangtai': dingdanData.zhuangtai || 0,
|
||||||
'jibenShuju.fadanpingtai': dingdanData.fadanpingtai || 0,
|
'jibenShuju.fadanpingtai': dingdanData.fadanpingtai || 0,
|
||||||
|
'jibenShuju.is_cross': dingdanData.is_cross || 0,
|
||||||
isLoading: false
|
isLoading: false
|
||||||
})
|
})
|
||||||
this.jiazaiXiangxiShuju(dingdanData.dingdan_id)
|
this.jiazaiXiangxiShuju(dingdanData.dingdan_id)
|
||||||
@@ -186,7 +187,9 @@ Page({
|
|||||||
fadanData: d.fadan || null,
|
fadanData: d.fadan || null,
|
||||||
fenhongLilv: parseFloat(d.fenhong_lilv) || 0,
|
fenhongLilv: parseFloat(d.fenhong_lilv) || 0,
|
||||||
xinDingdanId: d.xin_dingdan_id || '',
|
xinDingdanId: d.xin_dingdan_id || '',
|
||||||
'jibenShuju.zhuangtai': d.zhuangtai || this.data.jibenShuju.zhuangtai
|
'jibenShuju.zhuangtai': d.zhuangtai || this.data.jibenShuju.zhuangtai,
|
||||||
|
'jibenShuju.is_cross': d.is_cross != null ? d.is_cross : this.data.jibenShuju.is_cross,
|
||||||
|
'jibenShuju.fadanpingtai': d.fadanpingtai != null ? d.fadanpingtai : this.data.jibenShuju.fadanpingtai,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
wx.showToast({ title: res?.data?.msg || '获取详情失败', icon: 'none' })
|
wx.showToast({ title: res?.data?.msg || '获取详情失败', icon: 'none' })
|
||||||
@@ -243,8 +246,10 @@ Page({
|
|||||||
identityType: 'shangjia',
|
identityType: 'shangjia',
|
||||||
userId: 'Sj' + uid,
|
userId: 'Sj' + uid,
|
||||||
orderId,
|
orderId,
|
||||||
|
partnerUid: this.data.dashouInfo.yonghuid,
|
||||||
|
fadanPingtai: this.data.jibenShuju.fadanpingtai || 0,
|
||||||
groupName: (this.data.dashouInfo.nicheng || this.data.jibenShuju.nicheng) + '的订单群',
|
groupName: (this.data.dashouInfo.nicheng || this.data.jibenShuju.nicheng) + '的订单群',
|
||||||
isCross: this.data.jibenShuju.fadanpingtai || 0
|
isCross: this.data.jibenShuju.is_cross || 0
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('跳转群聊失败', err)
|
console.error('跳转群聊失败', err)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// utils/chat-core.js
|
// utils/chat-core.js
|
||||||
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 { getFreshImUser } from './im-user.js';
|
import { parseOrderCardText } from './group-chat.js';
|
||||||
|
import { persistGroupMeta } from './im-user.js';
|
||||||
|
|
||||||
let _globalPrivateHandler = null;
|
let _globalPrivateHandler = null;
|
||||||
let _globalGroupHandler = null;
|
let _globalGroupHandler = null;
|
||||||
@@ -200,7 +201,9 @@ function disconnectGoEasy(app) {
|
|||||||
|
|
||||||
async function connectWithIdentity(app, identityType, userId, isAutoRestore = false) {
|
async function connectWithIdentity(app, identityType, userId, isAutoRestore = false) {
|
||||||
const quanxian = await jianquanxian(app);
|
const quanxian = await jianquanxian(app);
|
||||||
if (!quanxian.allowed) return Promise.reject(quanxian.reason);
|
if (!quanxian.allowed) {
|
||||||
|
return Promise.reject(new Error(quanxian.reason || '无聊天权限'));
|
||||||
|
}
|
||||||
|
|
||||||
app.globalData.goEasyConnection.autoReconnect = true;
|
app.globalData.goEasyConnection.autoReconnect = true;
|
||||||
app.globalData.goEasyConnection.status = 'connecting';
|
app.globalData.goEasyConnection.status = 'connecting';
|
||||||
@@ -444,14 +447,8 @@ function handleNewMessage(app, message) {
|
|||||||
function shouldShowNotification(app) {
|
function shouldShowNotification(app) {
|
||||||
if (app.globalData.messageManager.notificationMuted) return false;
|
if (app.globalData.messageManager.notificationMuted) return false;
|
||||||
if (isDoNotDisturbTime(app)) return false;
|
if (isDoNotDisturbTime(app)) return false;
|
||||||
if (app.globalData.pageState.isInChatPage) {
|
if (app.globalData.pageState.isInChatPage && app.globalData.pageState.currentChatId) {
|
||||||
const pages = getCurrentPages();
|
return false;
|
||||||
if (pages.length > 0) {
|
|
||||||
const currentPage = pages[pages.length - 1];
|
|
||||||
if (currentPage.data && currentPage.data.currentChatId) {
|
|
||||||
if (isMessageFromCurrentChat(app, currentPage.data.currentChatId)) return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -472,8 +469,16 @@ function isDoNotDisturbTime(app) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMessageFromCurrentChat(app, currentChatId) {
|
function isMessageFromCurrentChat(app, message) {
|
||||||
return false;
|
const pageState = app.globalData.pageState || {};
|
||||||
|
if (!pageState.isInChatPage || !pageState.currentChatId) return false;
|
||||||
|
if (message.groupId) {
|
||||||
|
return message.groupId === pageState.currentChatId;
|
||||||
|
}
|
||||||
|
const myId = app.globalData.goEasyConnection?.userId || getCurrentGoEasyUserId();
|
||||||
|
if (!myId) return false;
|
||||||
|
const peerId = message.senderId === myId ? message.receiverId : message.senderId;
|
||||||
|
return peerId === pageState.currentChatId || message.senderId === pageState.currentChatId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showNotificationDirect(app, data) {
|
function showNotificationDirect(app, data) {
|
||||||
@@ -534,6 +539,20 @@ function formatMessageForNotification(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cacheMessage(app, message) {
|
function cacheMessage(app, message) {
|
||||||
|
if (message.groupId && message.type === 'text' && message.payload?.text) {
|
||||||
|
const card = parseOrderCardText(message.payload.text);
|
||||||
|
if (card && card.zhuangtai != null) {
|
||||||
|
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||||
|
const meta = {
|
||||||
|
...(app.globalData.groupInfoMap[message.groupId] || {}),
|
||||||
|
orderId: card.orderId,
|
||||||
|
orderZhuangtai: card.zhuangtai,
|
||||||
|
orderDesc: card.jieshao,
|
||||||
|
};
|
||||||
|
app.globalData.groupInfoMap[message.groupId] = meta;
|
||||||
|
persistGroupMeta(app, message.groupId, meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
const { latestMessages } = app.globalData.messageManager;
|
const { latestMessages } = app.globalData.messageManager;
|
||||||
latestMessages.unshift({
|
latestMessages.unshift({
|
||||||
id: message.messageId,
|
id: message.messageId,
|
||||||
|
|||||||
@@ -8,6 +8,39 @@ const ZHUANGTAI_MAP = {
|
|||||||
5: '已退款', 6: '退款失败', 7: '指定中', 8: '结算中',
|
5: '已退款', 6: '退款失败', 7: '指定中', 8: '结算中',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getZhuangtaiText(zhuangtai) {
|
||||||
|
if (zhuangtai == null || zhuangtai === '') return '';
|
||||||
|
const n = Number(zhuangtai);
|
||||||
|
return ZHUANGTAI_MAP[n] || ZHUANGTAI_MAP[zhuangtai] || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildDashouShangjiaGroupId(dashouUid, shangjiaUid) {
|
||||||
|
return `group_Ds${dashouUid}_Sj${shangjiaUid}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildDashouBossGroupId(dashouUid, bossUid) {
|
||||||
|
return `group_Ds${dashouUid}_Boss${bossUid}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveLocalGroupId(identityType, myUid, partnerUid, fadanPingtai, orderId, isCross) {
|
||||||
|
const cross = isCross === 1 || isCross === true || String(isCross) === '1';
|
||||||
|
if (cross && orderId) {
|
||||||
|
return `group_${orderId}`;
|
||||||
|
}
|
||||||
|
if (!myUid) return orderId ? `group_${orderId}` : null;
|
||||||
|
if (!partnerUid) return orderId ? `group_${orderId}` : null;
|
||||||
|
if (identityType === 'shangjia') {
|
||||||
|
return buildDashouShangjiaGroupId(partnerUid, myUid);
|
||||||
|
}
|
||||||
|
if (identityType === 'dashou') {
|
||||||
|
if (fadanPingtai === 2 || String(fadanPingtai) === '2') {
|
||||||
|
return buildDashouShangjiaGroupId(myUid, partnerUid);
|
||||||
|
}
|
||||||
|
return buildDashouBossGroupId(myUid, partnerUid);
|
||||||
|
}
|
||||||
|
return orderId ? `group_${orderId}` : null;
|
||||||
|
}
|
||||||
|
|
||||||
export function isPairGroupId(groupId) {
|
export function isPairGroupId(groupId) {
|
||||||
return /^group_Ds\w+_(Sj|Boss)\w+$/.test(groupId || '');
|
return /^group_Ds\w+_(Sj|Boss)\w+$/.test(groupId || '');
|
||||||
}
|
}
|
||||||
@@ -108,6 +141,8 @@ export function parseOrderCardText(text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import { getChatImageUrl } from '../static/lib/utils.js';
|
||||||
|
|
||||||
export function normalizeGroupMessage(msg) {
|
export function normalizeGroupMessage(msg) {
|
||||||
if (!msg) return msg;
|
if (!msg) return msg;
|
||||||
if (msg.type === 'text' && msg.payload && msg.payload.text) {
|
if (msg.type === 'text' && msg.payload && msg.payload.text) {
|
||||||
@@ -117,6 +152,26 @@ export function normalizeGroupMessage(msg) {
|
|||||||
msg.payload = card;
|
msg.payload = card;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (msg.type === 'custom' && msg.payload) {
|
||||||
|
const inner = msg.payload.payload || msg.payload;
|
||||||
|
if (inner && (inner.orderId || inner.dingdan_id)) {
|
||||||
|
msg.type = 'order';
|
||||||
|
msg.payload = {
|
||||||
|
orderId: inner.orderId || inner.dingdan_id,
|
||||||
|
jieshao: inner.jieshao || '',
|
||||||
|
jine: inner.jine || '',
|
||||||
|
beizhu: inner.beizhu || '',
|
||||||
|
zhuangtai: inner.zhuangtai,
|
||||||
|
nicheng: inner.nicheng || '',
|
||||||
|
create_time: inner.create_time || '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (msg.type === 'image') {
|
||||||
|
const url = getChatImageUrl(msg);
|
||||||
|
msg.payload = { ...(msg.payload || {}), url };
|
||||||
|
msg.imageUrl = url;
|
||||||
|
}
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ const app = getApp();
|
|||||||
import { formatDate } from '../static/lib/utils';
|
import { formatDate } from '../static/lib/utils';
|
||||||
import request from './request.js';
|
import request from './request.js';
|
||||||
import { getFreshImUser } from './im-user.js';
|
import { getFreshImUser } from './im-user.js';
|
||||||
|
import { sendGoEasyImage } from './chatImageSend.js';
|
||||||
|
|
||||||
|
function isCrossPlatformOrder(isCross) {
|
||||||
|
return isCross === 1 || isCross === true || String(isCross) === '1';
|
||||||
|
}
|
||||||
|
|
||||||
function sendGroupMessage(options) {
|
function sendGroupMessage(options) {
|
||||||
const { msgData, onSuccess, onSendStart } = options;
|
const { msgData, onSuccess, onSendStart } = options;
|
||||||
@@ -20,8 +25,7 @@ function sendGroupMessage(options) {
|
|||||||
const localMsg = buildLocalMessage(msgData);
|
const localMsg = buildLocalMessage(msgData);
|
||||||
if (onSendStart) onSendStart(localMsg);
|
if (onSendStart) onSendStart(localMsg);
|
||||||
|
|
||||||
// 只有 isCross 明确为 0 才走前端 SDK,其余一律走后端
|
if (!isCrossPlatformOrder(isCross)) {
|
||||||
if (isCross === 0) {
|
|
||||||
sendViaSDK(localMsg, currentUser, groupId, onSuccess, orderId, isCross, groupName, groupAvatar);
|
sendViaSDK(localMsg, currentUser, groupId, onSuccess, orderId, isCross, groupName, groupAvatar);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -32,7 +36,7 @@ function buildLocalMessage(data) {
|
|||||||
const { type, text, filePath, orderPayload, currentUser, groupId } = data;
|
const { type, text, filePath, orderPayload, currentUser, groupId } = data;
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const base = {
|
const base = {
|
||||||
messageId: `${type}-${now}`,
|
messageId: `local-${type}-${now}`,
|
||||||
timestamp: now,
|
timestamp: now,
|
||||||
senderId: currentUser.id,
|
senderId: currentUser.id,
|
||||||
groupId: groupId,
|
groupId: groupId,
|
||||||
@@ -45,7 +49,7 @@ function buildLocalMessage(data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (type === 'text') return { ...base, type: 'text', payload: { text } };
|
if (type === 'text') return { ...base, type: 'text', payload: { text } };
|
||||||
if (type === 'image') return { ...base, type: 'image', payload: { url: filePath } };
|
if (type === 'image') return { ...base, type: 'image', payload: { url: filePath }, imageUrl: filePath };
|
||||||
if (type === 'order') return { ...base, type: 'order', payload: orderPayload };
|
if (type === 'order') return { ...base, type: 'order', payload: orderPayload };
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
@@ -66,6 +70,7 @@ function sendViaSDK(localMsg, currentUser, groupId, onSuccess, orderId, isCross,
|
|||||||
dashouAvatar: groupMeta.dashouAvatar,
|
dashouAvatar: groupMeta.dashouAvatar,
|
||||||
partnerAvatar: groupMeta.partnerAvatar,
|
partnerAvatar: groupMeta.partnerAvatar,
|
||||||
orderDesc: groupMeta.orderDesc,
|
orderDesc: groupMeta.orderDesc,
|
||||||
|
orderZhuangtai: groupMeta.orderZhuangtai,
|
||||||
};
|
};
|
||||||
|
|
||||||
const to = {
|
const to = {
|
||||||
@@ -74,18 +79,35 @@ function sendViaSDK(localMsg, currentUser, groupId, onSuccess, orderId, isCross,
|
|||||||
data: toData
|
data: toData
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (localMsg.type === 'image') {
|
||||||
|
sendGoEasyImage({
|
||||||
|
file: localMsg.payload.url,
|
||||||
|
to,
|
||||||
|
onSuccess: (res) => {
|
||||||
|
const serverMsg = res && res.content;
|
||||||
|
if (serverMsg && onSuccess) {
|
||||||
|
onSuccess(localMsg.messageId, 'success', serverMsg);
|
||||||
|
} else if (onSuccess) {
|
||||||
|
onSuccess(localMsg.messageId, 'success');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onFailed: () => { if (onSuccess) onSuccess(localMsg.messageId, 'failed'); }
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let message;
|
let message;
|
||||||
if (localMsg.type === 'text') {
|
if (localMsg.type === 'text') {
|
||||||
message = wx.goEasy.im.createTextMessage({ text: localMsg.payload.text, to });
|
message = wx.goEasy.im.createTextMessage({ text: localMsg.payload.text, to });
|
||||||
} else if (localMsg.type === 'image') {
|
|
||||||
message = wx.goEasy.im.createImageMessage({ file: localMsg.payload.url, to });
|
|
||||||
} else if (localMsg.type === 'order') {
|
} else if (localMsg.type === 'order') {
|
||||||
message = wx.goEasy.im.createCustomMessage({ type: 'order', payload: localMsg.payload, to });
|
message = wx.goEasy.im.createCustomMessage({ type: 'order', payload: localMsg.payload, to });
|
||||||
}
|
}
|
||||||
|
|
||||||
wx.goEasy.im.sendMessage({
|
wx.goEasy.im.sendMessage({
|
||||||
message,
|
message,
|
||||||
onSuccess: () => { if (onSuccess) onSuccess(localMsg.messageId, 'success'); },
|
onSuccess: (res) => {
|
||||||
|
if (onSuccess) onSuccess(localMsg.messageId, 'success', res && res.content);
|
||||||
|
},
|
||||||
onFailed: () => { if (onSuccess) onSuccess(localMsg.messageId, 'failed'); }
|
onFailed: () => { if (onSuccess) onSuccess(localMsg.messageId, 'failed'); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -93,18 +115,17 @@ function sendViaSDK(localMsg, currentUser, groupId, onSuccess, orderId, isCross,
|
|||||||
function sendViaBackend(localMsg, currentUser, groupId, orderId, onSuccess) {
|
function sendViaBackend(localMsg, currentUser, groupId, orderId, onSuccess) {
|
||||||
const apiUrl = '/dingdan/kptxxfs';
|
const apiUrl = '/dingdan/kptxxfs';
|
||||||
|
|
||||||
// 🔥 实时获取当前身份,不再依赖外部传入的 currentUser.id
|
|
||||||
const uid = wx.getStorageSync('uid');
|
const uid = wx.getStorageSync('uid');
|
||||||
const role = app.globalData.currentRole || 'normal';
|
const role = app.globalData.currentRole || 'normal';
|
||||||
const prefixMap = { normal: 'Boss', dashou: 'Ds', shangjia: 'Sj', guanshi: 'Gs', zuzhang: 'Zz' };
|
|
||||||
const identityType = role === 'dashou' ? 'dashou' : (role === 'shangjia' ? 'shangjia' : 'boss');
|
const identityType = role === 'dashou' ? 'dashou' : (role === 'shangjia' ? 'shangjia' : 'boss');
|
||||||
|
const prefixMap = { normal: 'Boss', dashou: 'Ds', shangjia: 'Sj', guanshi: 'Gs', zuzhang: 'Zz' };
|
||||||
const prefix = prefixMap[role] || 'Boss';
|
const prefix = prefixMap[role] || 'Boss';
|
||||||
const senderId = prefix + uid;
|
const senderId = prefix + uid;
|
||||||
const freshUser = getFreshImUser(app, role, uid);
|
const freshUser = getFreshImUser(app, role, uid);
|
||||||
const params = {
|
const params = {
|
||||||
orderId: orderId,
|
orderId: orderId,
|
||||||
groupId: groupId,
|
groupId: groupId,
|
||||||
identityType: identityType, // 告诉后端当前是什么身份
|
identityType: identityType,
|
||||||
senderId: senderId,
|
senderId: senderId,
|
||||||
senderName: freshUser.name || currentUser.name || ('用户' + uid),
|
senderName: freshUser.name || currentUser.name || ('用户' + uid),
|
||||||
senderAvatar: freshUser.avatar || currentUser.avatar || (app.globalData.ossImageUrl + app.globalData.morentouxiang),
|
senderAvatar: freshUser.avatar || currentUser.avatar || (app.globalData.ossImageUrl + app.globalData.morentouxiang),
|
||||||
@@ -135,7 +156,6 @@ function sendViaBackend(localMsg, currentUser, groupId, orderId, onSuccess) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 图片消息
|
|
||||||
if (localMsg.type === 'image') {
|
if (localMsg.type === 'image') {
|
||||||
const token = wx.getStorageSync('token');
|
const token = wx.getStorageSync('token');
|
||||||
const formData = {
|
const formData = {
|
||||||
@@ -169,4 +189,4 @@ function sendViaBackend(localMsg, currentUser, groupId, orderId, onSuccess) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { sendGroupMessage };
|
module.exports = { sendGroupMessage };
|
||||||
|
|||||||
@@ -1,42 +1,46 @@
|
|||||||
/**
|
/**
|
||||||
* 连接管理模块 - 订单群聊跳转(后端准备群 + 稳定连接)
|
* 订单群聊跳转:先确定群 ID,IM 连接失败也尽量能进聊天页
|
||||||
*/
|
*/
|
||||||
import request from './request';
|
import request from './request';
|
||||||
import { persistGroupMeta } from './im-user.js';
|
import { persistGroupMeta } from './im-user.js';
|
||||||
|
import { resolveLocalGroupId } from './group-chat.js';
|
||||||
|
|
||||||
const app = getApp();
|
const app = getApp();
|
||||||
|
|
||||||
function waitForConnection(expectedUserId, timeout = 15000) {
|
function formatError(err) {
|
||||||
|
if (!err) return '进入聊天失败';
|
||||||
|
if (typeof err === 'string') return err;
|
||||||
|
if (err.message) return err.message;
|
||||||
|
if (err.content) return String(err.content);
|
||||||
|
if (err.msg) return String(err.msg);
|
||||||
|
if (err.code) return `连接失败(${err.code})`;
|
||||||
|
try {
|
||||||
|
return JSON.stringify(err);
|
||||||
|
} catch (e) {
|
||||||
|
return '进入聊天失败';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function withTimeout(promise, ms, errMsg) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const status = wx.goEasy?.getConnectionStatus?.();
|
const timer = setTimeout(() => reject(new Error(errMsg || '操作超时')), ms);
|
||||||
const currentUserId = wx.goEasy?.im?.userId;
|
promise
|
||||||
if ((status === 'connected' || status === 'reconnected') && currentUserId === expectedUserId) {
|
.then((v) => { clearTimeout(timer); resolve(v); })
|
||||||
resolve();
|
.catch((e) => { clearTimeout(timer); reject(e); });
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
app.off('connectionChanged', handler);
|
|
||||||
reject(new Error('连接超时'));
|
|
||||||
}, timeout);
|
|
||||||
|
|
||||||
const handler = (event) => {
|
|
||||||
if (event.status === 'connected') {
|
|
||||||
const uid = event.userId || wx.goEasy?.im?.userId;
|
|
||||||
if (uid === expectedUserId) {
|
|
||||||
clearTimeout(timer);
|
|
||||||
app.off('connectionChanged', handler);
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
} else if (event.status === 'disconnected' && event.manual) {
|
|
||||||
clearTimeout(timer);
|
|
||||||
app.off('connectionChanged', handler);
|
|
||||||
reject(new Error('连接已断开'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
app.on('connectionChanged', handler);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getConnectedUserId() {
|
||||||
|
const fromState = app.globalData?.goEasyConnection?.userId;
|
||||||
|
const fromIm = wx.goEasy?.im?.userId;
|
||||||
|
return fromState || fromIm || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function isImConnected() {
|
||||||
|
const status = wx.goEasy?.getConnectionStatus?.() || 'disconnected';
|
||||||
|
return status === 'connected' || status === 'reconnected';
|
||||||
|
}
|
||||||
|
|
||||||
async function ensureIdentityConnection(identityType, userId) {
|
async function ensureIdentityConnection(identityType, userId) {
|
||||||
app.globalData.currentRole = identityType;
|
app.globalData.currentRole = identityType;
|
||||||
wx.setStorageSync('currentRole', identityType);
|
wx.setStorageSync('currentRole', identityType);
|
||||||
@@ -50,21 +54,88 @@ async function ensureIdentityConnection(identityType, userId) {
|
|||||||
avatar: avatar,
|
avatar: avatar,
|
||||||
};
|
};
|
||||||
|
|
||||||
const status = wx.goEasy?.getConnectionStatus?.() || 'disconnected';
|
if (!app.globalData.chatEnabled || !wx.goEasy?.im) {
|
||||||
const currentUserId = wx.goEasy?.im?.userId;
|
throw new Error('聊天服务未就绪,请稍后重试');
|
||||||
|
}
|
||||||
|
|
||||||
if ((status === 'connected' || status === 'reconnected') && currentUserId === userId) {
|
if (isImConnected() && getConnectedUserId() === userId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUserId && currentUserId !== userId && app.disconnectGoEasy) {
|
const connectedId = getConnectedUserId();
|
||||||
|
if (connectedId && connectedId !== userId && app.disconnectGoEasy) {
|
||||||
await app.disconnectGoEasy();
|
await app.disconnectGoEasy();
|
||||||
}
|
}
|
||||||
|
|
||||||
const waitPromise = waitForConnection(userId);
|
if (!app.connectWithIdentity) {
|
||||||
const connectPromise = app.connectWithIdentity(identityType, userId, true);
|
throw new Error('聊天功能未初始化');
|
||||||
await waitPromise;
|
}
|
||||||
await connectPromise;
|
|
||||||
|
await withTimeout(
|
||||||
|
app.connectWithIdentity(identityType, userId, true),
|
||||||
|
12000,
|
||||||
|
'IM连接超时'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isImConnected()) {
|
||||||
|
throw new Error('IM连接失败,请检查网络后重试');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prepareGroupChat(identityType, userId, orderId, partnerUid, fadanPingtai, groupName, isCross) {
|
||||||
|
let chatData = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await withTimeout(
|
||||||
|
request({
|
||||||
|
url: '/dingdan/ltdhzb',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
dingdan_id: orderId,
|
||||||
|
identityType,
|
||||||
|
push_order_card: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
12000,
|
||||||
|
'准备群聊超时'
|
||||||
|
);
|
||||||
|
const body = res?.data || {};
|
||||||
|
if (body.code === 0 && body.data?.groupId) {
|
||||||
|
chatData = body.data;
|
||||||
|
} else if (body.msg) {
|
||||||
|
console.warn('ltdhzb:', body.msg);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('ltdhzb 请求失败,尝试本地 groupId', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chatData?.groupId) {
|
||||||
|
const myUid = userId.replace(/^(Ds|Sj|Boss)/, '');
|
||||||
|
let localGroupId = resolveLocalGroupId(
|
||||||
|
identityType, myUid, partnerUid, fadanPingtai, orderId, isCross
|
||||||
|
);
|
||||||
|
if (!localGroupId && orderId) {
|
||||||
|
localGroupId = `group_${orderId}`;
|
||||||
|
}
|
||||||
|
if (!localGroupId) {
|
||||||
|
throw new Error('无法确定群聊,请确认订单已接单且对方信息完整');
|
||||||
|
}
|
||||||
|
chatData = {
|
||||||
|
groupId: localGroupId,
|
||||||
|
orderId,
|
||||||
|
groupName: groupName || '订单群聊',
|
||||||
|
isCross: isCross || fadanPingtai || 0,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await request({
|
||||||
|
url: '/dingdan/ltdhzb',
|
||||||
|
method: 'POST',
|
||||||
|
data: { dingdan_id: orderId, identityType, push_order_card: true },
|
||||||
|
});
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
return chatData;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConnectionManager {
|
class ConnectionManager {
|
||||||
@@ -89,39 +160,30 @@ class ConnectionManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const param = { to, currentUser };
|
const param = { to, currentUser };
|
||||||
const path = '/pages/liaotian/liaotian?data=' + encodeURIComponent(JSON.stringify(param));
|
wx.navigateTo({ url: '/pages/liaotian/liaotian?data=' + encodeURIComponent(JSON.stringify(param)) });
|
||||||
wx.navigateTo({ url: path });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async connectToGroupChat(params) {
|
async connectToGroupChat(params) {
|
||||||
const { identityType, userId, orderId, groupName, groupAvatar, isCross } = params;
|
const {
|
||||||
|
identityType, userId, orderId, groupName, groupAvatar, isCross,
|
||||||
|
partnerUid, fadanPingtai,
|
||||||
|
} = params;
|
||||||
|
|
||||||
if (!identityType || !userId || !orderId) {
|
if (!identityType || !userId || !orderId) {
|
||||||
throw new Error('参数不完整:identityType, userId, orderId 必填');
|
throw new Error('参数不完整');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.globalData.currentRole = identityType;
|
||||||
|
wx.setStorageSync('currentRole', identityType);
|
||||||
|
|
||||||
wx.showLoading({ title: '建立联系中...', mask: true });
|
wx.showLoading({ title: '建立联系中...', mask: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ensureIdentityConnection(identityType, userId);
|
const chatData = await prepareGroupChat(
|
||||||
|
identityType, userId, orderId, partnerUid, fadanPingtai || isCross, groupName, isCross
|
||||||
|
);
|
||||||
|
|
||||||
const res = await request({
|
|
||||||
url: '/dingdan/ltdhzb',
|
|
||||||
method: 'POST',
|
|
||||||
data: {
|
|
||||||
dingdan_id: orderId,
|
|
||||||
identityType,
|
|
||||||
push_order_card: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = res?.data || {};
|
|
||||||
if (body.code !== 0 || !body.data || !body.data.groupId) {
|
|
||||||
throw new Error(body.msg || '准备群聊失败');
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatData = body.data;
|
|
||||||
const realGroupId = chatData.groupId;
|
const realGroupId = chatData.groupId;
|
||||||
|
|
||||||
let avatar = chatData.counterpartAvatar || chatData.groupAvatar || groupAvatar || '';
|
let avatar = chatData.counterpartAvatar || chatData.groupAvatar || groupAvatar || '';
|
||||||
if (avatar && !avatar.startsWith('http')) {
|
if (avatar && !avatar.startsWith('http')) {
|
||||||
avatar = app.globalData.ossImageUrl + avatar.replace(/^\//, '');
|
avatar = app.globalData.ossImageUrl + avatar.replace(/^\//, '');
|
||||||
@@ -148,30 +210,57 @@ class ConnectionManager {
|
|||||||
app.globalData.groupInfoMap[realGroupId] = meta;
|
app.globalData.groupInfoMap[realGroupId] = meta;
|
||||||
persistGroupMeta(app, realGroupId, meta);
|
persistGroupMeta(app, realGroupId, meta);
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
let imReady = false;
|
||||||
wx.goEasy.im.subscribeGroup({
|
try {
|
||||||
groupIds: [realGroupId],
|
await ensureIdentityConnection(identityType, userId);
|
||||||
onSuccess: () => resolve(),
|
imReady = true;
|
||||||
onFailed: (error) => reject(error),
|
try {
|
||||||
});
|
await withTimeout(
|
||||||
});
|
new Promise((resolve, reject) => {
|
||||||
|
wx.goEasy.im.subscribeGroup({
|
||||||
|
groupIds: [realGroupId],
|
||||||
|
onSuccess: () => resolve(),
|
||||||
|
onFailed: (error) => reject(error),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
8000,
|
||||||
|
'订阅群聊超时'
|
||||||
|
);
|
||||||
|
} catch (subErr) {
|
||||||
|
console.warn('订阅群聊失败,仍尝试进入页面', subErr);
|
||||||
|
}
|
||||||
|
} catch (imErr) {
|
||||||
|
console.warn('IM连接失败,仍进入聊天页由页面重连', imErr);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uid = userId.replace(/^(Ds|Sj|Boss)/, '');
|
||||||
const param = {
|
const param = {
|
||||||
groupId: realGroupId,
|
groupId: realGroupId,
|
||||||
orderId: chatData.orderId || orderId,
|
orderId: chatData.orderId || orderId,
|
||||||
groupName: chatData.counterpartName || chatData.groupName || groupName || '订单群聊',
|
groupName: chatData.counterpartName || chatData.groupName || groupName || '订单群聊',
|
||||||
groupAvatar: avatar,
|
groupAvatar: avatar,
|
||||||
isCross: chatData.isCross != null ? chatData.isCross : (isCross || 0),
|
isCross: chatData.isCross != null ? chatData.isCross : (isCross || 0),
|
||||||
|
currentUserId: userId,
|
||||||
|
currentUserName: app.globalData.currentUser?.name || `用户${uid}`,
|
||||||
|
currentUserAvatar: app.globalData.currentUser?.avatar ||
|
||||||
|
(wx.getStorageSync('touxiang') || (app.globalData.ossImageUrl + app.globalData.morentouxiang)),
|
||||||
|
orderZhuangtai: chatData.orderZhuangtai,
|
||||||
|
orderJine: chatData.orderJine,
|
||||||
|
orderDesc: chatData.orderDesc || '',
|
||||||
|
imReady,
|
||||||
};
|
};
|
||||||
|
|
||||||
wx.hideLoading();
|
wx.hideLoading();
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: '/pages/qunliaotian/qunliaotian?data=' + encodeURIComponent(JSON.stringify(param)),
|
url: '/pages/qunliaotian/qunliaotian?data=' + encodeURIComponent(JSON.stringify(param)),
|
||||||
|
fail: (navErr) => {
|
||||||
|
wx.showToast({ title: formatError(navErr), icon: 'none', duration: 2500 });
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
wx.hideLoading();
|
wx.hideLoading();
|
||||||
console.error('跳转群聊失败:', err);
|
console.error('跳转群聊失败:', err);
|
||||||
wx.showToast({ title: err.message || '进入聊天失败', icon: 'none' });
|
wx.showToast({ title: formatError(err), icon: 'none', duration: 2500 });
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user