123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <template>
- <view class="text_message_container bg_container" v-if="isText">
- <mp-html :previewImg="false" :showImgMenu="false" :lazyLoad="false" :content="getContent" />
- </view>
- <view @click="playAudio" class="audio_message_container bg_container"
- :class="{ audio_message_container_self: isSender }" v-else>
- <view class="cricleplay">
- <view class="small"></view>
- <view class="middle" :class="{ stopanimate: !playing }"></view>
- <view class="large" :class="{ stopanimate: !playing }"></view>
- </view>
- <text class="audio_duration">{{ data.soundElem.duration }}''</text>
- </view>
- </template>
- <script>
- export default {
- name: "MassMessageRender",
- props: {
- isSender: Boolean,
- data: Object,
- },
- data() {
- return {
- playing: false,
- paused: false,
- innerAudioContext: uni.createInnerAudioContext(),
- };
- },
- mounted() {
- this.setPlayListener();
- },
- beforeDestroy() {
- this.innerAudioContext.destroy();
- },
- computed: {
- isText() {
- return this.data.textElem !== null
- },
- getContent() {
- if (this.isText) {
- return this.data.textElem.content
- }
- },
- },
- methods: {
- setPlayListener() {
- const onPlayHandler = () => {
- this.playing = true;
- this.paused = false;
- };
- const onPauseOrStorHandler = () => {
- this.playing = false;
- this.paused = true;
- };
- this.innerAudioContext.onPlay(onPlayHandler);
- this.innerAudioContext.onPause(onPauseOrStorHandler);
- this.innerAudioContext.onEnded(onPauseOrStorHandler);
- },
- playAudio() {
- this.setPlayListener();
- if (this.paused) {
- this.innerAudioContext.play();
- return;
- }
- if (this.playing) {
- this.innerAudioContext.pause();
- return;
- }
- this.innerAudioContext.src = this.data.soundElem.sourceUrl;
- this.innerAudioContext.play();
- },
- }
- };
- </script>
- <style lang="scss" scoped>
- .bg_container {
- padding: 16rpx 24rpx;
- border-radius: 0rpx 12rpx 12rpx 12rpx;
- background-color: #f0f0f0;
- }
- .audio_message_container {
- @include vCenterBox();
- .audio_duration {
- font-size: 28rpx;
- }
- .cricleplay {
- display: flex;
- align-items: center;
- margin-right: 12rpx;
- .small {
- width: 5px;
- height: 5px;
- border-style: solid;
- border-color: #3870e4;
- border-top-color: transparent;
- border-left-color: transparent;
- border-bottom-color: transparent;
- border-radius: 50%;
- box-sizing: border-box;
- vertical-align: middle;
- display: inline-block;
- }
- .middle {
- width: 10px;
- height: 10px;
- border-style: solid;
- border-color: #3870e4;
- border-top-color: transparent;
- border-left-color: transparent;
- border-bottom-color: transparent;
- border-radius: 50%;
- box-sizing: border-box;
- vertical-align: middle;
- display: inline-block;
- margin-left: -5px;
- animation: show2 2s ease-in-out infinite;
- opacity: 1;
- }
- @keyframes show2 {
- 0% {
- opacity: 0;
- }
- 30% {
- opacity: 1;
- }
- 100% {
- opacity: 0;
- }
- }
- .large {
- width: 20px;
- height: 20px;
- border-style: solid;
- border-color: #3870e4;
- border-top-color: transparent;
- border-left-color: transparent;
- border-bottom-color: transparent;
- border-radius: 50%;
- box-sizing: border-box;
- vertical-align: middle;
- display: inline-block;
- margin-left: -15px;
- animation: show3 2s ease-in-out infinite;
- opacity: 1;
- }
- @keyframes show3 {
- 0% {
- opacity: 0;
- }
- 60% {
- opacity: 1;
- }
- 100% {
- opacity: 0;
- }
- }
- .stopanimate {
- -moz-animation-name: none;
- -webkit-animation-name: none;
- -ms-animation-name: none;
- animation-name: none;
- }
- }
- &_self {
- flex-direction: row-reverse;
- .cricleplay {
- margin-right: 0;
- margin-left: 12rpx;
- flex-direction: row-reverse;
- .small,
- .middle,
- .large {
- border-left-color: #3870e4;
- border-right-color: transparent;
- }
- .middle {
- margin-left: 0;
- margin-right: -5px;
- }
- .large {
- margin-left: 0;
- margin-right: -15px;
- }
- }
- }
- }
- </style>
|