From 716792404c107f8364a54028fb9070420b7eae0a Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 7 Feb 2022 13:33:56 +0800 Subject: [PATCH] =?UTF-8?q?IM=E5=BD=95=E9=9F=B3=E7=BB=84=E4=BB=B6=E6=8B=86?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/private/chat.nvue | 179 +++------------------ pages/im/private/components/sentText.nvue | 80 +++++++-- pages/im/private/components/sentVoice.nvue | 149 +++++++++++++++-- 3 files changed, 221 insertions(+), 187 deletions(-) diff --git a/pages/im/private/chat.nvue b/pages/im/private/chat.nvue index 991a103..c0bfd59 100644 --- a/pages/im/private/chat.nvue +++ b/pages/im/private/chat.nvue @@ -8,14 +8,14 @@ + @click="showUser(targetId, item.messageDirection)"> + :msg="item.content" /> + :msg="item.content.content" /> + :msg="item.content.content" /> {{ item.sentStatus == 50 ? '已读': '未读'}} @@ -27,26 +27,15 @@ - + - + - - - 按住说话 - - - - - - 发送 - - - - - 录音中 {{transcribeTime}} s + + @@ -57,20 +46,18 @@ } from '@/utils/filters.js' import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index" import im from '@/utils/im/index.js' - import permision from "@/js_sdk/wa-permission/permission.js" import showVoice from './components/showVoice' import showImage from './components/showImage' import showText from './components/showText' + import sentText from './components/sentText' + import sentVoice from './components/sentVoice' - var transcribe - const recorderManager = uni.getRecorderManager() const ChatList = uni.requireNativePlugin('dom') export default { data() { return { targetId: '', - inputTxt: '', messages: [], conversationType: 1, userInfo: { @@ -78,16 +65,15 @@ userId: '', portraitUrl: '' }, - importTabs: 1, - showAudioTranscribe: false, - transcribeTime: 60, - audioContextPaused: true + chatType: 1 // 0 语音,1 文本 } }, components: { showVoice, showImage, - showText + showText, + sentText, + sentVoice }, onLoad(e) { this.targetId = e.targetId @@ -128,68 +114,13 @@ onUnload() { RongIMLib.clearReadReceiptReceivedListener() }, - computed: { - disabled() { - return this.inputTxt.length == 0 - } - }, methods: { customCN(val) { return timeCustomCN(val) }, - // 检查安卓录制权限 - async getAndroidPermission() { - return await permision.requestAndroidPermission('android.permission.RECORD_AUDIO') - }, - // 切换聊天信息 + // 切换聊天类型 msgType() { - this.importTabs = this.importTabs === 1 ? 0 : 1 - }, - // 录制语音消息 - startAudio(e) { - this.getAndroidPermission().then(code => { - switch (code) { - case 1: - this.showAudioTranscribe = true - recorderManager.start() - transcribe = setInterval(() => { - this.transcribeTime -= 1 - if (this.transcribeTime === 0) { - this.chendAudio() - } - }, 1000) - break; - case 0: - uni.showToast({ - title: '暂无麦克风权限,请前往应用设置开启麦克风', - icon: 'none' - }) - break; - case -1: - uni.showToast({ - title: '应用权限错误', - icon: 'none' - }) - break; - } - }) - }, - // 结束录音 - chendAudio(e) { - if (!this.showAudioTranscribe) return - recorderManager.stop() - clearInterval(transcribe) - // 监听录音结束 - recorderManager.onStop(res => { - im.sentVoice(this.conversationType, this.targetId, res.tempFilePath, (60 - this - .transcribeTime), () => { - setTimeout(() => { - this.getMessageList() - }, 500) - }) - this.transcribeTime = 60 - this.showAudioTranscribe = false - }) + this.chatType = this.chatType === 1 ? 0 : 1 }, // 获取消息列表 getMessageList() { @@ -198,18 +129,8 @@ this.scrollBottom() }) }, - // 发送文本消息 - send() { - if (this.inputTxt === '') return - im.sentText(this.conversationType, this.targetId, this.inputTxt, () => { - setTimeout(() => { - this.getMessageList() - }, 500) - this.inputTxt = '' - }) - }, - // 展示好友信息 - showFriend(targetId, type) { + // 展示好友信息, type 1 是自己, 2 是对方 + showUser(targetId, type) { uni.navigateTo({ url: type === 1 ? '/pages/im/friends/mine?targetId=' + targetId : '/pages/im/friends/info?targetId=' + targetId @@ -229,30 +150,6 @@ diff --git a/pages/im/private/components/sentText.nvue b/pages/im/private/components/sentText.nvue index bb85538..52bab6b 100644 --- a/pages/im/private/components/sentText.nvue +++ b/pages/im/private/components/sentText.nvue @@ -1,15 +1,67 @@ - - - - - diff --git a/pages/im/private/components/sentVoice.nvue b/pages/im/private/components/sentVoice.nvue index bb85538..1452e8a 100644 --- a/pages/im/private/components/sentVoice.nvue +++ b/pages/im/private/components/sentVoice.nvue @@ -1,15 +1,136 @@ - - - - -