|
|
|
|
@@ -1,10 +1,16 @@
|
|
|
|
|
const app = getApp();
|
|
|
|
|
import { formatDate } from '../../static/lib/utils';
|
|
|
|
|
import { sendGroupMessage } from '../../utils/message-sender';
|
|
|
|
|
import { showConfirmByScene } from '../../utils/scriptService.js';
|
|
|
|
|
import { normalizeGroupMessage, getZhuangtaiText } from '../../utils/group-chat.js';
|
|
|
|
|
import { persistGroupMeta } from '../../utils/im-user.js';
|
|
|
|
|
import { getFreshImUser } from '../../utils/im-user.js';
|
|
|
|
|
import { getLocalImUserId } from '../../utils/im-user.js';
|
|
|
|
|
import { resolveAvatarUrl, getDefaultAvatarUrl, resolveAvatarFromStorage } from '../../utils/avatar.js';
|
|
|
|
|
import { getZhuangtaiText, isPairGroupId, normalizeGroupMessage, recordConversationOpen } from '../../utils/group-chat.js';
|
|
|
|
|
import request from '../../utils/request';
|
|
|
|
|
import {
|
|
|
|
|
fetchHistoryMessages,
|
|
|
|
|
getOldestHistoryTimestamp,
|
|
|
|
|
mergeHistoryMessages,
|
|
|
|
|
waitImConnected,
|
|
|
|
|
} from '../../utils/chat-history.js';
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
@@ -15,8 +21,8 @@ Page({
|
|
|
|
|
isCross: 0,
|
|
|
|
|
orderZhuangtai: null,
|
|
|
|
|
orderZhuangtaiText: '',
|
|
|
|
|
orderJine: '',
|
|
|
|
|
orderJieshao: '',
|
|
|
|
|
orderJine: '',
|
|
|
|
|
currentUser: null,
|
|
|
|
|
messages: [],
|
|
|
|
|
inputText: '',
|
|
|
|
|
@@ -34,8 +40,10 @@ Page({
|
|
|
|
|
lastTapMsgId: '',
|
|
|
|
|
emojiList: ['😀','😁','😂','🤣','😃','😄','😅','😆','😉','😊','😋','😎','😍','😘','😗','😙','😚','🙂','🤗','🤩','🤔','🤨','😐','😑','😶','🙄','😏','😣','😥','😮','🤐','😯','😪','😫','😴','😌','😛','😜','😝','🤤','😒','😓','😔','😕','🙃','🤑','😲','☹','🙁','😖','😞','😟','😤','😢','😭','😦','😧','😨','😩','🤯','😬','😰','😱','🥵','🥶','😳','🤪','😵','😡','😠','🤬','😷','🤒','🤕','🤢','🤮','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','👺','💀','👻','👽','🤖','💩','😺','😸','😹','😻','😼','😽','🙀','😿','😾'],
|
|
|
|
|
pendingImage: '',
|
|
|
|
|
pendingImageFile: null,
|
|
|
|
|
keyboardHeight: 0,
|
|
|
|
|
bottomSafeHeight: 10
|
|
|
|
|
bottomSafeHeight: 140,
|
|
|
|
|
defaultAvatarUrl: '',
|
|
|
|
|
},
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
let p = { groupId: '', groupName: '订单群聊', groupAvatar: '', orderId: '', isCross: 0,
|
|
|
|
|
@@ -46,182 +54,278 @@ Page({
|
|
|
|
|
p = { ...p, ...d };
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
}
|
|
|
|
|
const orderIdStr = String(p.orderId || '').replace(/^group_/, '') ||
|
|
|
|
|
(p.groupId && !isPairGroupId(p.groupId) ? String(p.groupId).replace(/^group_/, '') : '');
|
|
|
|
|
const groupId = p.groupId
|
|
|
|
|
? String(p.groupId)
|
|
|
|
|
: (orderIdStr ? `group_${orderIdStr}` : '');
|
|
|
|
|
const zt = p.orderZhuangtai;
|
|
|
|
|
const defAvatar = getDefaultAvatarUrl(app);
|
|
|
|
|
this.setData({
|
|
|
|
|
groupId: p.groupId,
|
|
|
|
|
groupId,
|
|
|
|
|
groupName: p.groupName,
|
|
|
|
|
groupAvatar: p.groupAvatar,
|
|
|
|
|
orderId: p.orderId,
|
|
|
|
|
isCross: p.isCross
|
|
|
|
|
groupAvatar: resolveAvatarUrl(p.groupAvatar, app) || defAvatar,
|
|
|
|
|
orderId: orderIdStr,
|
|
|
|
|
isCross: p.isCross,
|
|
|
|
|
orderJieshao: p.orderDesc || p.orderJieshao || '',
|
|
|
|
|
orderJine: p.orderJine || '',
|
|
|
|
|
orderZhuangtai: zt,
|
|
|
|
|
orderZhuangtaiText: zt != null ? getZhuangtaiText(zt) : '',
|
|
|
|
|
defaultAvatarUrl: defAvatar,
|
|
|
|
|
});
|
|
|
|
|
wx.setNavigationBarTitle({ title: this.data.groupName });
|
|
|
|
|
// 如果有外部传入的 currentUser 信息,直接用,不再依赖全局状态
|
|
|
|
|
if (p.currentUserId) {
|
|
|
|
|
this.setData({
|
|
|
|
|
currentUser: {
|
|
|
|
|
id: p.currentUserId,
|
|
|
|
|
name: p.currentUserName || `用户${p.currentUserId.replace(/^[A-Za-z]+/,'')}`,
|
|
|
|
|
avatar: p.currentUserAvatar || (app.globalData.ossImageUrl + app.globalData.morentouxiang)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.ensureCurrentUser(p);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ensureCurrentUser(p) {
|
|
|
|
|
p = p || {};
|
|
|
|
|
const localImId = getLocalImUserId(app);
|
|
|
|
|
const uid = wx.getStorageSync('uid') || '';
|
|
|
|
|
const userId = localImId || p.currentUserId || '';
|
|
|
|
|
if (!userId) {
|
|
|
|
|
this.initCurrentUser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const meta = (app.globalData.groupInfoMap && app.globalData.groupInfoMap[p.groupId]) || {};
|
|
|
|
|
const initZt = p.orderZhuangtai != null ? p.orderZhuangtai : meta.orderZhuangtai;
|
|
|
|
|
if (initZt != null) {
|
|
|
|
|
this.applyOrderStatus(initZt, {
|
|
|
|
|
orderId: p.orderId || meta.orderId,
|
|
|
|
|
jine: p.orderJine || meta.orderJine,
|
|
|
|
|
jieshao: p.orderDesc || meta.orderDesc,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
|
app.globalData.pageState.isInChatPage = true;
|
|
|
|
|
app.globalData.pageState.currentChatId = this.data.groupId;
|
|
|
|
|
app.globalData.pageState.isInGroupChat = true;
|
|
|
|
|
this.ensureChatConnection();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onHide() {
|
|
|
|
|
app.globalData.pageState.isInChatPage = false;
|
|
|
|
|
app.globalData.pageState.currentChatId = '';
|
|
|
|
|
app.globalData.pageState.isInGroupChat = false;
|
|
|
|
|
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 cardOrderId = payload.orderId || payload.dingdan_id;
|
|
|
|
|
if (cardOrderId && this.data.orderId && cardOrderId !== this.data.orderId) 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 defAvatar = getDefaultAvatarUrl(app);
|
|
|
|
|
const rawAvatar = p.currentUserAvatar
|
|
|
|
|
|| wx.getStorageSync('touxiang')
|
|
|
|
|
|| app.globalData.currentUser?.avatar
|
|
|
|
|
|| '';
|
|
|
|
|
const name = p.currentUserName
|
|
|
|
|
|| app.globalData.currentUser?.name
|
|
|
|
|
|| wx.getStorageSync('nicheng')
|
|
|
|
|
|| app.globalData.dashouNicheng
|
|
|
|
|
|| app.globalData.nicheng
|
|
|
|
|
|| `用户${uid}`;
|
|
|
|
|
const avatar = resolveAvatarUrl(rawAvatar, app) || defAvatar;
|
|
|
|
|
const currentUser = { id: userId, name, avatar: avatar || defAvatar };
|
|
|
|
|
app.globalData.currentUser = { ...app.globalData.currentUser, ...currentUser };
|
|
|
|
|
this.setData({ currentUser });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getMyChatProfile() {
|
|
|
|
|
const cu = this.data.currentUser;
|
|
|
|
|
const defAvatar = getDefaultAvatarUrl(app);
|
|
|
|
|
if (cu && cu.id) {
|
|
|
|
|
return {
|
|
|
|
|
id: cu.id,
|
|
|
|
|
name: cu.name || `用户${wx.getStorageSync('uid') || ''}`,
|
|
|
|
|
avatar: resolveAvatarUrl(cu.avatar, app) || defAvatar,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
const imId = getLocalImUserId(app);
|
|
|
|
|
const uid = wx.getStorageSync('uid') || '';
|
|
|
|
|
return {
|
|
|
|
|
id: imId || '',
|
|
|
|
|
name: wx.getStorageSync('nicheng') || app.globalData.nicheng || `用户${uid}`,
|
|
|
|
|
avatar: resolveAvatarFromStorage(app) || defAvatar,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initCurrentUser() {
|
|
|
|
|
const profile = this.getMyChatProfile();
|
|
|
|
|
if (!profile.id) return;
|
|
|
|
|
this.setData({ currentUser: profile });
|
|
|
|
|
app.globalData.currentUser = { ...app.globalData.currentUser, ...profile };
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
buildImageFile(tempPath, size) {
|
|
|
|
|
return {
|
|
|
|
|
path: tempPath,
|
|
|
|
|
tempFilePath: tempPath,
|
|
|
|
|
size: size || 0,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
normalizeMessage(msg) {
|
|
|
|
|
if (!msg) return msg;
|
|
|
|
|
msg = normalizeGroupMessage(msg);
|
|
|
|
|
if (!msg.payload) msg.payload = {};
|
|
|
|
|
const defAvatar = getDefaultAvatarUrl(app);
|
|
|
|
|
const me = this.getMyChatProfile();
|
|
|
|
|
if (me.id && msg.senderId === me.id) {
|
|
|
|
|
msg.senderData = {
|
|
|
|
|
name: me.name,
|
|
|
|
|
avatar: me.avatar || defAvatar,
|
|
|
|
|
};
|
|
|
|
|
} else if (msg.senderData?.avatar) {
|
|
|
|
|
msg.senderData.avatar = resolveAvatarUrl(msg.senderData.avatar, app) || defAvatar;
|
|
|
|
|
} else if (msg.senderData) {
|
|
|
|
|
msg.senderData.avatar = defAvatar;
|
|
|
|
|
}
|
|
|
|
|
if (msg.type === 'image' && msg.payload?.url && !String(msg.payload.url).startsWith('http')) {
|
|
|
|
|
msg.payload.url = resolveAvatarUrl(msg.payload.url, app) || msg.payload.url;
|
|
|
|
|
}
|
|
|
|
|
return msg;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
mapIdentityForApi() {
|
|
|
|
|
const role = app.globalData.currentRole || wx.getStorageSync('currentRole') || 'normal';
|
|
|
|
|
if (role === 'dashou') return 'dashou';
|
|
|
|
|
if (role === 'shangjia') return 'shangjia';
|
|
|
|
|
return 'normal';
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async refreshLatestOrderBar() {
|
|
|
|
|
const { groupId, orderId } = this.data;
|
|
|
|
|
if (!groupId && !orderId) return;
|
|
|
|
|
try {
|
|
|
|
|
const res = await request({
|
|
|
|
|
url: '/dingdan/ltpddd',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
data: {
|
|
|
|
|
groupId,
|
|
|
|
|
dingdan_id: orderId,
|
|
|
|
|
identityType: this.mapIdentityForApi(),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const body = res?.data || {};
|
|
|
|
|
const latest = body.data?.latest;
|
|
|
|
|
if (!latest) return;
|
|
|
|
|
this.setData({
|
|
|
|
|
orderId: latest.dingdan_id,
|
|
|
|
|
orderJieshao: latest.jieshao || '',
|
|
|
|
|
orderJine: latest.jine || '',
|
|
|
|
|
orderZhuangtai: latest.zhuangtai,
|
|
|
|
|
orderZhuangtaiText: getZhuangtaiText(latest.zhuangtai),
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn('刷新最新订单条失败', e);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async refreshOrderStatus() {
|
|
|
|
|
const { orderId } = this.data;
|
|
|
|
|
if (!orderId) return;
|
|
|
|
|
try {
|
|
|
|
|
const res = await request({
|
|
|
|
|
url: '/dingdan/ltddzt',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
data: {
|
|
|
|
|
dingdan_id: orderId,
|
|
|
|
|
identityType: this.mapIdentityForApi(),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const body = res?.data || {};
|
|
|
|
|
const st = body.data;
|
|
|
|
|
if (!st) return;
|
|
|
|
|
this.setData({
|
|
|
|
|
orderJieshao: st.jieshao || this.data.orderJieshao,
|
|
|
|
|
orderJine: st.jine || this.data.orderJine,
|
|
|
|
|
orderZhuangtai: st.zhuangtai,
|
|
|
|
|
orderZhuangtaiText: getZhuangtaiText(st.zhuangtai),
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn('刷新订单状态失败', e);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
startOrderStatusPoll() {
|
|
|
|
|
this.stopOrderStatusPoll();
|
|
|
|
|
this._orderPollTimer = setInterval(() => this.refreshOrderStatus(), 15000);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
stopOrderStatusPoll() {
|
|
|
|
|
if (this._orderPollTimer) {
|
|
|
|
|
clearInterval(this._orderPollTimer);
|
|
|
|
|
this._orderPollTimer = null;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
mergeSentMessage(localId, sent) {
|
|
|
|
|
if (!sent) {
|
|
|
|
|
this.updateMsg(localId, 'success');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
return this.normalizeMessage({
|
|
|
|
|
...m,
|
|
|
|
|
...sent,
|
|
|
|
|
status: 'success',
|
|
|
|
|
messageId: sent.messageId || m.messageId,
|
|
|
|
|
payload: sent.payload || m.payload,
|
|
|
|
|
senderData: m.senderData || sent.senderData,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
this.setData({ messages: msgs });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async ensureChatConnection() {
|
|
|
|
|
const role = app.globalData.currentRole || 'normal';
|
|
|
|
|
const uid = wx.getStorageSync('uid');
|
|
|
|
|
const prefixMap = { normal:'Boss', dashou:'Ds', shangjia:'Sj', guanshi:'Gs', zuzhang:'Zz', kaoheguan:'Kh' };
|
|
|
|
|
const pageUserId = this.data.currentUser?.id;
|
|
|
|
|
const targetUserId = pageUserId || (prefixMap[role] || 'Boss') + uid;
|
|
|
|
|
|
|
|
|
|
const onReady = () => {
|
|
|
|
|
this.subscribeGroupIfNeeded()
|
|
|
|
|
.then(() => {
|
|
|
|
|
this.setupAllListeners();
|
|
|
|
|
return this.loadHistory(true);
|
|
|
|
|
})
|
|
|
|
|
.then(() => this.markGroupMessageAsRead());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const connectedId = app.globalData?.goEasyConnection?.userId || wx.goEasy?.im?.userId;
|
|
|
|
|
const status = wx.goEasy?.getConnectionStatus?.() || 'disconnected';
|
|
|
|
|
const imOk = status === 'connected' || status === 'reconnected';
|
|
|
|
|
|
|
|
|
|
if (imOk && connectedId === targetUserId) {
|
|
|
|
|
onReady();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (app.ensureImForRole) {
|
|
|
|
|
await app.ensureImForRole(role);
|
|
|
|
|
} else if (app.connectWithIdentity) {
|
|
|
|
|
await app.connectWithIdentity(role, targetUserId, true);
|
|
|
|
|
}
|
|
|
|
|
onReady();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
const s = wx.goEasy?.getConnectionStatus?.();
|
|
|
|
|
if (s === 'connected' || s === 'reconnected') onReady();
|
|
|
|
|
else wx.showToast({ title: '连接失败,请重试', icon: 'none' });
|
|
|
|
|
onShow() {
|
|
|
|
|
const defAvatar = getDefaultAvatarUrl(app);
|
|
|
|
|
this.setData({
|
|
|
|
|
defaultAvatarUrl: defAvatar,
|
|
|
|
|
groupAvatar: resolveAvatarUrl(this.data.groupAvatar, app) || defAvatar,
|
|
|
|
|
});
|
|
|
|
|
this.ensureCurrentUser({});
|
|
|
|
|
if (this.data.groupId) {
|
|
|
|
|
if (!app.globalData.pageState) app.globalData.pageState = {};
|
|
|
|
|
app.globalData.pageState.lastOpenedConvId = this.data.groupId;
|
|
|
|
|
recordConversationOpen({ groupId: this.data.groupId });
|
|
|
|
|
}
|
|
|
|
|
this.refreshLatestOrderBar();
|
|
|
|
|
this.startOrderStatusPoll();
|
|
|
|
|
this.autoConnect();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
clearPageListeners() {
|
|
|
|
|
onHide() {
|
|
|
|
|
if (this.data.groupId) {
|
|
|
|
|
recordConversationOpen({ groupId: this.data.groupId });
|
|
|
|
|
}
|
|
|
|
|
this.stopOrderStatusPoll();
|
|
|
|
|
this.clearAllListeners();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onUnload() {
|
|
|
|
|
this.stopOrderStatusPoll();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
autoConnect() {
|
|
|
|
|
const targetUserId = this.data.currentUser?.id || getLocalImUserId(app);
|
|
|
|
|
if (!targetUserId) return;
|
|
|
|
|
|
|
|
|
|
const afterReady = () => {
|
|
|
|
|
this.subscribeGroupIfNeeded().then(() => {
|
|
|
|
|
this.setupAllListeners();
|
|
|
|
|
this.loadHistory(true);
|
|
|
|
|
this.markGroupMessageAsRead();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (app.ensureConnection) {
|
|
|
|
|
app.ensureConnection();
|
|
|
|
|
setTimeout(afterReady, 400);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const status = wx.goEasy.getConnectionStatus ? wx.goEasy.getConnectionStatus() : 'disconnected';
|
|
|
|
|
if (status === 'connected' || status === 'reconnected') {
|
|
|
|
|
const currentUserId = wx.goEasy.im ? wx.goEasy.im.userId : null;
|
|
|
|
|
if (currentUserId === targetUserId) {
|
|
|
|
|
afterReady();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
wx.goEasy.disconnect();
|
|
|
|
|
}
|
|
|
|
|
this.connectGoEasy(targetUserId);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
connectGoEasy(userId) {
|
|
|
|
|
const { currentUser } = this.data;
|
|
|
|
|
if (!currentUser) return;
|
|
|
|
|
const me = this.getMyChatProfile();
|
|
|
|
|
if (!me.id) return;
|
|
|
|
|
const defAvatar = getDefaultAvatarUrl(app);
|
|
|
|
|
wx.goEasy.connect({
|
|
|
|
|
id: userId,
|
|
|
|
|
data: {
|
|
|
|
|
name: currentUser.name,
|
|
|
|
|
avatar: currentUser.avatar || (app.globalData.ossImageUrl + app.globalData.morentouxiang)
|
|
|
|
|
name: me.name,
|
|
|
|
|
avatar: me.avatar || defAvatar,
|
|
|
|
|
},
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
this.subscribeGroupIfNeeded()
|
|
|
|
|
.then(() => {
|
|
|
|
|
this.setupAllListeners();
|
|
|
|
|
return this.loadHistory(true);
|
|
|
|
|
})
|
|
|
|
|
.then(() => this.markGroupMessageAsRead());
|
|
|
|
|
this.subscribeGroupIfNeeded().then(() => {
|
|
|
|
|
this.setupAllListeners();
|
|
|
|
|
this.loadHistory(true);
|
|
|
|
|
this.markGroupMessageAsRead();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onFailed: (error) => {
|
|
|
|
|
if (error.code === 408) {
|
|
|
|
|
@@ -238,17 +342,14 @@ Page({
|
|
|
|
|
|
|
|
|
|
subscribeGroupIfNeeded() {
|
|
|
|
|
const { groupId } = this.data;
|
|
|
|
|
if (!groupId || !wx.goEasy?.im) return Promise.resolve();
|
|
|
|
|
if (!groupId || !wx.goEasy?.im?.subscribeGroup) return Promise.resolve();
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
wx.goEasy.im.subscribeGroup({
|
|
|
|
|
groupIds: [groupId],
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
console.log(`[群聊页] 订阅成功: ${groupId}`);
|
|
|
|
|
resolve();
|
|
|
|
|
},
|
|
|
|
|
onFailed: (err) => {
|
|
|
|
|
console.error(`[群聊页] 订阅失败: ${groupId}`, err);
|
|
|
|
|
resolve();
|
|
|
|
|
groupIds: [String(groupId)],
|
|
|
|
|
onSuccess: () => resolve(true),
|
|
|
|
|
onFailed: (error) => {
|
|
|
|
|
console.warn('subscribeGroup failed', error);
|
|
|
|
|
resolve(false);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
@@ -267,23 +368,6 @@ Page({
|
|
|
|
|
if (this._deleteHandler) { wx.goEasy.im.off(wx.GoEasy.IM_EVENT.MESSAGE_DELETED, this._deleteHandler); this._deleteHandler = null; }
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initCurrentUser() {
|
|
|
|
|
const uid = wx.getStorageSync('uid');
|
|
|
|
|
const role = app.globalData.currentRole || 'normal';
|
|
|
|
|
const fresh = getFreshImUser(app, role, uid);
|
|
|
|
|
this.setData({ currentUser: {
|
|
|
|
|
id: fresh.id,
|
|
|
|
|
name: fresh.name,
|
|
|
|
|
avatar: fresh.avatar,
|
|
|
|
|
}});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fixAvatar(url) {
|
|
|
|
|
if (!url) return app.globalData.ossImageUrl + app.globalData.morentouxiang;
|
|
|
|
|
if (url.startsWith('http')) return url;
|
|
|
|
|
return app.globalData.ossImageUrl + url;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
isConnected() {
|
|
|
|
|
const s = wx.goEasy.getConnectionStatus ? wx.goEasy.getConnectionStatus() : 'disconnected';
|
|
|
|
|
return s === 'connected' || s === 'reconnected';
|
|
|
|
|
@@ -291,78 +375,110 @@ Page({
|
|
|
|
|
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
if (this.data.loadingHistory) return;
|
|
|
|
|
if (!this.data.hasMore) {
|
|
|
|
|
wx.showToast({ title: '没有更早的消息了', icon: 'none' });
|
|
|
|
|
this.setData({ isRefreshing: false });
|
|
|
|
|
wx.stopPullDownRefresh();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setData({ isRefreshing: true });
|
|
|
|
|
this.loadHistory(false).finally(() => { this.setData({ isRefreshing: false }); wx.stopPullDownRefresh(); });
|
|
|
|
|
this.loadHistory(false).finally(() => {
|
|
|
|
|
this.setData({ isRefreshing: false });
|
|
|
|
|
wx.stopPullDownRefresh();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadHistory(refresh) {
|
|
|
|
|
if (!refresh && !this.data.hasMore) return Promise.resolve();
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
this.setData({ loadingHistory: true });
|
|
|
|
|
const { groupId, lastTimestamp } = this.data;
|
|
|
|
|
const ts = refresh ? null : lastTimestamp;
|
|
|
|
|
wx.goEasy.im.history({
|
|
|
|
|
type: wx.GoEasy.IM_SCENE.GROUP,
|
|
|
|
|
id: groupId,
|
|
|
|
|
lastTimestamp: ts,
|
|
|
|
|
limit: 20,
|
|
|
|
|
onSuccess: (res) => {
|
|
|
|
|
let list = res.content || [];
|
|
|
|
|
list.sort((a, b) => a.timestamp - b.timestamp);
|
|
|
|
|
list.forEach((m, idx) => {
|
|
|
|
|
normalizeGroupMessage(m);
|
|
|
|
|
m.formattedTime = formatDate(m.timestamp);
|
|
|
|
|
if (idx === 0) m.showTime = true;
|
|
|
|
|
else m.showTime = (m.timestamp - list[idx-1].timestamp) / 60000 > 5;
|
|
|
|
|
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];
|
|
|
|
|
if (!refresh) {
|
|
|
|
|
for (let i = 0; i < final.length; i++) {
|
|
|
|
|
if (i === 0) final[i].showTime = true;
|
|
|
|
|
else final[i].showTime = (final[i].timestamp - final[i-1].timestamp) / 60000 > 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const ids = new Set();
|
|
|
|
|
const unique = [];
|
|
|
|
|
for (const m of final) { if (!ids.has(m.messageId)) { ids.add(m.messageId); unique.push(m); } }
|
|
|
|
|
const update = {
|
|
|
|
|
messages: unique,
|
|
|
|
|
hasMore: list.length >= 20,
|
|
|
|
|
lastTimestamp: unique.length ? unique[0].timestamp : lastTimestamp,
|
|
|
|
|
loadingHistory: false
|
|
|
|
|
};
|
|
|
|
|
if (refresh) update.scrollToView = 'msg-bottom';
|
|
|
|
|
this.setData(update);
|
|
|
|
|
resolve();
|
|
|
|
|
},
|
|
|
|
|
onFailed: () => { this.setData({ loadingHistory: false }); resolve(); }
|
|
|
|
|
});
|
|
|
|
|
mapHistoryMessage(m, idx, list) {
|
|
|
|
|
m = this.normalizeMessage(m);
|
|
|
|
|
m.formattedTime = formatDate(m.timestamp);
|
|
|
|
|
if (idx === 0) m.showTime = true;
|
|
|
|
|
else m.showTime = (m.timestamp - list[idx - 1].timestamp) / 60000 > 5;
|
|
|
|
|
if (!m.senderData) m.senderData = { name: '未知用户', avatar: '' };
|
|
|
|
|
return m;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async fetchGroupHistoryPage(gid, lastTimestamp) {
|
|
|
|
|
return fetchHistoryMessages({
|
|
|
|
|
scene: wx.GoEasy.IM_SCENE.GROUP,
|
|
|
|
|
id: gid,
|
|
|
|
|
lastTimestamp,
|
|
|
|
|
limit: 20,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async loadHistory(refresh) {
|
|
|
|
|
if (!refresh && !this.data.hasMore) return;
|
|
|
|
|
if (this.data.loadingHistory) return;
|
|
|
|
|
if (!this.data.groupId) return;
|
|
|
|
|
|
|
|
|
|
this.setData({ loadingHistory: true });
|
|
|
|
|
try {
|
|
|
|
|
const ready = await waitImConnected(app);
|
|
|
|
|
if (!ready) {
|
|
|
|
|
wx.showToast({ title: '消息服务未连接,请稍后重试', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.subscribeGroupIfNeeded();
|
|
|
|
|
|
|
|
|
|
const ts = refresh
|
|
|
|
|
? null
|
|
|
|
|
: getOldestHistoryTimestamp(this.data.messages, this.data.lastTimestamp);
|
|
|
|
|
if (!refresh && ts == null) {
|
|
|
|
|
this.setData({ hasMore: false });
|
|
|
|
|
wx.showToast({ title: '没有更早的消息了', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let raw = await this.fetchGroupHistoryPage(this.data.groupId, ts);
|
|
|
|
|
|
|
|
|
|
if (refresh && raw.length === 0 && isPairGroupId(this.data.groupId) && this.data.orderId) {
|
|
|
|
|
const legacyId = `group_${this.data.orderId}`;
|
|
|
|
|
if (legacyId !== this.data.groupId) {
|
|
|
|
|
raw = await this.fetchGroupHistoryPage(legacyId, ts);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const merged = mergeHistoryMessages({
|
|
|
|
|
incoming: raw,
|
|
|
|
|
existing: this.data.messages,
|
|
|
|
|
refresh,
|
|
|
|
|
limit: 20,
|
|
|
|
|
mapMessage: (m, idx, list) => this.mapHistoryMessage(m, idx, list),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
|
messages: merged.messages,
|
|
|
|
|
hasMore: merged.hasMore,
|
|
|
|
|
lastTimestamp: merged.lastTimestamp,
|
|
|
|
|
};
|
|
|
|
|
if (refresh) update.scrollToView = 'msg-bottom';
|
|
|
|
|
this.setData(update);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn('[群聊] 历史消息加载失败', e);
|
|
|
|
|
if (!refresh) {
|
|
|
|
|
wx.showToast({ title: '加载历史消息失败', icon: 'none' });
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({ loadingHistory: false });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
listenNewMsg() {
|
|
|
|
|
if (this._msgHandler) wx.goEasy.im.off(wx.GoEasy.IM_EVENT.GROUP_MESSAGE_RECEIVED, this._msgHandler);
|
|
|
|
|
this._msgHandler = (msg) => {
|
|
|
|
|
if (msg.groupId !== this.data.groupId) return;
|
|
|
|
|
normalizeGroupMessage(msg);
|
|
|
|
|
if (msg.type === 'order' && msg.payload) {
|
|
|
|
|
this.applyOrderCardPayload(msg.payload);
|
|
|
|
|
}
|
|
|
|
|
if (msg.senderId === this.data.currentUser.id && msg.type !== 'order') return;
|
|
|
|
|
if (msg.senderId === this.data.currentUser.id) return;
|
|
|
|
|
msg = this.normalizeMessage(msg);
|
|
|
|
|
msg.formattedTime = formatDate(msg.timestamp);
|
|
|
|
|
const msgs = this.data.messages;
|
|
|
|
|
if (msgs.some((m) => m.messageId === msg.messageId)) return;
|
|
|
|
|
const last = msgs.length ? msgs[msgs.length-1] : null;
|
|
|
|
|
msg.showTime = last ? (msg.timestamp - last.timestamp) / 60000 > 5 : true;
|
|
|
|
|
this.setData({ messages: [...msgs, msg], scrollToView: 'msg-bottom' });
|
|
|
|
|
this.markGroupMessageAsRead();
|
|
|
|
|
};
|
|
|
|
|
wx.goEasy.im.on(wx.GoEasy.IM_EVENT.GROUP_MESSAGE_RECEIVED, this._msgHandler);
|
|
|
|
|
this.markGroupMessageAsRead(); // ← 收到新消息就标记已读
|
|
|
|
|
this.markGroupMessageAsRead();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
markGroupMessageAsRead() {
|
|
|
|
|
@@ -397,21 +513,31 @@ Page({
|
|
|
|
|
|
|
|
|
|
chooseImage() {
|
|
|
|
|
const that = this;
|
|
|
|
|
wx.chooseImage({
|
|
|
|
|
count: 1, sizeType: ['compressed'], sourceType: ['album', 'camera'],
|
|
|
|
|
success(res) { that.setData({ pendingImage: res.tempFilePaths[0] }); }
|
|
|
|
|
wx.chooseMedia({
|
|
|
|
|
count: 1,
|
|
|
|
|
mediaType: ['image'],
|
|
|
|
|
sizeType: ['compressed'],
|
|
|
|
|
sourceType: ['album', 'camera'],
|
|
|
|
|
success(res) {
|
|
|
|
|
const file = (res.tempFiles && res.tempFiles[0]) || null;
|
|
|
|
|
if (!file || !file.tempFilePath) return;
|
|
|
|
|
that.setData({
|
|
|
|
|
pendingImage: file.tempFilePath,
|
|
|
|
|
pendingImageFile: that.buildImageFile(file.tempFilePath, file.size),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
fail() {
|
|
|
|
|
wx.showToast({ title: '选择图片失败', icon: 'none' });
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
clearPendingImage() { this.setData({ pendingImage: '' }); },
|
|
|
|
|
clearPendingImage() { this.setData({ pendingImage: '', pendingImageFile: null }); },
|
|
|
|
|
|
|
|
|
|
sendMessage() {
|
|
|
|
|
if (this.data.pendingImage) {
|
|
|
|
|
const file = this.data.pendingImage;
|
|
|
|
|
showConfirmByScene('chat_image_confirm', () => {
|
|
|
|
|
this.sendImageMsg(file);
|
|
|
|
|
this.setData({ pendingImage: '' });
|
|
|
|
|
});
|
|
|
|
|
this.sendImageMsg(this.data.pendingImage, this.data.pendingImageFile);
|
|
|
|
|
this.setData({ pendingImage: '', pendingImageFile: null });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const text = this.data.inputText.trim();
|
|
|
|
|
@@ -442,18 +568,61 @@ Page({
|
|
|
|
|
}
|
|
|
|
|
that.setData({ messages: [...msgs, localMsg], scrollToView: 'msg-bottom' });
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (messageId, status, serverMsg) => {
|
|
|
|
|
that.mergeServerMessage(messageId, status, serverMsg);
|
|
|
|
|
onSuccess: (messageId, status) => {
|
|
|
|
|
that.updateMsg(messageId, status);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
sendImageMsg(file) {
|
|
|
|
|
sendImageMsg(filePath, fileObj) {
|
|
|
|
|
const that = this;
|
|
|
|
|
const { currentUser, groupId, orderId, isCross, groupName, groupAvatar } = that.data;
|
|
|
|
|
if (!filePath || !currentUser || !groupId) return;
|
|
|
|
|
|
|
|
|
|
if (isCross === 0) {
|
|
|
|
|
if (!wx.goEasy || !wx.goEasy.im) {
|
|
|
|
|
wx.showToast({ title: '聊天未连接', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const avatar = resolveAvatarUrl(currentUser.avatar, app);
|
|
|
|
|
const name = currentUser.name || '用户';
|
|
|
|
|
const localId = `image-${Date.now()}`;
|
|
|
|
|
const imageFile = fileObj || this.buildImageFile(filePath, 0);
|
|
|
|
|
const localMsg = {
|
|
|
|
|
messageId: localId,
|
|
|
|
|
type: 'image',
|
|
|
|
|
timestamp: Date.now(),
|
|
|
|
|
senderId: currentUser.id,
|
|
|
|
|
groupId,
|
|
|
|
|
senderData: { name, avatar },
|
|
|
|
|
payload: { url: filePath },
|
|
|
|
|
status: 'sending',
|
|
|
|
|
formattedTime: formatDate(Date.now()),
|
|
|
|
|
showTime: this.needShow(Date.now()),
|
|
|
|
|
};
|
|
|
|
|
that.setData({ messages: [...that.data.messages, localMsg], scrollToView: 'msg-bottom' });
|
|
|
|
|
const toData = { name: groupName || '订单群聊', avatar: groupAvatar || avatar, isCross: 0 };
|
|
|
|
|
if (orderId) toData.orderId = orderId;
|
|
|
|
|
const imgMsg = wx.goEasy.im.createImageMessage({
|
|
|
|
|
file: imageFile,
|
|
|
|
|
to: { type: wx.GoEasy.IM_SCENE.GROUP, id: groupId, data: toData },
|
|
|
|
|
});
|
|
|
|
|
wx.goEasy.im.sendMessage({
|
|
|
|
|
message: imgMsg,
|
|
|
|
|
onSuccess: (sent) => that.mergeSentMessage(localId, sent),
|
|
|
|
|
onFailed: (error) => {
|
|
|
|
|
console.error('[群聊] 图片发送失败', error);
|
|
|
|
|
that.updateMsg(localId, 'failed');
|
|
|
|
|
wx.showToast({ title: '图片发送失败', icon: 'none' });
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendGroupMessage({
|
|
|
|
|
msgData: {
|
|
|
|
|
type: 'image',
|
|
|
|
|
filePath: file,
|
|
|
|
|
filePath,
|
|
|
|
|
currentUser: that.data.currentUser,
|
|
|
|
|
groupId: that.data.groupId,
|
|
|
|
|
orderId: that.data.orderId,
|
|
|
|
|
@@ -470,8 +639,11 @@ Page({
|
|
|
|
|
}
|
|
|
|
|
that.setData({ messages: [...msgs, localMsg], scrollToView: 'msg-bottom' });
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (messageId, status, serverMsg) => {
|
|
|
|
|
that.mergeServerMessage(messageId, status, serverMsg);
|
|
|
|
|
onSuccess: (messageId, status) => {
|
|
|
|
|
that.updateMsg(messageId, status);
|
|
|
|
|
if (status === 'failed') {
|
|
|
|
|
wx.showToast({ title: '图片发送失败', icon: 'none' });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
@@ -506,7 +678,7 @@ Page({
|
|
|
|
|
const msgId = e.currentTarget.dataset.messageid;
|
|
|
|
|
if (!msgId) return;
|
|
|
|
|
const msg = this.data.messages.find(m => m.messageId === msgId);
|
|
|
|
|
if (!msg || String(msg.messageId).startsWith('local-')) return;
|
|
|
|
|
if (!msg || msg.messageId.startsWith('local-')) return;
|
|
|
|
|
const itemList = ['复制'];
|
|
|
|
|
if (msg.senderId === this.data.currentUser.id && (Date.now() - msg.timestamp < 120000) && !msg.recalled) {
|
|
|
|
|
itemList.push('撤回');
|
|
|
|
|
@@ -575,7 +747,9 @@ Page({
|
|
|
|
|
orderId: order.dingdan_id,
|
|
|
|
|
jieshao: order.jieshao,
|
|
|
|
|
jine: order.jine,
|
|
|
|
|
beizhu: order.beizhu
|
|
|
|
|
beizhu: order.beizhu,
|
|
|
|
|
zhuangtai: order.zhuangtai,
|
|
|
|
|
nicheng: order.nicheng,
|
|
|
|
|
};
|
|
|
|
|
sendGroupMessage({
|
|
|
|
|
msgData: {
|
|
|
|
|
@@ -599,6 +773,10 @@ Page({
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (messageId, status) => {
|
|
|
|
|
that.updateMsg(messageId, status);
|
|
|
|
|
that.closeOrderSender();
|
|
|
|
|
if (status === 'success') {
|
|
|
|
|
wx.showToast({ title: '订单已发送', icon: 'success' });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
@@ -610,5 +788,24 @@ Page({
|
|
|
|
|
this.setData({ detailText: text, showDetailModal: true });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onKeyboardHeightChange(e) { this.setData({ keyboardHeight: e.detail.height }); }
|
|
|
|
|
onKeyboardHeightChange(e) { this.setData({ keyboardHeight: e.detail.height }); },
|
|
|
|
|
|
|
|
|
|
onAvatarError(e) {
|
|
|
|
|
const def = getDefaultAvatarUrl(app);
|
|
|
|
|
const idx = e.currentTarget.dataset.index;
|
|
|
|
|
if (idx != null && idx !== '') {
|
|
|
|
|
this.setData({ [`messages[${idx}].senderData.avatar`]: def });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onSelfAvatarError() {
|
|
|
|
|
const def = getDefaultAvatarUrl(app);
|
|
|
|
|
if (this.data.currentUser) {
|
|
|
|
|
this.setData({ 'currentUser.avatar': def });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
tapOrderBar() {
|
|
|
|
|
this.openOrderSender();
|
|
|
|
|
},
|
|
|
|
|
});
|