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