diff --git a/pages/im/components/sentText.nvue b/pages/im/components/sentText.nvue index d8b6915..6dcc4b5 100644 --- a/pages/im/components/sentText.nvue +++ b/pages/im/components/sentText.nvue @@ -47,9 +47,7 @@ if (!this.disabled) { RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId) im.sentText(this.conversationType, this.targetId, this.inputTxt, () => { - setTimeout(() => { - this.$emit('success') - }, 500) + this.$emit('success') this.inputTxt = '' }) } diff --git a/pages/im/private/chat.nvue b/pages/im/private/chat.nvue index d6dd1b8..baa2058 100644 --- a/pages/im/private/chat.nvue +++ b/pages/im/private/chat.nvue @@ -52,7 +52,7 @@ import sentText from '../components/sentText' import sentVoice from '../components/sentVoice' - const ChatList = uni.requireNativePlugin('dom') + const ChatList = uni.requireNativePlugin('dom') export default { data() { @@ -81,8 +81,8 @@ this.userInfo = this.$store.getters.userInfo(this.targetId) // 获取消息列表 - this.initMessageList() - + this.initMessageList() + uni.setNavigationBarTitle({ title: this.userInfo.name }) @@ -120,11 +120,18 @@ this.chatType = this.chatType === 1 ? 0 : 1 }, // 获取消息列表 - getMessageList() { - im.getMessageList(this.conversationType, this.targetId, (messages) => { - this.messages = messages.reverse() - this.scrollBottom() - }) + getMessageList() { + im.getMessageList( + this.conversationType, + this.targetId, + new Date().getTime(), + 10, + true, + (messages) => { + console.log(messages); + this.messages = messages.reverse() + this.scrollBottom() + }) }, // 展示好友信息, type 1 是自己, 2 是对方 showUser(targetId, type) { diff --git a/utils/im/message.js b/utils/im/message.js index 8b0069b..368715a 100644 --- a/utils/im/message.js +++ b/utils/im/message.js @@ -1,7 +1,7 @@ import store from '@/store/index.js' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' -const getMessageList = (conversationType, targetId, callback) => { +const getMessageList = (conversationType, targetId, timeStamp, count, isForward, callback) => { // 获取消息列表 const objectNames = [ 'RC:TxtMsg', @@ -16,10 +16,12 @@ const getMessageList = (conversationType, targetId, callback) => { 'RC:ReferenceMsg', 'RC:CombineMsg' ] - const timeStamp = new Date().getTime() - const count = 10 // 获取的消息数量 - const isForward = true // 是否向前获取 - RongIMLib.getHistoryMessagesByTimestamp(conversationType, targetId, objectNames, timeStamp, + + RongIMLib.getHistoryMessagesByTimestamp( + conversationType, + targetId, + objectNames, + timeStamp + 1000, count, isForward, ({