|
@@ -104,9 +104,10 @@ import store from "@/store";
|
|
import { getQrCode } from '@/api/qw/login';
|
|
import { getQrCode } from '@/api/qw/login';
|
|
import { getDeviceId} from '@/api/qw/account';
|
|
import { getDeviceId} from '@/api/qw/account';
|
|
import LemonMessageVoice from "@/components/LemonUI/components/message/voice";
|
|
import LemonMessageVoice from "@/components/LemonUI/components/message/voice";
|
|
-import { getContactsByUser,getConversation,getMessageList} from '@/api/qw/im';
|
|
|
|
|
|
+import { getContactsByUser,getConversations,getMessageList,getConversation,sendTextMsg} from '@/api/qw/im';
|
|
import ContactsData from "@/components/LemonUI/database/contacts";
|
|
import ContactsData from "@/components/LemonUI/database/contacts";
|
|
import MessagesData from "@/components/LemonUI/database/messages";
|
|
import MessagesData from "@/components/LemonUI/database/messages";
|
|
|
|
+import Conversations from "@/components/LemonUI/database/conversations";
|
|
import EmojiData from "@/components/LemonUI/database/emoji";
|
|
import EmojiData from "@/components/LemonUI/database/emoji";
|
|
import '@/components/LemonUI/index.css';
|
|
import '@/components/LemonUI/index.css';
|
|
let pages = {};
|
|
let pages = {};
|
|
@@ -252,6 +253,7 @@ export default {
|
|
},
|
|
},
|
|
contactData:null,
|
|
contactData:null,
|
|
conversationData:null,
|
|
conversationData:null,
|
|
|
|
+ isFromLogin:false,
|
|
windowWidth: document.documentElement.clientWidth*0.65, //实时屏幕宽度
|
|
windowWidth: document.documentElement.clientWidth*0.65, //实时屏幕宽度
|
|
windowHeight: document.documentElement.clientHeight*0.7, //实时屏幕高度
|
|
windowHeight: document.documentElement.clientHeight*0.7, //实时屏幕高度
|
|
queryParams: {
|
|
queryParams: {
|
|
@@ -262,7 +264,7 @@ export default {
|
|
};
|
|
};
|
|
},
|
|
},
|
|
created(){
|
|
created(){
|
|
- this.initSocket();
|
|
|
|
|
|
+
|
|
// this.$store.dispatch('qwLoginOut').then(() => {
|
|
// this.$store.dispatch('qwLoginOut').then(() => {
|
|
// });
|
|
// });
|
|
},
|
|
},
|
|
@@ -275,6 +277,11 @@ export default {
|
|
}, 2000);
|
|
}, 2000);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ console.log("qxj qwUserId:"+JSON.stringify(this.qwUser));
|
|
|
|
+ this.isFromLogin=this.$route.query.isFromLogin;
|
|
|
|
+ if(this.isFromLogin!=1){
|
|
|
|
+ this.initSocket(this.qwUser.deviceId);
|
|
|
|
+ }
|
|
this.UserData.id=this.qwUser.userId;
|
|
this.UserData.id=this.qwUser.userId;
|
|
this.UserData.displayName=this.qwUser.nickName;
|
|
this.UserData.displayName=this.qwUser.nickName;
|
|
this.UserData.avatar=this.qwUser.avatar;
|
|
this.UserData.avatar=this.qwUser.avatar;
|
|
@@ -315,21 +322,20 @@ export default {
|
|
};
|
|
};
|
|
const IMUI = this.$refs.IMUI;
|
|
const IMUI = this.$refs.IMUI;
|
|
|
|
|
|
- var conversationData = ContactsData.filter(item => item.id<=1688856679458971);
|
|
|
|
|
|
+ var conversationData = Conversations.filter(item => item.conversationId<=1688856679458971);
|
|
conversationData.sort((a1, a2) => {
|
|
conversationData.sort((a1, a2) => {
|
|
return a2.lastSendTime - a1.lastSendTime;
|
|
return a2.lastSendTime - a1.lastSendTime;
|
|
});
|
|
});
|
|
|
|
|
|
- this.getContacts(); //获取联系人信息
|
|
|
|
- this.getConversation(); //获取会话信息
|
|
|
|
-
|
|
|
|
- // IMUI.initContacts(ContactsData);
|
|
|
|
-
|
|
|
|
- // IMUI.initConversations(conversationData);
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ // IMUI.initContacts(ContactsData);
|
|
|
|
+ // IMUI.initConversations(conversationData);
|
|
// setTimeout(() => {
|
|
// setTimeout(() => {
|
|
// IMUI.changeContact(1688856679458971);
|
|
// IMUI.changeContact(1688856679458971);
|
|
// }, 500);
|
|
// }, 500);
|
|
|
|
+
|
|
|
|
+ this.getContacts(); //获取联系人信息
|
|
|
|
+ this.getConversation(); //获取会话信息
|
|
|
|
|
|
IMUI.initMenus([
|
|
IMUI.initMenus([
|
|
{
|
|
{
|
|
@@ -391,13 +397,20 @@ export default {
|
|
},
|
|
},
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
- initSocket() {
|
|
|
|
|
|
+ initSocket(userId) {
|
|
let that=this;
|
|
let that=this;
|
|
- if(!!this.qwIm.socket){
|
|
|
|
|
|
+ console.log("qxj socket:"+this.qwIm.socket);
|
|
|
|
+ if(!!this.qwIm.socket){
|
|
|
|
+ this.qwIm.initSocket(userId,true);
|
|
|
|
+ // 监听socket连接
|
|
|
|
+ this.qwIm.socket.onopen = function() {
|
|
|
|
+ console.log("socket连接成功");
|
|
|
|
+ };
|
|
this.qwIm.socket.onerror = function() {
|
|
this.qwIm.socket.onerror = function() {
|
|
console.log("连接错误")
|
|
console.log("连接错误")
|
|
};
|
|
};
|
|
// 监听socket消息
|
|
// 监听socket消息
|
|
|
|
+ const IMUI = this.$refs.IMUI;
|
|
this.qwIm.socket.onmessage = function(res) {
|
|
this.qwIm.socket.onmessage = function(res) {
|
|
var data=JSON.parse(res.data);
|
|
var data=JSON.parse(res.data);
|
|
console.log("收到服务端内容", JSON.stringify(data));
|
|
console.log("收到服务端内容", JSON.stringify(data));
|
|
@@ -409,7 +422,21 @@ export default {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
that.$router.push({path:'/qw/qwLogin'});
|
|
that.$router.push({path:'/qw/qwLogin'});
|
|
}, 2000);
|
|
}, 2000);
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ if(data.cmd=="receiveMsg"){
|
|
|
|
+ var msgData=JSON.parse(data.msg);
|
|
|
|
+ if(!IMUI.hasConversation(msgData.toContactId)){ //收到新消息时是最新的会话,添加该会话
|
|
|
|
+ let queryParams={conversationId:msgData.toContactId,userId:that.qwUser.userId}
|
|
|
|
+ getConversation(queryParams).then(response => {
|
|
|
|
+ if(response.code==200){
|
|
|
|
+ var conversation=response.data;
|
|
|
|
+ IMUI.appendConversation(conversation);
|
|
|
|
+ that.appendMessageAction(msgData);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ that.appendMessageAction(msgData);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
};
|
|
};
|
|
// 监听socket消息
|
|
// 监听socket消息
|
|
@@ -418,6 +445,7 @@ export default {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+
|
|
getContacts(){
|
|
getContacts(){
|
|
getContactsByUser(this.qwUser.userId).then(response => {
|
|
getContactsByUser(this.qwUser.userId).then(response => {
|
|
this.contactData = response.data;
|
|
this.contactData = response.data;
|
|
@@ -428,7 +456,7 @@ export default {
|
|
getConversation(){
|
|
getConversation(){
|
|
let that=this;
|
|
let that=this;
|
|
const IMUI = this.$refs.IMUI;
|
|
const IMUI = this.$refs.IMUI;
|
|
- getConversation(this.qwUser.userId).then(response => {
|
|
|
|
|
|
+ getConversations(this.qwUser.userId).then(response => {
|
|
this.conversationData = response.data;
|
|
this.conversationData = response.data;
|
|
IMUI.initConversations(response.data);
|
|
IMUI.initConversations(response.data);
|
|
var fstConversation=this.conversationData[0];
|
|
var fstConversation=this.conversationData[0];
|
|
@@ -443,8 +471,32 @@ export default {
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ appendMessageAction(msgData){
|
|
|
|
+ if(msgData.type=="text"){ //文本
|
|
|
|
+ const message = {
|
|
|
|
+ id: msgData.id,
|
|
|
|
+ status: msgData.status,
|
|
|
|
+ type: msgData.type,
|
|
|
|
+ sendTime: msgData.sendTime,
|
|
|
|
+ content: msgData.content,
|
|
|
|
+ params1: "1",
|
|
|
|
+ params2: "2",
|
|
|
|
+ toContactId: msgData.toContactId,
|
|
|
|
+ fromUser: msgData.fromUser,
|
|
|
|
+ };
|
|
|
|
+ this.appendRemoteMessage(message);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ sendTextMsg(){
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
messageTimeFormat(time) {
|
|
messageTimeFormat(time) {
|
|
- console.log("qxj messageTimeFormat:"+time);
|
|
|
|
|
|
+ //console.log("qxj messageTimeFormat:"+time);
|
|
return this.friendlyDate(time);
|
|
return this.friendlyDate(time);
|
|
},
|
|
},
|
|
changeTheme() {
|
|
changeTheme() {
|
|
@@ -488,14 +540,15 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
// setTimeout(() => {
|
|
// setTimeout(() => {
|
|
// let isEnd = true;
|
|
// let isEnd = true;
|
|
- // next(MessagesData[contact.id], isEnd);
|
|
|
|
|
|
+ // next(MessagesData[contact.conversationId], isEnd);
|
|
// }, 2000);
|
|
// }, 2000);
|
|
|
|
|
|
},
|
|
},
|
|
handleChangeContact(contact, instance) {
|
|
handleChangeContact(contact, instance) {
|
|
- console.log("qxj contact:"+JSON.stringify(contact));
|
|
|
|
|
|
+ //console.log("qxj contact:"+JSON.stringify(contact));
|
|
if (!pages[contact.conversationId]){
|
|
if (!pages[contact.conversationId]){
|
|
pages[contact.conversationId] =1;
|
|
pages[contact.conversationId] =1;
|
|
}
|
|
}
|
|
@@ -505,10 +558,20 @@ export default {
|
|
instance.closeDrawer();
|
|
instance.closeDrawer();
|
|
},
|
|
},
|
|
handleSend(message, next, file) {
|
|
handleSend(message, next, file) {
|
|
- console.log(message, next, file);
|
|
|
|
- setTimeout(() => {
|
|
|
|
- next();
|
|
|
|
- }, 1000);
|
|
|
|
|
|
+ console.log(JSON.stringify(message));
|
|
|
|
+ var params={};
|
|
|
|
+ if(message.type=="text"){ //text image voice video
|
|
|
|
+ params={"conversationId":message.toContactId,"deviceId":this.qwUser.deviceId,"userId":this.qwUser.userId,"content":message.content};
|
|
|
|
+ sendTextMsg(params).then(response => {
|
|
|
|
+ if(response.code==200){
|
|
|
|
+ next();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // setTimeout(() => {
|
|
|
|
+ // next();
|
|
|
|
+ // }, 1000);
|
|
},
|
|
},
|
|
handleMenuAvatarClick() {
|
|
handleMenuAvatarClick() {
|
|
console.log("Event:menu-avatar-click");
|
|
console.log("Event:menu-avatar-click");
|
|
@@ -618,6 +681,11 @@ export default {
|
|
};
|
|
};
|
|
IMUI.appendMessage(message, true);
|
|
IMUI.appendMessage(message, true);
|
|
},
|
|
},
|
|
|
|
+ appendRemoteMessage(message) { //从服务端返回的消息
|
|
|
|
+ const { IMUI } = this.$refs;
|
|
|
|
+ IMUI.appendMessage(message, true);
|
|
|
|
+ },
|
|
|
|
+
|
|
updateContact() {
|
|
updateContact() {
|
|
this.$refs.IMUI.updateContact({
|
|
this.$refs.IMUI.updateContact({
|
|
id: "contact-3",
|
|
id: "contact-3",
|
|
@@ -633,11 +701,6 @@ export default {
|
|
openCustomContainer() {
|
|
openCustomContainer() {
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
},
|
|
},
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|