From 2ad211cefe1ab49980b0c934f0bf814272613ef1 Mon Sep 17 00:00:00 2001 From: "xie.bx" Date: Tue, 8 Nov 2022 20:39:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E8=AF=AD=E9=9F=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bx/common/enums/FileTypeEnum.java | 4 +- im-ui/package.json | 2 +- im-ui/src/components/chat/ChatBox.vue | 27 ++++- im-ui/src/components/chat/ChatVoice.vue | 109 ++++++++++++------ im-ui/src/components/chat/MessageItem.vue | 24 +++- 5 files changed, 127 insertions(+), 39 deletions(-) diff --git a/commom/src/main/java/com/bx/common/enums/FileTypeEnum.java b/commom/src/main/java/com/bx/common/enums/FileTypeEnum.java index 35091b1..a41ac1f 100644 --- a/commom/src/main/java/com/bx/common/enums/FileTypeEnum.java +++ b/commom/src/main/java/com/bx/common/enums/FileTypeEnum.java @@ -4,7 +4,9 @@ public enum FileTypeEnum { FILE(0,"文件"), IMAGE(1,"图片"), - VIDEO(2,"视频"); + VIDEO(2,"视频"), + AUDIO(3,"声音"); + private Integer code; diff --git a/im-ui/package.json b/im-ui/package.json index b95209b..0413271 100644 --- a/im-ui/package.json +++ b/im-ui/package.json @@ -11,7 +11,7 @@ "axios": "^1.1.3", "core-js": "^3.6.5", "element-ui": "^2.15.10", - "recorderx": "^2.0.2", + "js-audio-recorder": "^1.0.7", "sass": "^1.47.0", "sass-loader": "^7.3.1", "vue": "^2.6.11", diff --git a/im-ui/src/components/chat/ChatBox.vue b/im-ui/src/components/chat/ChatBox.vue index 14bf987..477c900 100644 --- a/im-ui/src/components/chat/ChatBox.vue +++ b/im-ui/src/components/chat/ChatBox.vue @@ -48,7 +48,7 @@ - + @@ -231,6 +231,31 @@ closeVoiceBox(){ this.showVoice = false; }, + handleSendVoice(data){ + let msgInfo = { + content: JSON.stringify(data), + type: 3 + } + // 填充对方id + this.setTargetId(msgInfo, this.chat.targetId); + this.$http({ + url: this.messageAction, + method: 'post', + data: msgInfo + }).then(() => { + this.$message.success("发送成功"); + msgInfo.sendTime = new Date().getTime(); + msgInfo.sendId = this.$store.state.userStore.userInfo.id; + msgInfo.selfSend = true; + this.$store.commit("insertMessage", msgInfo); + // 保持输入框焦点 + this.$refs.sendBox.focus(); + // 滚动到底部 + this.scrollToBottom(); + // 关闭录音窗口 + this.showVoice = false; + }) + }, setTargetId(msgInfo, targetId) { if (this.chat.type == "GROUP") { msgInfo.groupId = targetId; diff --git a/im-ui/src/components/chat/ChatVoice.vue b/im-ui/src/components/chat/ChatVoice.vue index a18250e..80b335a 100644 --- a/im-ui/src/components/chat/ChatVoice.vue +++ b/im-ui/src/components/chat/ChatVoice.vue @@ -1,15 +1,21 @@ - diff --git a/im-ui/src/components/chat/MessageItem.vue b/im-ui/src/components/chat/MessageItem.vue index cd05691..9e89f7c 100644 --- a/im-ui/src/components/chat/MessageItem.vue +++ b/im-ui/src/components/chat/MessageItem.vue @@ -32,6 +32,9 @@ +
+ +
@@ -65,6 +68,12 @@ required: true } }, + data(){ + return { + audioPlayState: 'STOP', + } + + }, methods:{ handleSendFail(){ this.$message.error("该文件已发送失败,目前不支持自动重新发送,建议手动重新发送") @@ -74,7 +83,15 @@ if(imageUrl){ this.$store.commit('showFullImageBox',imageUrl); } - } + }, + handlePlayVoice(){ + if(!this.audio){ + this.audio = new Audio(); + } + this.audio.src = JSON.parse(this.msgInfo.content).url; + this.audio.play(); + this.handlePlayVoice = 'RUNNING'; + } }, computed:{ loading(){ @@ -229,6 +246,11 @@ } } + + .im-msg-voice { + font-size: 14px; + cursor: pointer; + } } }