2025-12-11 22:33:31 +08:00
|
|
|
<template>
|
|
|
|
|
<view class="voice_message_container bg_container">
|
2025-12-17 08:47:58 +08:00
|
|
|
<view @tap="handleAudio"
|
|
|
|
|
:class="{'content-audio-container':true,'chat-audio-container-me':true}"
|
|
|
|
|
:style="'width:'+((message.soundElem.duration)*2+130)+'rpx'">
|
|
|
|
|
<view class="voice_icon"
|
|
|
|
|
:class="[
|
|
|
|
|
{ voice_icon_right: isSender },
|
|
|
|
|
{ voice_icon_left: !isSender },
|
|
|
|
|
{ voice_icon_right_an: isSender && message.clientMsgID == storeCurrentMsg.clientMsgID},
|
|
|
|
|
{ voice_icon_left_an: !isSender && message.clientMsgID == storeCurrentMsg.clientMsgID }
|
|
|
|
|
]">
|
|
|
|
|
</view>
|
|
|
|
|
<view class="">{{message.soundElem.duration}}s</view>
|
|
|
|
|
</view>
|
2025-12-11 22:33:31 +08:00
|
|
|
</view>
|
|
|
|
|
</template>v
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-12-17 08:47:58 +08:00
|
|
|
import {mapGetters,mapActions} from "vuex";
|
|
|
|
|
import util from "@/util"
|
|
|
|
|
import md5 from "md5";
|
2025-12-11 22:33:31 +08:00
|
|
|
export default {
|
|
|
|
|
name: "VoiceMessageRender",
|
|
|
|
|
components: {},
|
|
|
|
|
props: {
|
|
|
|
|
message: Object,
|
2025-12-17 08:47:58 +08:00
|
|
|
isSender: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2025-12-11 22:33:31 +08:00
|
|
|
conversationID:String,
|
|
|
|
|
},
|
|
|
|
|
data() {
|
2025-12-17 08:47:58 +08:00
|
|
|
return {
|
|
|
|
|
src:"",
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed:{
|
|
|
|
|
...mapGetters(["storeCurrentMsg"]),
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.init();
|
2025-12-11 22:33:31 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
2025-12-17 08:47:58 +08:00
|
|
|
async init(){
|
2025-12-23 00:18:46 +08:00
|
|
|
//console.log(this.message);
|
2025-12-17 08:47:58 +08:00
|
|
|
const self = this;
|
|
|
|
|
let audio = this.message.soundElem;
|
|
|
|
|
//soundPath
|
|
|
|
|
// 如果有远程 snapshotUrl,则下载到 cachePath
|
|
|
|
|
const snapshotUrl = audio.sourceUrl;
|
|
|
|
|
const key = md5(snapshotUrl || '');
|
|
|
|
|
const save_file_name = `audio_${key}.${audio.soundType}`;
|
|
|
|
|
const cachePath = `${this.conversationID}/${save_file_name}`;
|
|
|
|
|
if (typeof plus === 'undefined' || !cachePath) return;
|
|
|
|
|
util.cacheFile(snapshotUrl,cachePath,(fn)=>{
|
|
|
|
|
self.src = fn;
|
2025-12-23 00:18:46 +08:00
|
|
|
//console.log(fn);
|
2025-12-17 08:47:58 +08:00
|
|
|
},(e)=>{
|
|
|
|
|
console.log(e);
|
|
|
|
|
},(e)=>{
|
|
|
|
|
console.log(e);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
handleAudio(){
|
|
|
|
|
const event = {
|
|
|
|
|
message:this.message,
|
|
|
|
|
src:this.src,
|
|
|
|
|
type:'audio_msg_click'
|
|
|
|
|
};
|
|
|
|
|
this.$emit("messageEvent",event);
|
|
|
|
|
}
|
2025-12-11 22:33:31 +08:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2025-12-17 08:47:58 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
//语音信息样式
|
|
|
|
|
.content-audio-container {
|
|
|
|
|
border-radius: 10rpx;
|
|
|
|
|
padding: 0 20rpx;
|
|
|
|
|
/* #ifndef APP-NVUE */
|
|
|
|
|
max-width: 500rpx;
|
|
|
|
|
/* #endif */
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
|
|
.voice_icon {
|
|
|
|
|
height: 34rpx;
|
|
|
|
|
width: 34rpx;
|
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
|
background-size: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.voice_icon_right {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-left-3.png');
|
|
|
|
|
margin-left: 10rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.voice_icon_left {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-right-3.png');
|
|
|
|
|
margin-right: 10rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.voice_icon_right_an {
|
|
|
|
|
animation: voiceAn_right 1s linear alternate infinite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.voice_icon_left_an {
|
|
|
|
|
animation: voiceAn_left 1s linear alternate infinite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@keyframes voiceAn_right {
|
|
|
|
|
0% {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-left-1.png');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
50% {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-left-2.png');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
100% {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-left-3.png');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@keyframes voiceAn_left {
|
|
|
|
|
0% {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-right-1.png');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
50% {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-right-2.png');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
100% {
|
|
|
|
|
background-image: url('@/static/images/chat/voice/voice-right-3.png');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|