merge
This commit is contained in:
@@ -39,6 +39,11 @@
|
|||||||
smsAuth
|
smsAuth
|
||||||
} from "@/apis/interfaces/auth";
|
} from "@/apis/interfaces/auth";
|
||||||
import userAuth from "@/public/userAuth";
|
import userAuth from "@/public/userAuth";
|
||||||
|
import {
|
||||||
|
getImToken
|
||||||
|
} from '@/apis/interfaces/im.js'
|
||||||
|
import im from '@/utils/im/index.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -59,6 +64,11 @@
|
|||||||
"setToken",
|
"setToken",
|
||||||
res.token_type + " " + res.access_token
|
res.token_type + " " + res.access_token
|
||||||
);
|
);
|
||||||
|
// 在这里,登录成功,链接IM服务
|
||||||
|
getImToken().then(res => {
|
||||||
|
console.log('在这获取IM-TOKEN', res);
|
||||||
|
im.connect(res.token, res.userInfo, () => {})
|
||||||
|
})
|
||||||
this.$Router.back();
|
this.$Router.back();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
<list class="body" :show-scrollbar="false">
|
<list class="body" :show-scrollbar="false">
|
||||||
<cell class="cell" v-for="(item, index) in messages" :key="index">
|
<cell class="cell" v-for="(item, index) in messages" :key="index">
|
||||||
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
||||||
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square" :src="item.content.userInfo.portraitUrl" />
|
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square"
|
||||||
|
:src="item.content.userInfo.portraitUrl" />
|
||||||
<view class="msg">
|
<view class="msg">
|
||||||
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
||||||
:msg="item.content" :name="item.content.userInfo.name" />
|
:msg="item.content" :name="item.content.userInfo.name" />
|
||||||
@@ -43,13 +44,18 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
targetId: '',
|
targetId: '',
|
||||||
conversationType: 3,
|
conversationType: RongIMLib.ConversationType.GROUP,
|
||||||
messages: [],
|
messages: [],
|
||||||
groupInfo: {
|
groupInfo: {
|
||||||
name: ''
|
name: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
latestMessage() {
|
||||||
|
return this.messages[this.messages.length - 1]
|
||||||
|
}
|
||||||
|
},
|
||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
this.targetId = e.targetId
|
this.targetId = e.targetId
|
||||||
this.groupInfo = this.$store.getters.contactInfo(this.targetId)
|
this.groupInfo = this.$store.getters.contactInfo(this.targetId)
|
||||||
@@ -64,10 +70,6 @@
|
|||||||
})
|
})
|
||||||
uni.$once('cleanGroupMessage', this.getMessageList)
|
uni.$once('cleanGroupMessage', this.getMessageList)
|
||||||
},
|
},
|
||||||
onBackPress() {
|
|
||||||
uni.$off('onReceiveMessage')
|
|
||||||
console.log('Off onReceiveMessage');
|
|
||||||
},
|
|
||||||
onNavigationBarButtonTap() {
|
onNavigationBarButtonTap() {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/im/group/info?targetId=' + this.targetId
|
url: '/pages/im/group/info?targetId=' + this.targetId
|
||||||
@@ -82,18 +84,18 @@
|
|||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/im/friends/mine?targetId=' + item.senderUserId
|
url: '/pages/im/friends/mine?targetId=' + item.senderUserId
|
||||||
})
|
})
|
||||||
} else{
|
} else {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/im/friends/info?targetId=' + item.senderUserId
|
url: '/pages/im/friends/info?targetId=' + item.senderUserId
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getNewMessage() {
|
getNewMessage() {
|
||||||
im.getMessageList(
|
im.getMessageList(
|
||||||
this.conversationType,
|
this.conversationType,
|
||||||
this.targetId,
|
this.targetId,
|
||||||
new Date().getTime(),
|
this.latestMessage.sentTime,
|
||||||
10,
|
1,
|
||||||
false,
|
false,
|
||||||
(messages) => {
|
(messages) => {
|
||||||
this.messages = this.messages.concat(messages)
|
this.messages = this.messages.concat(messages)
|
||||||
@@ -105,7 +107,7 @@
|
|||||||
im.getMessageList(
|
im.getMessageList(
|
||||||
this.conversationType,
|
this.conversationType,
|
||||||
this.targetId,
|
this.targetId,
|
||||||
new Date().getTime(),
|
0,
|
||||||
100,
|
100,
|
||||||
true,
|
true,
|
||||||
(messages) => {
|
(messages) => {
|
||||||
@@ -115,12 +117,15 @@
|
|||||||
},
|
},
|
||||||
// 滚动到底部
|
// 滚动到底部
|
||||||
scrollBottom(type) {
|
scrollBottom(type) {
|
||||||
// 清理当前会话,未读消息数量
|
if (this.latestMessage) {
|
||||||
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100)
|
// 清理当前会话,未读消息数量
|
||||||
// 发送消息已读状态给对方
|
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
|
||||||
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
|
.sentTime)
|
||||||
// 更新badge提醒数量
|
// // 发送消息已读状态给对方
|
||||||
im.setNotifyBadge()
|
// RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
|
||||||
|
// 更新badge提醒数量
|
||||||
|
im.setNotifyBadge()
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let el = this.$refs.chatBottom
|
let el = this.$refs.chatBottom
|
||||||
|
|||||||
@@ -42,6 +42,12 @@
|
|||||||
const ChatList = uni.requireNativePlugin('dom')
|
const ChatList = uni.requireNativePlugin('dom')
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
sentMessageBar,
|
||||||
|
showVoice,
|
||||||
|
showImage,
|
||||||
|
showText
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
targetId: '',
|
targetId: '',
|
||||||
@@ -54,11 +60,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
computed: {
|
||||||
sentMessageBar,
|
latestMessage() {
|
||||||
showVoice,
|
return this.messages[this.messages.length - 1]
|
||||||
showImage,
|
}
|
||||||
showText
|
|
||||||
},
|
},
|
||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
this.targetId = e.targetId
|
this.targetId = e.targetId
|
||||||
@@ -98,8 +103,8 @@
|
|||||||
im.getMessageList(
|
im.getMessageList(
|
||||||
this.conversationType,
|
this.conversationType,
|
||||||
this.targetId,
|
this.targetId,
|
||||||
new Date().getTime(),
|
this.latestMessage.sentTime,
|
||||||
10,
|
1,
|
||||||
false,
|
false,
|
||||||
(messages) => {
|
(messages) => {
|
||||||
this.messages = this.messages.concat(messages)
|
this.messages = this.messages.concat(messages)
|
||||||
@@ -111,7 +116,7 @@
|
|||||||
im.getMessageList(
|
im.getMessageList(
|
||||||
this.conversationType,
|
this.conversationType,
|
||||||
this.targetId,
|
this.targetId,
|
||||||
new Date().getTime(),
|
0,
|
||||||
100,
|
100,
|
||||||
true,
|
true,
|
||||||
(messages) => {
|
(messages) => {
|
||||||
@@ -128,12 +133,15 @@
|
|||||||
},
|
},
|
||||||
// 滚动到底部
|
// 滚动到底部
|
||||||
scrollBottom(type) {
|
scrollBottom(type) {
|
||||||
// 清理当前会话,未读消息数量
|
if (this.latestMessage) {
|
||||||
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime())
|
// 清理当前会话,未读消息数量
|
||||||
// 发送消息已读状态给对方
|
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
|
||||||
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
|
.sentTime)
|
||||||
// 更新badge提醒数量
|
// // 发送消息已读状态给对方
|
||||||
im.setNotifyBadge()
|
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
|
||||||
|
// 更新badge提醒数量
|
||||||
|
im.setNotifyBadge()
|
||||||
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let el = this.$refs.chatBottom
|
let el = this.$refs.chatBottom
|
||||||
ChatList.scrollToElement(el, {
|
ChatList.scrollToElement(el, {
|
||||||
|
|||||||
@@ -105,9 +105,11 @@ class userAuth {
|
|||||||
openid: authResult.authResult.openid
|
openid: authResult.authResult.openid
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
uni.closeAuthView()
|
uni.closeAuthView()
|
||||||
store.commit('setToken', res.token_type + ' ' + res.access_token)
|
store.commit('setToken', res.token_type + ' ' + res
|
||||||
|
.access_token)
|
||||||
// 在这里,登录成功,链接IM服务
|
// 在这里,登录成功,链接IM服务
|
||||||
getImToken().then(res => {
|
getImToken().then(res => {
|
||||||
|
console.log('在这获取IM-TOKEN', res);
|
||||||
im.connect(res.token, res.userInfo)
|
im.connect(res.token, res.userInfo)
|
||||||
})
|
})
|
||||||
resolve()
|
resolve()
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import listeners from './listeners.js'
|
|||||||
import {
|
import {
|
||||||
getFriends,
|
getFriends,
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
getImToken
|
getImToken,
|
||||||
|
getMyGroups
|
||||||
} from '@/apis/interfaces/im.js'
|
} from '@/apis/interfaces/im.js'
|
||||||
|
|
||||||
const initIm = (KEY) => {
|
const initIm = (KEY) => {
|
||||||
@@ -58,7 +59,7 @@ const connect = (token, userInfo, callback) => {
|
|||||||
// 设置未读消息数量
|
// 设置未读消息数量
|
||||||
setNotifyBadge()
|
setNotifyBadge()
|
||||||
// 首次运行获取好友列表
|
// 首次运行获取好友列表
|
||||||
const FK = 'IFT_' + userInfo.targetId
|
const FK = 'ZHK_' + userInfo.targetId
|
||||||
|
|
||||||
uni.getStorage({
|
uni.getStorage({
|
||||||
key: FK,
|
key: FK,
|
||||||
@@ -71,10 +72,12 @@ const connect = (token, userInfo, callback) => {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: () => {
|
||||||
// 程序是首次运行,初始化加载好友信息
|
// 程序是首次运行,初始化加载好友和群组信息
|
||||||
getFriends().then(res => {
|
Promise.all([getFriends(), getMyGroups()]).then(result => {
|
||||||
res.map(item => {
|
result.map(contacts => {
|
||||||
store.dispatch('initContact', item)
|
contacts.map(item => {
|
||||||
|
store.dispatch('initContact', item)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
uni.setStorageSync(FK, userInfo.targetId)
|
uni.setStorageSync(FK, userInfo.targetId)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user