45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
/* contacts.js */
|
|
const restapi = getApp().globalData.restapi
|
|
import IMService from '../../static/lib/imservice.js';
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
groups:[],
|
|
friends:[],
|
|
},
|
|
onShow () {
|
|
let currentUser = wx.getStorageSync("currentUser");
|
|
if(!currentUser){
|
|
wx.redirectTo({
|
|
url : '../login/login'
|
|
});
|
|
return;
|
|
}
|
|
|
|
if(wx.im.getStatus() === 'disconnected') {
|
|
app.globalData.imService= new IMService(wx.im);
|
|
app.globalData.imService.connectIM(currentUser);
|
|
}
|
|
let currentUsers = app.globalData.imService.currentUser;
|
|
let groups = restapi.findGroups(currentUsers);
|
|
let friends = restapi.findFriends(currentUsers);
|
|
this.setData({
|
|
groups: groups,
|
|
friends: friends,
|
|
});
|
|
},
|
|
onUnload(){
|
|
app.globalData.imService.disconnect();
|
|
},
|
|
enterChat (e) {//进入私聊
|
|
let type = e.currentTarget.dataset.type;
|
|
let conversation = e.currentTarget.dataset.conversation;
|
|
let path = type === wx.GoEasyIM.SCENE.PRIVATE?
|
|
'../chat/privateChat/privateChat?to='+conversation.uuid
|
|
:'../chat/groupChat/groupChat?to='+ conversation.uuid;
|
|
wx.navigateTo({
|
|
url : path
|
|
});
|
|
}
|
|
}) |