Commit 84f8399a by 施宇

1111

parent 55cddca5
...@@ -15,7 +15,8 @@ App({ ...@@ -15,7 +15,8 @@ App({
token: wx.getStorageSync('access_token'), token: wx.getStorageSync('access_token'),
isIPX: false, //是否为iphone X isIPX: false, //是否为iphone X
customerNum: "001", customerNum: "001",
customerName: "IC助手客服" customerName: "IC助手客服",
isRelogin:true,//登入环信失败后是否重新登入,只允许重新登入一次
}, },
getImUser: chat.getImUser, getImUser: chat.getImUser,
addChatMember: function (id,userId) {//id为环信id userId为账户id addChatMember: function (id,userId) {//id为环信id userId为账户id
......
...@@ -30,12 +30,12 @@ Page({ ...@@ -30,12 +30,12 @@ Page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function(options) { onLoad: function (options) {
if (judgeToken(true)) { if (judgeToken(true)) {
let me = this; let me = this;
let my = wx.getStorageSync("myUsername"); let my = wx.getStorageSync("myUsername");
//监听未读消息数 //监听未读消息数
disp.on("em.xmpp.unreadspot", function(message) { disp.on("em.xmpp.unreadspot", function (message) {
if (getApp().globalData.customerNum != my) { if (getApp().globalData.customerNum != my) {
me.getCustom(); me.getCustom();
} }
...@@ -47,7 +47,7 @@ Page({ ...@@ -47,7 +47,7 @@ Page({
} }
}, },
getCustom: function() { getCustom: function () {
let my = wx.getStorageSync("myUsername"); let my = wx.getStorageSync("myUsername");
let companyName = wx.getStorageSync("company_name") || ''; let companyName = wx.getStorageSync("company_name") || '';
let userId = wx.getStorageSync("user_id") || ''; let userId = wx.getStorageSync("user_id") || '';
...@@ -120,7 +120,7 @@ Page({ ...@@ -120,7 +120,7 @@ Page({
return array; return array;
}, },
into_singleChatRoom: function(detail) { into_singleChatRoom: function (detail) {
let my = wx.getStorageSync("myUsername"); let my = wx.getStorageSync("myUsername");
let nameList = { let nameList = {
myName: my, myName: my,
...@@ -137,14 +137,14 @@ Page({ ...@@ -137,14 +137,14 @@ Page({
url: "/pages/detail/chat/index?username=" + JSON.stringify(nameList) url: "/pages/detail/chat/index?username=" + JSON.stringify(nameList)
}); });
}, },
into_chatRoom: function(event) { into_chatRoom: function (event) {
let detail = event.currentTarget.dataset.item; let detail = event.currentTarget.dataset.item;
this.into_singleChatRoom(detail) this.into_singleChatRoom(detail)
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function() { onReady: function () {
}, },
...@@ -152,7 +152,7 @@ Page({ ...@@ -152,7 +152,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function() { onShow: function () {
let my = wx.getStorageSync("myUsername"); let my = wx.getStorageSync("myUsername");
let token = wx.getStorageSync('access_token') || ''; let token = wx.getStorageSync('access_token') || '';
let im = wx.getStorageSync('im') || ''; let im = wx.getStorageSync('im') || '';
...@@ -180,36 +180,36 @@ Page({ ...@@ -180,36 +180,36 @@ Page({
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide: function() { onHide: function () {
}, },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload: function() { onUnload: function () {
}, },
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh: function() { onPullDownRefresh: function () {
}, },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom: function() { onReachBottom: function () {
}, },
getSys: function(token) { getSys: function (token) {
let me = this; let me = this;
getData(apis.userSysmsg, 'get', { getData(apis.userSysmsg, 'get', {
token: token, token: token,
"limit": 1, "limit": 1,
"page": 1, "page": 1,
}, function(res) { }, function (res) {
if (res.errcode == 0) { if (res.errcode == 0) {
me.setData({ me.setData({
count: res.data.act_unread_msg + res.data.sys_unread_msg count: res.data.act_unread_msg + res.data.sys_unread_msg
...@@ -218,13 +218,13 @@ Page({ ...@@ -218,13 +218,13 @@ Page({
} }
}, true) }, true)
}, },
getAct: function(token, sysarr) { getAct: function (token, sysarr) {
let me = this; let me = this;
getData(apis.userActmsg, 'get', { getData(apis.userActmsg, 'get', {
token: token, token: token,
"limit": 1, "limit": 1,
"page": 1, "page": 1,
}, function(res) { }, function (res) {
if (res.errcode == 0) { if (res.errcode == 0) {
let actarr = res.data['act_msg'].data; let actarr = res.data['act_msg'].data;
let nowDate = Date.parse(new Date()); let nowDate = Date.parse(new Date());
...@@ -258,13 +258,13 @@ Page({ ...@@ -258,13 +258,13 @@ Page({
}, false) }, false)
}, },
deleteChatItem: function(e) { //拉黑 deleteChatItem: function (e) { //拉黑
this.del_chat(e, 2) this.del_chat(e, 2)
}, },
deleteChat: function(e) { //删除记录 deleteChat: function (e) { //删除记录
this.del_chat(e, 1) this.del_chat(e, 1)
}, },
del_chat: function(event, type) { del_chat: function (event, type) {
let detail = event.currentTarget.dataset.item; let detail = event.currentTarget.dataset.item;
let your = detail.username; let your = detail.username;
console.log(your) console.log(your)
...@@ -282,14 +282,14 @@ Page({ ...@@ -282,14 +282,14 @@ Page({
wx.showModal({ wx.showModal({
title: title, title: title,
confirmText: "确定", confirmText: "确定",
success: function(res) { success: function (res) {
if (res.confirm) { if (res.confirm) {
if (type == 1) { if (type == 1) {
getData(apis.addrecord, 'GET', { getData(apis.addrecord, 'GET', {
"token": token, "token": token,
"user_id": id, "user_id": id,
status: 3 status: 3
}, function(res) { }, function (res) {
if (res.errcode === 0) { if (res.errcode === 0) {
let member = wx.getStorageSync('member'); let member = wx.getStorageSync('member');
let index = member.indexOf(your); let index = member.indexOf(your);
...@@ -309,22 +309,31 @@ Page({ ...@@ -309,22 +309,31 @@ Page({
} }
}, false); }, false);
} else { } else {
list
let list = { let list = {
your: { // your: {
jid: WebIM.config.appkey + '_' + your + '@easemob.com', // jid: WebIM.config.appkey + '_' + your + '@easemob.com',
name: your, // name: your,
order: 1, // order: 5,
}, // },
}; };
list[your] = {
jid: WebIM.config.appkey + '_' + your + '@easemob.com',
name: your,
order: 1,
subscription: 'both',
type:"jid"
}
WebIM.conn.addToBlackList({ WebIM.conn.addToBlackList({
list: list, list: list,
type: 'jid', type: 'jid',
success: function() { success: function () {
console.log('拉黑成功')
getData(apis.addrecord, 'GET', { getData(apis.addrecord, 'GET', {
"token": token, "token": token,
"user_id": id, "user_id": id,
status: 2 status: 2
}, function(res) { }, function (res) {
if (res.errcode === 0) { if (res.errcode === 0) {
let member = wx.getStorageSync('member'); let member = wx.getStorageSync('member');
let index = member.indexOf(your); let index = member.indexOf(your);
...@@ -344,7 +353,7 @@ Page({ ...@@ -344,7 +353,7 @@ Page({
} }
}, false); }, false);
}, },
error: function() { error: function () {
wx.showToast({ wx.showToast({
title: '加入黑名单失败', title: '加入黑名单失败',
icon: 'none', icon: 'none',
...@@ -357,15 +366,15 @@ Page({ ...@@ -357,15 +366,15 @@ Page({
} }
}, },
fail: function(err) {} fail: function (err) { }
}); });
}, },
closeTip: function() { closeTip: function () {
this.setData({ this.setData({
isShowTip: false isShowTip: false
}) })
}, },
toSys: function() { toSys: function () {
wx.navigateTo({ wx.navigateTo({
url: "/pages/list/notice/index" url: "/pages/list/notice/index"
}); });
......
...@@ -65,6 +65,10 @@ const apis = { ...@@ -65,6 +65,10 @@ const apis = {
*/ */
authme: auth_url + '/auth/me', authme: auth_url + '/auth/me',
/*** /***
* 手动注册im账号
*/
authregistim: auth_url + '/auth/registIMUser',
/***
* 新增会员认证信息 * 新增会员认证信息
*/ */
addAuth: user_url + '/user/addauth', addAuth: user_url + '/user/addauth',
......
...@@ -37,7 +37,18 @@ const onMessageError = (err) => { ...@@ -37,7 +37,18 @@ const onMessageError = (err) => {
return true; return true;
} }
const getImUser = () => { const getImUser = () => {
let token = wx.getStorageSync('access_token') || '' let token = wx.getStorageSync('access_token') || '';
let imName = wx.getStorageSync('myUsername') || '';
let imPassword = wx.getStorageSync('myPassword') || '';
if (imName && imPassword) {
conn.open({
apiUrl: WebIM.config.apiURL,
user: imName,
pwd: imPassword,
appKey: WebIM.config.appkey
});
return;
}
getData(apis.authme, 'get', { getData(apis.authme, 'get', {
"token": token, "token": token,
}, function(res) { }, function(res) {
...@@ -46,7 +57,7 @@ const getImUser = () => { ...@@ -46,7 +57,7 @@ const getImUser = () => {
wx.setStorageSync('avatar', res.data.avatar); wx.setStorageSync('avatar', res.data.avatar);
wx.setStorageSync('company_name', res.data.company_name); wx.setStorageSync('company_name', res.data.company_name);
wx.setStorageSync("myUsername", res.data.im_username); wx.setStorageSync("myUsername", res.data.im_username);
console.log(res) wx.setStorageSync("myPassword", res.data.im_password);
conn.open({ conn.open({
apiUrl: WebIM.config.apiURL, apiUrl: WebIM.config.apiURL,
user: res.data.im_username, user: res.data.im_username,
...@@ -73,6 +84,20 @@ const addImUser = (message) => { //接收消息后进行用户的处理,以便 ...@@ -73,6 +84,20 @@ const addImUser = (message) => { //接收消息后进行用户的处理,以便
} }
}; };
const registerIm = () => {
let token = wx.getStorageSync('access_token') || '';
getData(apis.authregistim + '?source=1', 'post', {}, function(res) {
if (res.errcode == 0) {
getImUser();
} else {
wx.showModal({
title: '提示',
content: '聊天系统出现异常!',
showCancel: false
})
}
}, false, true)
};
const webimListen = () => { const webimListen = () => {
let my = wx.getStorageSync('myUsername') || ''; let my = wx.getStorageSync('myUsername') || '';
WebIM.conn.listen({ WebIM.conn.listen({
...@@ -146,7 +171,7 @@ const webimListen = () => { ...@@ -146,7 +171,7 @@ const webimListen = () => {
calcUnReadSpot(message); calcUnReadSpot(message);
} }
}, },
onBlacklistUpdate: function (list) { //黑名单变动 onBlacklistUpdate: function(list) { //黑名单变动
// 查询黑名单,将好友拉黑,将好友从黑名单移除都会回调这个函数,list则是黑名单现有的所有好友信息 // 查询黑名单,将好友拉黑,将好友从黑名单移除都会回调这个函数,list则是黑名单现有的所有好友信息
console.log(list); console.log(list);
}, },
...@@ -160,10 +185,19 @@ const webimListen = () => { ...@@ -160,10 +185,19 @@ const webimListen = () => {
if (curPage.route == "pages/detail/chat/index" || curPage.route == 'pages/tab/message/message') { if (curPage.route == "pages/detail/chat/index" || curPage.route == 'pages/tab/message/message') {
reloginIm() reloginIm()
} }
} else if (error.type == 1) {
} else if(error.type == 1){ if (getApp().globalData.isRelogin) {
getImUser() getApp().globalData.isRelogin = false;
}else { console.log('重新登录')
registerIm()
} else {
wx.showModal({
title: '提示',
content: '聊天系统登录失败!',
showCancel: false
})
}
} else {
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
content: '聊天系统出现异常!', content: '聊天系统出现异常!',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment