|
@@ -649,6 +649,7 @@ module.exports = {
|
|
|
success(res) {
|
|
success(res) {
|
|
|
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
|
|
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
|
|
|
console.log('连接成功',res)
|
|
console.log('连接成功',res)
|
|
|
|
|
+ that.onSocketMsg();
|
|
|
},
|
|
},
|
|
|
fail(err) {
|
|
fail(err) {
|
|
|
console.log('连接失败',res)
|
|
console.log('连接失败',res)
|
|
@@ -656,6 +657,30 @@ module.exports = {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+ onSocketMsg(){
|
|
|
|
|
+ let that = this
|
|
|
|
|
+ uni.onSocketMessage((res) => {
|
|
|
|
|
+ if (res.data === 'HeartBeat') return // 忽略心跳包
|
|
|
|
|
+ let msg
|
|
|
|
|
+ try {
|
|
|
|
|
+ msg = JSON.parse(res.data)
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ // console.log('消息不是JSON格式:', res.data)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if (msg.type === 'kickOut') {
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '提示',
|
|
|
|
|
+ content: msg.content,
|
|
|
|
|
+ showCancel: false,
|
|
|
|
|
+ success() {
|
|
|
|
|
+ that.logout();
|
|
|
|
|
+ uni.reLaunch({ url: '/pages/public/loginphone?type=1' })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
sendImMessage(userId,content,messageType,chatConversationId){
|
|
sendImMessage(userId,content,messageType,chatConversationId){
|
|
|
let data = {
|
|
let data = {
|
|
|
userId,
|
|
userId,
|