mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-11-10 02:49:03 +08:00
fix(im): 修复商家端客服台接收新消息不刷新会话列表与摘要的问题
This commit is contained in:
@@ -43,7 +43,8 @@ class Talk extends Base {
|
||||
super();
|
||||
this.sender_id = resource.fromUser; //发送
|
||||
this.receiver_id = resource.toUser; //接收
|
||||
this.talk_type = resource.messageType; //类型
|
||||
// 后端推送的 messageType 是消息内容类型(MESSAGE/PICTURE/GOODS/ORDERS),私聊会话类型固定为 1
|
||||
this.talk_type = Number(resource.talk_type) || 1;
|
||||
|
||||
this.resource = resource;
|
||||
|
||||
@@ -93,12 +94,22 @@ class Talk extends Base {
|
||||
return userId == this.getAccountId() ? "right" : "left";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息内容类型(MESSAGE/PICTURE/GOODS/ORDERS)
|
||||
*/
|
||||
getMessageType () {
|
||||
return this.resource.messageType || this.resource.msg_type || "MESSAGE";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天列表左侧的对话信息
|
||||
*/
|
||||
getTalkText () {
|
||||
let text = this.resource.content || this.resource.text;
|
||||
switch (this.resource.msg_type) {
|
||||
switch (this.getMessageType()) {
|
||||
case 'PICTURE':
|
||||
text = "[图片]";
|
||||
break;
|
||||
case 'GOODS':
|
||||
text = "[商品链接]";
|
||||
break;
|
||||
@@ -224,10 +235,15 @@ class Talk extends Base {
|
||||
}
|
||||
// console.log("%c 准备更新...UPDATE_TALK_ITEM ", "color:red");
|
||||
|
||||
const nowTime = parseTime(new Date());
|
||||
const msgText = this.getTalkText() || record.text;
|
||||
talkStore.UPDATE_TALK_ITEM({
|
||||
index_name: this.getIndexName(),
|
||||
msg_text: this.getTalkText() || record.text,
|
||||
updated_at: parseTime(new Date()),
|
||||
msg_text: msgText,
|
||||
lastTalkMessage: msgText,
|
||||
lastTalkTime: nowTime,
|
||||
lastMessageType: this.getMessageType(),
|
||||
updated_at: nowTime,
|
||||
});
|
||||
|
||||
if (this.talk_type == 1 && this.getAccountId() !== this.sender_id) {
|
||||
@@ -248,6 +264,7 @@ class Talk extends Base {
|
||||
useTalkStore().UPDATE_TALK_MESSAGE({
|
||||
index_name: this.getIndexName(),
|
||||
msg_text: this.getTalkText(),
|
||||
lastMessageType: this.getMessageType(),
|
||||
updated_at: parseTime(new Date()),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ export default {
|
||||
await this.createTalk(this.$route.query.id);
|
||||
} else if (typeof this.loadChatList === "function") {
|
||||
await this.loadChatList();
|
||||
} else if (typeof this.loadChatListInJs === "function") {
|
||||
await this.loadChatListInJs();
|
||||
}
|
||||
}
|
||||
if(this.$route.query.goodsId && this.$route.query.skuId && this.goodsParams){
|
||||
@@ -104,8 +106,8 @@ export default {
|
||||
items: result.map((item) => formatTalkItem(item)),
|
||||
});
|
||||
|
||||
// 判断
|
||||
if (this.$route.query.id) {
|
||||
// 判断(仅在挂载了 clickTab 的页面组件实例上自动切换会话)
|
||||
if (this.$route.query.id && typeof this.clickTab === "function") {
|
||||
let takeData, takeIndex;
|
||||
result.forEach((take, index) => {
|
||||
if (take.id == this.$route.query.id) {
|
||||
@@ -113,9 +115,13 @@ export default {
|
||||
takeIndex = index;
|
||||
}
|
||||
});
|
||||
this.$nextTick(() =>
|
||||
this.clickTab(this.$route.query.id, takeData, takeIndex)
|
||||
);
|
||||
if (typeof this.$nextTick === "function") {
|
||||
this.$nextTick(() =>
|
||||
this.clickTab(this.$route.query.id, takeData, takeIndex)
|
||||
);
|
||||
} else {
|
||||
this.clickTab(this.$route.query.id, takeData, takeIndex);
|
||||
}
|
||||
}
|
||||
}).finally(() => {
|
||||
this.loadStatus = 1;
|
||||
|
||||
@@ -71,11 +71,17 @@ export const useTalkStore = defineStore("talks", {
|
||||
UPDATE_TALK_MESSAGE(resource) {
|
||||
let enableGetTalkList = true;
|
||||
this.items.forEach((item) => {
|
||||
if (item.userId == resource.index_name.split("_")[1]) {
|
||||
if (
|
||||
item.index_name === resource.index_name ||
|
||||
item.userId == resource.index_name.split("_")[1]
|
||||
) {
|
||||
item.unread++;
|
||||
item.msg_text = resource.msg_text;
|
||||
item.lastTalkTime = resource.updated_at;
|
||||
item.lastTalkMessage = resource.msg_text;
|
||||
if (resource.lastMessageType) {
|
||||
item.lastMessageType = resource.lastMessageType;
|
||||
}
|
||||
item.updated_at = resource.updated_at;
|
||||
enableGetTalkList = false;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ const mixinCtx = {
|
||||
return router.currentRoute.value;
|
||||
},
|
||||
};
|
||||
mixinCtx.loadChatListInJs = MainMixin.methods.loadChatListInJs.bind(mixinCtx);
|
||||
mixinCtx.loadStoreChatList = MainMixin.methods.loadStoreChatList.bind(mixinCtx);
|
||||
|
||||
export function setRefreshView(fn) {
|
||||
refreshViewFn = fn;
|
||||
|
||||
@@ -113,8 +113,9 @@
|
||||
</div>
|
||||
<div class="talk-message">
|
||||
<span v-if="item.lastMessageType === 'MESSAGE'" v-html="textReplaceEmoji(item.lastTalkMessage)"></span>
|
||||
<span v-if="item.lastMessageType === 'GOODS'">[商品链接]</span>
|
||||
<span v-if="item.lastMessageType === 'ORDER'">[订单链接]</span>
|
||||
<span v-else-if="item.lastMessageType === 'PICTURE'">[图片]</span>
|
||||
<span v-else-if="item.lastMessageType === 'GOODS'">[商品链接]</span>
|
||||
<span v-else-if="item.lastMessageType === 'ORDERS' || item.lastMessageType === 'ORDER'">[订单链接]</span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<template v-if="index_name != item.index_name && item.draft_text">
|
||||
@@ -428,7 +429,7 @@ function clickTab(id, val, index) {
|
||||
if (id == index_name.value.split("_")[1]) {
|
||||
talkStore.UPDATE_TALK_ITEM({
|
||||
userId: id,
|
||||
index_name: "MESSAGE_" + index_name.value.split("_")[1],
|
||||
index_name: index_name.value,
|
||||
unread: 0,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user