|
@@ -99,6 +99,9 @@ export default {
|
|
|
VideoPlayer,
|
|
|
UserDetail
|
|
|
},
|
|
|
+ props: {
|
|
|
+ showQw: Boolean
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
contactName:'',
|
|
@@ -148,7 +151,10 @@ export default {
|
|
|
detail: {
|
|
|
title: '',
|
|
|
open: false
|
|
|
- }
|
|
|
+ },
|
|
|
+ messagePollingTimer: null, // 定时器引用
|
|
|
+ pollingInterval: 5000, // 轮询间隔(毫秒)
|
|
|
+ lastMessageIdMap: {}, // 记录每个会话最后一条消息ID
|
|
|
};
|
|
|
},
|
|
|
created(){
|
|
@@ -165,6 +171,19 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ showQw(nv, ov) {
|
|
|
+ if (nv) {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.IMUI.messageViewToBottom();
|
|
|
+ });
|
|
|
+ this.startMessagePolling()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.stopMessagePolling();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted() {
|
|
|
this.$watch('appKey', (newValue, oldValue) => {
|
|
|
if (newValue) {
|
|
@@ -185,7 +204,12 @@ export default {
|
|
|
}
|
|
|
]);
|
|
|
IMUI.initEmoji(EmojiData);
|
|
|
+ IMUI.initEditorTools([])
|
|
|
|
|
|
+ this.startMessagePolling(); // 启动定时轮询
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ this.stopMessagePolling();
|
|
|
},
|
|
|
methods: {
|
|
|
// 切换企微账号
|
|
@@ -206,6 +230,12 @@ export default {
|
|
|
const IMUI = this.$refs.IMUI;
|
|
|
getConversations(this.qwUser.id).then(response => {
|
|
|
this.conversationData = response.data;
|
|
|
+ // 初始化msgId
|
|
|
+ if (Array.isArray(response.data)) {
|
|
|
+ response.data.forEach(conversation => {
|
|
|
+ this.lastMessageIdMap[conversation.conversationId] = conversation.msgId || 0;
|
|
|
+ });
|
|
|
+ }
|
|
|
IMUI.initConversations(response.data);
|
|
|
const fstConversation = this.conversationData[0];
|
|
|
if(fstConversation) {
|
|
@@ -459,7 +489,43 @@ export default {
|
|
|
setTimeout(() => {
|
|
|
this.$refs.userDetail.getDetail(sessionId);
|
|
|
}, 1);
|
|
|
- }
|
|
|
+ },
|
|
|
+ startMessagePolling() {
|
|
|
+ this.stopMessagePolling(); // 避免重复启动
|
|
|
+ this.messagePollingTimer = setInterval(() => {
|
|
|
+ this.fetchAllConversationsLatestMessages();
|
|
|
+ }, this.pollingInterval);
|
|
|
+ },
|
|
|
+ stopMessagePolling() {
|
|
|
+ if (this.messagePollingTimer) {
|
|
|
+ clearInterval(this.messagePollingTimer);
|
|
|
+ this.messagePollingTimer = null;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fetchAllConversationsLatestMessages() {
|
|
|
+ if (!this.qwUser || !this.conversationData) return;
|
|
|
+ this.conversationData.forEach(conversation => {
|
|
|
+ const lastMsgId = this.lastMessageIdMap[conversation.conversationId] || 0;
|
|
|
+ const params = {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 20,
|
|
|
+ conversationId: conversation.conversationId,
|
|
|
+ userId: this.qwUser.id,
|
|
|
+ msgId: lastMsgId // 用消息ID拉取新消息
|
|
|
+ };
|
|
|
+ getMessageList(params).then(response => {
|
|
|
+ if (response.code === 200 && response.data && response.data.list) {
|
|
|
+ response.data.list.forEach(msg => {
|
|
|
+ // 更新lastMessageIdMap
|
|
|
+ if (!this.lastMessageIdMap[conversation.conversationId] || msg.id > this.lastMessageIdMap[conversation.conversationId]) {
|
|
|
+ this.lastMessageIdMap[conversation.conversationId] = msg.id;
|
|
|
+ }
|
|
|
+ this.appendMessageAction(msg);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|