语音消息发送成功,播放暂时不支持带token的路径
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
* 碌碌无为枉半生,一朝惊醒万事空。
|
* 碌碌无为枉半生,一朝惊醒万事空。
|
||||||
* moduleName: 聊聊
|
* moduleName: 聊聊
|
||||||
*/
|
*/
|
||||||
|
import store from '@/store'
|
||||||
import {
|
import {
|
||||||
request
|
request
|
||||||
} from '../index'
|
} from '../index'
|
||||||
@@ -84,9 +84,9 @@ const pedingFriend = (recipient) => {
|
|||||||
url: 'im/friends/' + recipient
|
url: 'im/friends/' + recipient
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 好友申请数量
|
* 好友申请数量
|
||||||
*/
|
*/
|
||||||
const getPendingCount = () => {
|
const getPendingCount = () => {
|
||||||
return request({
|
return request({
|
||||||
@@ -94,6 +94,49 @@ const getPendingCount = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传聊天附件
|
||||||
|
* 图片
|
||||||
|
* 语音
|
||||||
|
* 视频
|
||||||
|
*/
|
||||||
|
// 基础配置
|
||||||
|
const config = {
|
||||||
|
apiUrl: 'http://api.zh.shangkelian.cn/api/', // 正式环境
|
||||||
|
timeout: 60000
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadMessageFile = (file, type) => {
|
||||||
|
config.header = {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': store.getters.getToken || ''
|
||||||
|
}
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.uploadFile({
|
||||||
|
url: config.apiUrl + 'im/upload',
|
||||||
|
filePath: file,
|
||||||
|
name: 'upload',
|
||||||
|
formData: {
|
||||||
|
type
|
||||||
|
},
|
||||||
|
header: config.header || {},
|
||||||
|
success: (res) => {
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
let updData = JSON.parse(res.data)
|
||||||
|
if (updData.status_code === 200) {
|
||||||
|
resolve(updData.data)
|
||||||
|
} else {
|
||||||
|
reject(updData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.log('ERR', err);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getImToken,
|
getImToken,
|
||||||
deleteFriend,
|
deleteFriend,
|
||||||
@@ -105,5 +148,6 @@ export {
|
|||||||
rejectFriend,
|
rejectFriend,
|
||||||
searchFriend,
|
searchFriend,
|
||||||
pedingFriend,
|
pedingFriend,
|
||||||
getPendingCount
|
getPendingCount,
|
||||||
|
uploadMessageFile
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,80 +1,93 @@
|
|||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<view class="im--audio" :class="guest ? 'right': 'left'" @click="onPlayMsg">
|
<view class="im--audio" :class="guest ? 'right': 'left'" @click="onPlayMsg">
|
||||||
<image v-if="!guest" class="audio-mp3" src="@/static/icon/audio_green.png" mode="widthFix"></image>
|
<image v-if="!guest" class="audio-mp3" src="@/static/icon/audio_green.png" mode="widthFix"></image>
|
||||||
<text class="audio-text">"{{msg.time}}"</text>
|
<text class="audio-text">"{{msg.duration}}"</text>
|
||||||
<image v-if="guest" class="audio-mp3" src="@/static/icon/audio_white.png" mode="widthFix"></image>
|
<image v-if="guest" class="audio-mp3" src="@/static/icon/audio_white.png" mode="widthFix"></image>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name:"im",
|
name: "im",
|
||||||
props:{
|
props: {
|
||||||
msg : {
|
msg: {
|
||||||
type : Object,
|
type: Object,
|
||||||
default: () => {
|
default: () => {
|
||||||
return {
|
return {
|
||||||
src: "",
|
local: '',
|
||||||
time: "20"
|
remote: '',
|
||||||
}
|
objectName: '',
|
||||||
}
|
duration: 0
|
||||||
},
|
}
|
||||||
guest: {
|
}
|
||||||
type: Boolean,
|
},
|
||||||
default: true
|
guest: {
|
||||||
}
|
type: Boolean,
|
||||||
},
|
default: true
|
||||||
methods:{
|
}
|
||||||
// 播放语音消息
|
},
|
||||||
onPlayMsg() {
|
methods: {
|
||||||
let innerAudioContext = uni.createInnerAudioContext()
|
// 播放语音消息
|
||||||
innerAudioContext.src = this.audioSrc
|
onPlayMsg() {
|
||||||
if (this.audioContextPaused) {
|
console.log('播放', this.msg.remote);
|
||||||
innerAudioContext.play()
|
let innerAudioContext = uni.createInnerAudioContext()
|
||||||
this.audioContextPaused = false
|
innerAudioContext.src = this.msg.remote
|
||||||
return
|
if (this.audioContextPaused) {
|
||||||
}
|
innerAudioContext.play()
|
||||||
innerAudioContext.stop()
|
this.audioContextPaused = false
|
||||||
innerAudioContext.onStop(resStop => {
|
return
|
||||||
this.audioContextPaused = true
|
}
|
||||||
})
|
innerAudioContext.stop()
|
||||||
}
|
innerAudioContext.onStop(resStop => {
|
||||||
}
|
console.log('停止');
|
||||||
}
|
this.audioContextPaused = true
|
||||||
</script>
|
})
|
||||||
|
innerAudioContext.onError(err => {
|
||||||
<style scoped>
|
console.log(err);
|
||||||
.im--audio{
|
})
|
||||||
flex-direction: row;
|
}
|
||||||
justify-content: space-between;
|
}
|
||||||
align-items: center;
|
}
|
||||||
height: 79rpx;
|
</script>
|
||||||
width: 170rpx;
|
|
||||||
padding: 0 20rpx;
|
<style scoped>
|
||||||
box-sizing: border-box;
|
.im--audio {
|
||||||
},
|
flex-direction: row;
|
||||||
.im--audio.left{
|
justify-content: space-between;
|
||||||
border-radius: 0 20rpx 20rpx 20rpx;
|
align-items: center;
|
||||||
background: white;
|
height: 79rpx;
|
||||||
}
|
width: 170rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
.im--audio.right{
|
box-sizing: border-box;
|
||||||
border-radius: 20rpx 0 20rpx 20rpx;
|
}
|
||||||
background: #34CE98;
|
|
||||||
}
|
,
|
||||||
.audio-mp3{
|
.im--audio.left {
|
||||||
width: 38rpx;
|
border-radius: 0 20rpx 20rpx 20rpx;
|
||||||
height: 38rpx;
|
background: white;
|
||||||
}
|
}
|
||||||
.audio-text{
|
|
||||||
font-size: 30rpx;
|
.im--audio.right {
|
||||||
}
|
border-radius: 20rpx 0 20rpx 20rpx;
|
||||||
.im--audio.left .audio-text{
|
background: #34CE98;
|
||||||
color: #333;
|
}
|
||||||
}
|
|
||||||
.im--audio.right .audio-text{
|
.audio-mp3 {
|
||||||
color: white;
|
width: 38rpx;
|
||||||
}
|
height: 38rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.audio-text {
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.im--audio.left .audio-text {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.im--audio.right .audio-text {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,393 +1,412 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="chat">
|
<view class="chat">
|
||||||
<!-- chat -->
|
<!-- chat -->
|
||||||
<list class="chat-scroll">
|
<list class="chat-scroll">
|
||||||
<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-time">
|
<view class="cell-time">
|
||||||
<text class="cell-time-text">{{ item.sentTime|timeCustomCN }}</text>
|
<text class="cell-time-text">{{ item.sentTime|timeCustomCN }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
||||||
<image class="active" :src="userInfo.portraitUrl" mode="aspectFill" @click="showFriend(targetId, item.messageDirection)"></image>
|
<image class="active" :src="userInfo.portraitUrl" mode="aspectFill"
|
||||||
<view class="msg">
|
@click="showFriend(targetId, item.messageDirection)"></image>
|
||||||
<imAUDIO v-if="item.objectName === 'RC:VcMsg'" :guest="item.messageDirection == 1" :msg="item.content.content"></imAUDIO>
|
<view class="msg">
|
||||||
<imIMG v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1" :msg="item.content.content"></imIMG>
|
<imAUDIO v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
||||||
<imTXT v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1" :msg="item.content.content"></imTXT>
|
:msg="item.content"></imAUDIO>
|
||||||
<view class="state" v-if="item.messageDirection == 1">
|
<imIMG v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1"
|
||||||
<text class="state-text">{{ item.sentStatus == 50 ? '已读': '未读'}}</text>
|
:msg="item.content.content"></imIMG>
|
||||||
</view>
|
<imTXT v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
|
||||||
</view>
|
:msg="item.content.content"></imTXT>
|
||||||
</view>
|
<view class="state" v-if="item.messageDirection == 1">
|
||||||
</cell>
|
<text class="state-text">{{ item.sentStatus == 50 ? '已读': '未读'}}</text>
|
||||||
<cell class="cell-footer" ref="chatBottom"></cell>
|
</view>
|
||||||
</list>
|
</view>
|
||||||
<!-- footer -->
|
</view>
|
||||||
<view class="chat-footer">
|
</cell>
|
||||||
<view class="msg-type" @click="msgType">
|
<cell class="cell-footer" ref="chatBottom"></cell>
|
||||||
<image class="msg-type-icon" src="@/static/icon/key-icon.png" v-if="importTabs === 0" mode="widthFix"></image>
|
</list>
|
||||||
<image class="msg-type-icon" src="@/static/icon/msg-icon.png" v-if="importTabs === 1" mode="widthFix"></image>
|
<!-- footer -->
|
||||||
</view>
|
<view class="chat-footer">
|
||||||
<block v-if="importTabs === 0">
|
<view class="msg-type" @click="msgType">
|
||||||
<view class="chat-mp3" hover-class="chat-hover" @touchstart="startAudio" @touchend="chendAudio">
|
<image class="msg-type-icon" src="@/static/icon/key-icon.png" v-if="importTabs === 0" mode="widthFix">
|
||||||
<text class="chat-mp3-text">按住说话</text>
|
</image>
|
||||||
</view>
|
<image class="msg-type-icon" src="@/static/icon/msg-icon.png" v-if="importTabs === 1" mode="widthFix">
|
||||||
</block>
|
</image>
|
||||||
<block v-if="importTabs === 1">
|
</view>
|
||||||
<input class="chat-input" type="text" v-model="inputTxt" confirm-type="发送" @confirm="send" cursor-spacing="10" />
|
<block v-if="importTabs === 0">
|
||||||
</block>
|
<view class="chat-mp3" hover-class="chat-hover" @touchstart="startAudio" @touchend="chendAudio">
|
||||||
<text class="chat-push" size="mini" @click="send">发送</text>
|
<text class="chat-mp3-text">按住说话</text>
|
||||||
</view>
|
</view>
|
||||||
<!-- 录音中提示 -->
|
</block>
|
||||||
<view class="audio-transcribe" v-if="showAudioTranscribe">
|
<block v-if="importTabs === 1">
|
||||||
<image class="audio-transcribe-src" src="@/static/icon/record-icon.png" mode="widthFix"></image>
|
<input class="chat-input" type="text" v-model="inputTxt" confirm-type="发送" @confirm="send"
|
||||||
<text class="audio-transcribe-text">录音中 {{transcribeTime}} s</text>
|
cursor-spacing="10" />
|
||||||
</view>
|
</block>
|
||||||
</view>
|
<text class="chat-push" size="mini" @click="send">发送</text>
|
||||||
</template>
|
</view>
|
||||||
|
<!-- 录音中提示 -->
|
||||||
<script>
|
<view class="audio-transcribe" v-if="showAudioTranscribe">
|
||||||
import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index"
|
<image class="audio-transcribe-src" src="@/static/icon/record-icon.png" mode="widthFix"></image>
|
||||||
import im from '@/utils/im/index.js'
|
<text class="audio-transcribe-text">录音中 {{transcribeTime}} s</text>
|
||||||
import permision from "@/js_sdk/wa-permission/permission.js"
|
</view>
|
||||||
import imAUDIO from '@/components/im/imAUDIO'
|
</view>
|
||||||
import imIMG from '@/components/im/imIMG'
|
</template>
|
||||||
import imTXT from '@/components/im/imTXT'
|
|
||||||
|
<script>
|
||||||
var transcribe
|
import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index"
|
||||||
var recorderManager = uni.getRecorderManager()
|
import im from '@/utils/im/index.js'
|
||||||
|
import permision from "@/js_sdk/wa-permission/permission.js"
|
||||||
const ChatList = uni.requireNativePlugin('dom')
|
import imAUDIO from '@/components/im/imAUDIO'
|
||||||
export default {
|
import imIMG from '@/components/im/imIMG'
|
||||||
data() {
|
import imTXT from '@/components/im/imTXT'
|
||||||
return {
|
|
||||||
targetId: '',
|
var transcribe
|
||||||
scrollIntoID: 'chatID_0',
|
var recorderManager = uni.getRecorderManager()
|
||||||
inputTxt: '',
|
|
||||||
messages: [],
|
const ChatList = uni.requireNativePlugin('dom')
|
||||||
conversationType: 1,
|
export default {
|
||||||
totalCount: 0,
|
data() {
|
||||||
userInfo: {
|
return {
|
||||||
name: '',
|
targetId: '',
|
||||||
userId: '',
|
scrollIntoID: 'chatID_0',
|
||||||
portraitUrl: ''
|
inputTxt: '',
|
||||||
},
|
messages: [],
|
||||||
importTabs: 1,
|
conversationType: 1,
|
||||||
showAudioTranscribe: false,
|
userInfo: {
|
||||||
transcribeTime: 60,
|
name: '',
|
||||||
audioSrc: '',
|
userId: '',
|
||||||
audioContextPaused: true
|
portraitUrl: ''
|
||||||
}
|
},
|
||||||
},
|
importTabs: 1,
|
||||||
components:{ imAUDIO, imIMG, imTXT },
|
showAudioTranscribe: false,
|
||||||
onLoad(e) {
|
transcribeTime: 60,
|
||||||
|
audioSrc: '',
|
||||||
console.log(e)
|
audioContextPaused: true
|
||||||
console.log(11111)
|
}
|
||||||
|
},
|
||||||
this.targetId = e.targetId
|
components: {
|
||||||
this.conversationType = e.conversationType // 会话类型
|
imAUDIO,
|
||||||
// 消息总数量
|
imIMG,
|
||||||
RongIMLib.getMessageCount(this.conversationType, this.targetId, ({
|
imTXT
|
||||||
code,
|
},
|
||||||
count
|
onLoad(e) {
|
||||||
}) => {
|
this.targetId = e.targetId
|
||||||
if (code == 0) {
|
this.conversationType = e.conversationType // 会话类型
|
||||||
this.totalCount = count
|
this.userInfo = this.$store.getters.userInfo(this.targetId)
|
||||||
}
|
uni.setNavigationBarTitle({
|
||||||
})
|
title: this.$store.getters.userInfo(this.targetId).name
|
||||||
this.userInfo = this.$store.getters.userInfo(this.targetId)
|
})
|
||||||
uni.setNavigationBarTitle({
|
|
||||||
title: this.$store.getters.userInfo(this.targetId).name
|
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime())
|
||||||
})
|
im.setNotifyBadge()
|
||||||
|
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
|
||||||
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime())
|
|
||||||
im.setNotifyBadge()
|
this.getMessageList()
|
||||||
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
|
|
||||||
|
// 监听消息回执
|
||||||
this.getMessageList()
|
RongIMLib.addReadReceiptReceivedListener(({
|
||||||
|
data
|
||||||
// 监听消息回执
|
}) => {
|
||||||
RongIMLib.addReadReceiptReceivedListener(({
|
if (data.targetId == this.targetId) {
|
||||||
data
|
this.getMessageList()
|
||||||
}) => {
|
}
|
||||||
if (data.targetId == this.targetId) {
|
})
|
||||||
this.getMessageList()
|
|
||||||
}
|
// 监听收到新消息,判断是否是当前会话,更新会话内容
|
||||||
})
|
uni.$on('onReceiveMessage', (msg) => {
|
||||||
|
if (msg.targetId == this.targetId) {
|
||||||
// 监听录音结束
|
RongIMLib.clearMessagesUnreadStatus(msg.conversationType, msg.targetId, msg.sentTime)
|
||||||
recorderManager.onStop(res => {
|
RongIMLib.sendReadReceiptMessage(msg.conversationType, msg.targetId, msg.sentTime)
|
||||||
if (res.tempFilePath) this.audioSrc = res.tempFilePath
|
this.getMessageList()
|
||||||
console.log('------------------获取到了录音的临时路径---------------')
|
im.setNotifyBadge()
|
||||||
console.log(res.tempFilePath)
|
}
|
||||||
})
|
})
|
||||||
// 简童收到新消息,判断是否是当前会话,更新会话内容
|
},
|
||||||
uni.$on('onReceiveMessage', (msg) => {
|
beforeDestroy() {
|
||||||
if (msg.targetId == this.targetId) {
|
uni.$off('onReceiveMessage')
|
||||||
RongIMLib.clearMessagesUnreadStatus(msg.conversationType, msg.targetId, msg.sentTime)
|
},
|
||||||
RongIMLib.sendReadReceiptMessage(msg.conversationType, msg.targetId, msg.sentTime)
|
onUnload() {
|
||||||
this.getMessageList()
|
RongIMLib.clearReadReceiptReceivedListener()
|
||||||
im.setNotifyBadge()
|
},
|
||||||
}
|
computed: {
|
||||||
})
|
disabled() {
|
||||||
},
|
return this.inputTxt.length == 0
|
||||||
beforeDestroy() {
|
}
|
||||||
uni.$off('onReceiveMessage')
|
},
|
||||||
},
|
onNavigationBarButtonTap(e) {
|
||||||
onUnload() {
|
if (e.index == 0) {
|
||||||
RongIMLib.clearReadReceiptReceivedListener()
|
uni.navigateTo({
|
||||||
},
|
url: '/pages/im/private/setting?targetId=' + this.targetId +
|
||||||
computed: {
|
'&conversationType=' + this.conversationType,
|
||||||
disabled() {
|
events: {
|
||||||
return this.inputTxt.length == 0
|
messageClear: () => {
|
||||||
}
|
this.getMessageList()
|
||||||
},
|
console.log('聊天消息被清空');
|
||||||
onNavigationBarButtonTap(e) {
|
}
|
||||||
if (e.index == 0) {
|
}
|
||||||
uni.navigateTo({
|
})
|
||||||
url: '/pages/im/private/setting?targetId=' + this.targetId +
|
}
|
||||||
'&conversationType=' + this.conversationType,
|
},
|
||||||
events: {
|
methods: {
|
||||||
messageClear: () => {
|
// 检查安卓录制权限
|
||||||
this.getMessageList()
|
async getAndroidPermission() {
|
||||||
console.log('聊天消息被清空');
|
return await permision.requestAndroidPermission('android.permission.RECORD_AUDIO')
|
||||||
}
|
},
|
||||||
}
|
// 切换聊天信息
|
||||||
})
|
msgType() {
|
||||||
}
|
this.importTabs = this.importTabs === 1 ? 0 : 1
|
||||||
},
|
},
|
||||||
methods: {
|
// 录制语音消息
|
||||||
// 检查安卓录制权限
|
startAudio(e) {
|
||||||
async getAndroidPermission() {
|
this.getAndroidPermission().then(code => {
|
||||||
return await permision.requestAndroidPermission('android.permission.RECORD_AUDIO')
|
switch (code) {
|
||||||
},
|
case 1:
|
||||||
// 切换聊天信息
|
this.showAudioTranscribe = true
|
||||||
msgType() {
|
recorderManager.start()
|
||||||
this.importTabs = this.importTabs === 1 ? 0 : 1
|
transcribe = setInterval(() => {
|
||||||
},
|
this.transcribeTime -= 1
|
||||||
// 录制语音消息
|
if (this.transcribeTime === 0) {
|
||||||
startAudio(e) {
|
this.chendAudio()
|
||||||
this.getAndroidPermission().then(code => {
|
}
|
||||||
switch (code) {
|
}, 1000)
|
||||||
case 1:
|
break;
|
||||||
this.showAudioTranscribe = true
|
case 0:
|
||||||
recorderManager.start()
|
uni.showToast({
|
||||||
transcribe = setInterval(() => {
|
title: '暂无麦克风权限,请前往应用设置开启麦克风',
|
||||||
this.transcribeTime -= 1
|
icon: 'none'
|
||||||
if (this.transcribeTime === 0) {
|
})
|
||||||
this.chendAudio()
|
break;
|
||||||
}
|
case -1:
|
||||||
}, 1000)
|
uni.showToast({
|
||||||
break;
|
title: '应用权限错误',
|
||||||
case 0:
|
icon: 'none'
|
||||||
uni.showToast({
|
})
|
||||||
title: '暂无麦克风权限,请前往应用设置开启麦克风',
|
break;
|
||||||
icon: 'none'
|
}
|
||||||
})
|
})
|
||||||
break;
|
},
|
||||||
case -1:
|
// 结束录音
|
||||||
uni.showToast({
|
chendAudio(e) {
|
||||||
title: '应用权限错误',
|
if (!this.showAudioTranscribe) return
|
||||||
icon: 'none'
|
recorderManager.stop()
|
||||||
})
|
clearInterval(transcribe)
|
||||||
break;
|
// 监听录音结束
|
||||||
}
|
recorderManager.onStop(res => {
|
||||||
})
|
if (res.tempFilePath) this.audioSrc = res.tempFilePath
|
||||||
},
|
im.sendVoiceMsg(this.conversationType, this.targetId, res.tempFilePath, (60 - this
|
||||||
// 结束录音
|
.transcribeTime), () => {
|
||||||
chendAudio(e) {
|
this.getMessageList()
|
||||||
if (!this.showAudioTranscribe) return
|
|
||||||
recorderManager.stop()
|
|
||||||
clearInterval(transcribe)
|
|
||||||
this.transcribeTime = 60
|
|
||||||
this.showAudioTranscribe = false
|
|
||||||
},
|
|
||||||
getMessageList() {
|
|
||||||
// 获取消息列表
|
|
||||||
const objectNames = [
|
|
||||||
'RC:TxtMsg',
|
|
||||||
'RC:VcMsg',
|
|
||||||
'RC:HQVCMsg',
|
|
||||||
'RC:ImgMsg',
|
|
||||||
'RC:GIFMsg',
|
|
||||||
'RC:ImgTextMsg',
|
|
||||||
'RC:FileMsg',
|
|
||||||
'RC:LBSMsg',
|
|
||||||
'RC:SightMsg',
|
|
||||||
'RC:ReferenceMsg',
|
|
||||||
'RC:CombineMsg'
|
|
||||||
]
|
|
||||||
const timeStamp = new Date().getTime()
|
|
||||||
const count = 20 // 获取的消息数量
|
|
||||||
const isForward = true // 是否向前获取
|
|
||||||
RongIMLib.getHistoryMessagesByTimestamp(this.conversationType, this.targetId, objectNames, timeStamp,
|
|
||||||
count,
|
|
||||||
isForward,
|
|
||||||
({
|
|
||||||
code,
|
|
||||||
messages
|
|
||||||
}) => {
|
|
||||||
if (code === 0) {
|
|
||||||
console.log(this.messages)
|
|
||||||
this.messages = messages.reverse()
|
|
||||||
this.scrollBottom()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
send() {
|
|
||||||
if(this.inputTxt === '') return
|
|
||||||
im.sendMsg(this.conversationType, this.targetId, this.inputTxt, () => {
|
|
||||||
this.getMessageList()
|
|
||||||
this.inputTxt = ''
|
|
||||||
})
|
|
||||||
},
|
|
||||||
showFriend(targetId, type) {
|
|
||||||
uni.navigateTo({
|
|
||||||
url: type === 1 ? '/pages/im/friends/mine?targetId=' +targetId : '/pages/im/friends/info?targetId=' +targetId
|
|
||||||
})
|
|
||||||
},
|
|
||||||
scrollBottom() {
|
|
||||||
setTimeout(() => {
|
|
||||||
let el = this.$refs.chatBottom
|
|
||||||
ChatList.scrollToElement(el, {
|
|
||||||
animated: true
|
|
||||||
})
|
})
|
||||||
},100)
|
this.transcribeTime = 60
|
||||||
}
|
this.showAudioTranscribe = false
|
||||||
}
|
})
|
||||||
|
},
|
||||||
}
|
getMessageList() {
|
||||||
</script>
|
// 获取消息列表
|
||||||
|
const objectNames = [
|
||||||
<style scoped>
|
'RC:TxtMsg',
|
||||||
.audio-transcribe {
|
'RC:VcMsg',
|
||||||
background: rgba(0,0,0,.6);
|
'RC:HQVCMsg',
|
||||||
position: fixed;
|
'RC:ImgMsg',
|
||||||
height: 200rpx;
|
'RC:GIFMsg',
|
||||||
width: 300rpx;
|
'RC:ImgTextMsg',
|
||||||
border-radius: 10rpx;
|
'RC:FileMsg',
|
||||||
z-index: 99;
|
'RC:LBSMsg',
|
||||||
top: 550rpx;
|
'RC:SightMsg',
|
||||||
left: 225rpx;
|
'RC:ReferenceMsg',
|
||||||
flex-direction: column;
|
'RC:CombineMsg'
|
||||||
align-items: center;
|
]
|
||||||
justify-content: center;
|
const timeStamp = new Date().getTime()
|
||||||
}
|
const count = 30 // 获取的消息数量
|
||||||
|
const isForward = true // 是否向前获取
|
||||||
.audio-transcribe-src{
|
RongIMLib.getHistoryMessagesByTimestamp(this.conversationType, this.targetId, objectNames, timeStamp,
|
||||||
width: 88rpx;
|
count,
|
||||||
height: 88rpx;
|
isForward,
|
||||||
}
|
({
|
||||||
|
code,
|
||||||
.audio-transcribe-text {
|
messages
|
||||||
font-size: 28rpx;
|
}) => {
|
||||||
color: #FFFFFF;
|
if (code === 0) {
|
||||||
}
|
this.messages = messages.reverse()
|
||||||
|
this.scrollBottom()
|
||||||
/* 窗口 */
|
}
|
||||||
.chat{
|
}
|
||||||
background: #F3F6FB;
|
)
|
||||||
flex: 1;
|
},
|
||||||
}
|
send() {
|
||||||
.chat-scroll{
|
if (this.inputTxt === '') return
|
||||||
flex: 1;
|
im.sendMsg(this.conversationType, this.targetId, this.inputTxt, () => {
|
||||||
}
|
this.getMessageList()
|
||||||
.cell{
|
this.inputTxt = ''
|
||||||
padding:10rpx 30rpx;
|
})
|
||||||
}
|
},
|
||||||
.cell-time{
|
showFriend(targetId, type) {
|
||||||
justify-content: center;
|
uni.navigateTo({
|
||||||
align-items: center;
|
url: type === 1 ? '/pages/im/friends/mine?targetId=' + targetId :
|
||||||
padding-bottom: 20rpx;
|
'/pages/im/friends/info?targetId=' + targetId
|
||||||
}
|
})
|
||||||
.cell-time-text{
|
},
|
||||||
background: #fff;
|
scrollBottom() {
|
||||||
font-size: 24rpx;
|
setTimeout(() => {
|
||||||
color: #666;
|
let el = this.$refs.chatBottom
|
||||||
line-height: 40rpx;
|
ChatList.scrollToElement(el, {
|
||||||
padding: 0 20rpx;
|
animated: true
|
||||||
border-radius: 10rpx;
|
})
|
||||||
}
|
}, 100)
|
||||||
.cell-item{
|
}
|
||||||
width: 690rpx;
|
}
|
||||||
justify-content: flex-start;
|
|
||||||
}
|
}
|
||||||
.cell-footer{
|
</script>
|
||||||
height: 20rpx;
|
|
||||||
}
|
<style scoped>
|
||||||
.active{
|
.audio-transcribe {
|
||||||
width: 78rpx;
|
background: rgba(0, 0, 0, .6);
|
||||||
height: 78rpx;
|
position: fixed;
|
||||||
background-color: white;
|
height: 200rpx;
|
||||||
border-radius: 10rpx;
|
width: 300rpx;
|
||||||
}
|
border-radius: 10rpx;
|
||||||
.msg{
|
z-index: 99;
|
||||||
margin: 0 20rpx;
|
top: 550rpx;
|
||||||
}
|
left: 225rpx;
|
||||||
.state{
|
flex-direction: column;
|
||||||
padding-top: 10rpx;
|
align-items: center;
|
||||||
}
|
justify-content: center;
|
||||||
.state-text{
|
}
|
||||||
font-size: 24rpx;
|
|
||||||
color: #666;
|
.audio-transcribe-src {
|
||||||
}
|
width: 88rpx;
|
||||||
.cell-item.left{
|
height: 88rpx;
|
||||||
flex-direction: row;
|
}
|
||||||
}
|
|
||||||
.cell-item.right{
|
.audio-transcribe-text {
|
||||||
flex-direction: row-reverse;
|
font-size: 28rpx;
|
||||||
}
|
color: #FFFFFF;
|
||||||
.cell-item.right .state{
|
}
|
||||||
flex-direction: row;
|
|
||||||
justify-content: flex-end;
|
/* 窗口 */
|
||||||
}
|
.chat {
|
||||||
/* footer */
|
background: #F3F6FB;
|
||||||
.chat-footer{
|
flex: 1;
|
||||||
background: white;
|
}
|
||||||
padding: 20rpx 30rpx;
|
|
||||||
display: flex;
|
.chat-scroll {
|
||||||
justify-content: space-between;
|
flex: 1;
|
||||||
flex-direction: row;
|
}
|
||||||
}
|
|
||||||
.msg-type{
|
.cell {
|
||||||
width: 70rpx;
|
padding: 10rpx 30rpx;
|
||||||
height: 70rpx;
|
}
|
||||||
}
|
|
||||||
.msg-type > .msg-type-icon{
|
.cell-time {
|
||||||
margin: 5rpx;
|
justify-content: center;
|
||||||
width: 60rpx;
|
align-items: center;
|
||||||
height: 60rpx;
|
padding-bottom: 20rpx;
|
||||||
}
|
}
|
||||||
.chat-mp3{
|
|
||||||
background: #F3F6FB;
|
.cell-time-text {
|
||||||
height: 70rpx;
|
background: #fff;
|
||||||
line-height: 70rpx;
|
font-size: 24rpx;
|
||||||
justify-content: center;
|
color: #666;
|
||||||
align-items: center;
|
line-height: 40rpx;
|
||||||
width: 460rpx;
|
padding: 0 20rpx;
|
||||||
border-radius: 10rpx;
|
border-radius: 10rpx;
|
||||||
margin-right: 15rpx;
|
}
|
||||||
}
|
|
||||||
.chat-mp3-text{
|
.cell-item {
|
||||||
font-size: 30rpx;
|
width: 690rpx;
|
||||||
color: #333;
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
.chat-input{
|
|
||||||
background: #F3F6FB;
|
.cell-footer {
|
||||||
height: 70rpx;
|
height: 20rpx;
|
||||||
width: 460rpx;
|
}
|
||||||
border-radius: 10rpx;
|
|
||||||
margin-right: 15rpx;
|
.active {
|
||||||
padding: 0 20rpx;
|
width: 78rpx;
|
||||||
}
|
height: 78rpx;
|
||||||
.chat-push{
|
background-color: white;
|
||||||
background: #34CE98;
|
border-radius: 10rpx;
|
||||||
color: white;
|
}
|
||||||
width: 120rpx;
|
|
||||||
line-height: 70rpx;
|
.msg {
|
||||||
text-align: center;
|
margin: 0 20rpx;
|
||||||
border-radius: 10rpx;
|
}
|
||||||
font-size: 30rpx;
|
|
||||||
font-weight: bold;
|
.state {
|
||||||
}
|
padding-top: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-text {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-item.left {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-item.right {
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-item.right .state {
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* footer */
|
||||||
|
.chat-footer {
|
||||||
|
background: white;
|
||||||
|
padding: 20rpx 30rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.msg-type {
|
||||||
|
width: 70rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.msg-type>.msg-type-icon {
|
||||||
|
margin: 5rpx;
|
||||||
|
width: 60rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-mp3 {
|
||||||
|
background: #F3F6FB;
|
||||||
|
height: 70rpx;
|
||||||
|
line-height: 70rpx;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 460rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
margin-right: 15rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-mp3-text {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-input {
|
||||||
|
background: #F3F6FB;
|
||||||
|
height: 70rpx;
|
||||||
|
width: 460rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
margin-right: 15rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-push {
|
||||||
|
background: #34CE98;
|
||||||
|
color: white;
|
||||||
|
width: 120rpx;
|
||||||
|
line-height: 70rpx;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ const addListeners = () => {
|
|||||||
RongIMLib.addReceiveMessageListener((res) => {
|
RongIMLib.addReceiveMessageListener((res) => {
|
||||||
console.log('收到消息', res.data.message);
|
console.log('收到消息', res.data.message);
|
||||||
const message = res.data.message
|
const message = res.data.message
|
||||||
if (inArray(message.objectName, notifyMsgTypes)) {
|
if (inArray(message.objectName, notifyMsgTypes)) {
|
||||||
console.log('new Message');
|
console.log('new Message');
|
||||||
newMessage(message)
|
newMessage(message)
|
||||||
}
|
}
|
||||||
@@ -235,6 +235,38 @@ const sendMsg = (conversationType, targetId, content, callback) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* conversationType 会话类型
|
||||||
|
* voiceUrl 本地的录音路径
|
||||||
|
* time 录音时长
|
||||||
|
*/
|
||||||
|
const sendVoiceMsg = (conversationType, targetId, voiceUrl, time, callback) => {
|
||||||
|
console.log('sendVoiceMsg', plus.io.convertLocalFileSystemURL(voiceUrl));
|
||||||
|
const msg = {
|
||||||
|
conversationType: conversationType,
|
||||||
|
targetId: String(targetId),
|
||||||
|
content: {
|
||||||
|
objectName: 'RC:HQVCMsg',
|
||||||
|
local: 'file:///' + plus.io.convertLocalFileSystemURL(voiceUrl),
|
||||||
|
duration: time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RongIMLib.sendMediaMessage(msg, {
|
||||||
|
success: (messageId) => {
|
||||||
|
callback(messageId);
|
||||||
|
},
|
||||||
|
progress: (progress, messageId) => {
|
||||||
|
console.log(messageId);
|
||||||
|
},
|
||||||
|
cancel: (messageId) => {
|
||||||
|
// 发送取消回调
|
||||||
|
},
|
||||||
|
error: (errorCode, messageId) => {
|
||||||
|
console.log(errorCode, messageId);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步好友信息,保存头像地址等
|
* 同步好友信息,保存头像地址等
|
||||||
@@ -252,6 +284,7 @@ export default {
|
|||||||
initIm,
|
initIm,
|
||||||
connect,
|
connect,
|
||||||
sendMsg,
|
sendMsg,
|
||||||
|
sendVoiceMsg,
|
||||||
setNotifyBadge,
|
setNotifyBadge,
|
||||||
syncFriends,
|
syncFriends,
|
||||||
syncUserInfo
|
syncUserInfo
|
||||||
|
|||||||
Reference in New Issue
Block a user