|
@@ -1,7 +1,7 @@
|
|
<template>
|
|
<template>
|
|
<div style="width: 100%;height: 100%">
|
|
<div style="width: 100%;height: 100%">
|
|
|
|
|
|
- <el-tabs type="card" v-model="appKey" @tab-click="qwUserChange">
|
|
|
|
|
|
+ <el-tabs class="im-tabs" type="card" v-model="appKey" @tab-click="qwUserChange">
|
|
<el-tab-pane
|
|
<el-tab-pane
|
|
v-for="item in qwUserList"
|
|
v-for="item in qwUserList"
|
|
:key="item.id"
|
|
:key="item.id"
|
|
@@ -91,6 +91,8 @@ import EmojiData from "@/components/LemonUI/database/emoji";
|
|
import '@/components/LemonUI/index.css';
|
|
import '@/components/LemonUI/index.css';
|
|
import VideoPlayer from '@/components/VideoPlayer/VueAliplayer.vue'
|
|
import VideoPlayer from '@/components/VideoPlayer/VueAliplayer.vue'
|
|
import UserDetail from "@/views/qw/qwChat/userDetail/index.vue";
|
|
import UserDetail from "@/views/qw/qwChat/userDetail/index.vue";
|
|
|
|
+import {ImSocket} from "@/utils/ImSocket";
|
|
|
|
+import {getToken} from '@/utils/auth'
|
|
|
|
|
|
let pages = {};
|
|
let pages = {};
|
|
export default {
|
|
export default {
|
|
@@ -152,9 +154,7 @@ export default {
|
|
title: '',
|
|
title: '',
|
|
open: false
|
|
open: false
|
|
},
|
|
},
|
|
- messagePollingTimer: null, // 定时器引用
|
|
|
|
- pollingInterval: 5000, // 轮询间隔(毫秒)
|
|
|
|
- lastMessageIdMap: {}, // 记录每个会话最后一条消息ID
|
|
|
|
|
|
+ imSocket: null,
|
|
};
|
|
};
|
|
},
|
|
},
|
|
created(){
|
|
created(){
|
|
@@ -166,6 +166,7 @@ export default {
|
|
this.appKey = this.qwUser.appKey;
|
|
this.appKey = this.qwUser.appKey;
|
|
this.setQwUserInfo();
|
|
this.setQwUserInfo();
|
|
this.getConversation();
|
|
this.getConversation();
|
|
|
|
+ this.initImSocket(this.qwUser.companyId)
|
|
}else {
|
|
}else {
|
|
this.qwUser={};
|
|
this.qwUser={};
|
|
}
|
|
}
|
|
@@ -177,19 +178,10 @@ export default {
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
this.$refs.IMUI.messageViewToBottom();
|
|
this.$refs.IMUI.messageViewToBottom();
|
|
});
|
|
});
|
|
- this.startMessagePolling()
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- this.stopMessagePolling();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- this.$watch('appKey', (newValue, oldValue) => {
|
|
|
|
- if (newValue) {
|
|
|
|
- console.log("appkey====",newValue);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
this.showQW=true;
|
|
this.showQW=true;
|
|
const IMUI = this.$refs.IMUI;
|
|
const IMUI = this.$refs.IMUI;
|
|
|
|
|
|
@@ -204,13 +196,27 @@ export default {
|
|
}
|
|
}
|
|
]);
|
|
]);
|
|
IMUI.initEmoji(EmojiData);
|
|
IMUI.initEmoji(EmojiData);
|
|
-
|
|
|
|
- this.startMessagePolling(); // 启动定时轮询
|
|
|
|
},
|
|
},
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
- this.stopMessagePolling();
|
|
|
|
|
|
+ if (this.imSocket) {
|
|
|
|
+ this.imSocket.close();
|
|
|
|
+ }
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
|
|
+ initImSocket(companyId) {
|
|
|
|
+ this.imSocket = new ImSocket(`ws://127.0.0.1:8667/qwImSocket/${companyId}?token=${getToken()}`);
|
|
|
|
+ this.imSocket.onMessage(data => {
|
|
|
|
+ const { IMUI } = this.$refs;
|
|
|
|
+ let message = JSON.parse(data);
|
|
|
|
+ this.appendRemoteMessage(message)
|
|
|
|
+ let conversation = IMUI.findConversation(message.toContactId);
|
|
|
|
+ if (conversation.msgId) {
|
|
|
|
+ conversation.lastSendTime = message.sendTime;
|
|
|
|
+ conversation.lastContent = message.content;
|
|
|
|
+ IMUI.topPopConversations(conversation);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
// 切换企微账号
|
|
// 切换企微账号
|
|
qwUserChange(tab, event){
|
|
qwUserChange(tab, event){
|
|
this.appKey = tab.name;
|
|
this.appKey = tab.name;
|
|
@@ -219,7 +225,6 @@ export default {
|
|
this.getConversation(); //获取会话信息
|
|
this.getConversation(); //获取会话信息
|
|
this.setQwUserInfo();
|
|
this.setQwUserInfo();
|
|
},
|
|
},
|
|
-
|
|
|
|
setQwUserInfo(){
|
|
setQwUserInfo(){
|
|
this.userData.id=this.qwUser.id;
|
|
this.userData.id=this.qwUser.id;
|
|
this.userData.displayName=this.qwUser.qwUserName;
|
|
this.userData.displayName=this.qwUser.qwUserName;
|
|
@@ -229,12 +234,6 @@ export default {
|
|
const IMUI = this.$refs.IMUI;
|
|
const IMUI = this.$refs.IMUI;
|
|
getConversations(this.qwUser.id).then(response => {
|
|
getConversations(this.qwUser.id).then(response => {
|
|
this.conversationData = response.data;
|
|
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);
|
|
IMUI.initConversations(response.data);
|
|
const fstConversation = this.conversationData[0];
|
|
const fstConversation = this.conversationData[0];
|
|
if(fstConversation) {
|
|
if(fstConversation) {
|
|
@@ -352,6 +351,14 @@ export default {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ // image
|
|
|
|
+ else if(message.type === "image"){
|
|
|
|
+ console.log("Event:image-click", message, next, file)
|
|
|
|
+ }
|
|
|
|
+ // file
|
|
|
|
+ else if(message.type === "file"){
|
|
|
|
+ console.log("Event:file-click", message, next, file)
|
|
|
|
+ }
|
|
},
|
|
},
|
|
handleMenuAvatarClick() {
|
|
handleMenuAvatarClick() {
|
|
console.log("Event:menu-avatar-click");
|
|
console.log("Event:menu-avatar-click");
|
|
@@ -489,42 +496,6 @@ export default {
|
|
this.$refs.userDetail.getDetail(sessionId);
|
|
this.$refs.userDetail.getDetail(sessionId);
|
|
}, 1);
|
|
}, 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>
|
|
</script>
|
|
@@ -569,6 +540,15 @@ export default {
|
|
margin-top: 0 !important;
|
|
margin-top: 0 !important;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+::v-deep .im-tabs {
|
|
|
|
+ .el-tabs__header {
|
|
|
|
+ margin: 0 !important;
|
|
|
|
+ .el-tabs__item {
|
|
|
|
+ border-bottom: 0 !important;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
</style>
|
|
</style>
|
|
|
|
|
|
|
|
|