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 @@ - - - 录音时长:{{duration}} + + + {{stateTip}} + 时长: {{state=='STOP'?0:parseInt(rc.duration)}}s - - + + + 开始录音 暂停录音 继续录音 - 结束录音 - 播放录音 + + 结束录音 + 播放录音 + + 停止播放 + 重新录音 立即发送 @@ -19,9 +25,7 @@ - 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; + } } }