|  | @@ -1,33 +1,27 @@
 | 
											
												
													
														|  |  <template>
 |  |  <template>
 | 
											
												
													
														|  | -  <div
 |  | 
 | 
											
												
													
														|  | -    class="message-audio"
 |  | 
 | 
											
												
													
														|  | -    :class="[data.message.flow === 'out' && 'reserve']"
 |  | 
 | 
											
												
													
														|  | -    @click.stop="play"
 |  | 
 | 
											
												
													
														|  | -    :style="`width: ${data?.second * 10 + 40}Px`"
 |  | 
 | 
											
												
													
														|  | -  >
 |  | 
 | 
											
												
													
														|  | -    <i
 |  | 
 | 
											
												
													
														|  | -      class="icon icon-voice"
 |  | 
 | 
											
												
													
														|  | -      :class="[data.message.flow === 'out' && 'icon-reserve']"
 |  | 
 | 
											
												
													
														|  | -    ></i>
 |  | 
 | 
											
												
													
														|  | -    <label>{{ data.second }}s</label>
 |  | 
 | 
											
												
													
														|  | -    <audio ref="audio" :src="data.url"></audio>
 |  | 
 | 
											
												
													
														|  | 
 |  | +  <div class="message-audio" :class="[data.message.flow === 'out' && 'reserve']" @click.stop="play" :style="`width: ${data?.second * 10 + 40}Px`">
 | 
											
												
													
														|  | 
 |  | +    <i class="icon icon-voice" :class="[data.message.flow === 'out' && 'icon-reserve', data.message.isPlay ? 'icon-voice-active' : '']"></i>
 | 
											
												
													
														|  | 
 |  | +    <!-- 消息时间不到1s,默认显示1s -->
 | 
											
												
													
														|  | 
 |  | +    <label>{{ data.second ? data.second : 1 }}s</label>
 | 
											
												
													
														|  | 
 |  | +    <audio ref="audio" :src="data.url" @pause="onStopAnimation" @ended="onStopAnimation"></audio>
 | 
											
												
													
														|  |    </div>
 |  |    </div>
 | 
											
												
													
														|  |  </template>
 |  |  </template>
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  <script lang="ts">
 |  |  <script lang="ts">
 | 
											
												
													
														|  | -import { defineComponent, watch, reactive, toRefs, ref } from 'vue';
 |  | 
 | 
											
												
													
														|  | 
 |  | +import { defineComponent, watch, reactive, toRefs, ref } from "vue";
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  export default defineComponent({
 |  |  export default defineComponent({
 | 
											
												
													
														|  |    props: {
 |  |    props: {
 | 
											
												
													
														|  |      data: {
 |  |      data: {
 | 
											
												
													
														|  |        type: Object,
 |  |        type: Object,
 | 
											
												
													
														|  | -      default: () => ({})
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +      default: () => ({}),
 | 
											
												
													
														|  | 
 |  | +    },
 | 
											
												
													
														|  |    },
 |  |    },
 | 
											
												
													
														|  |    setup(props: any, ctx: any) {
 |  |    setup(props: any, ctx: any) {
 | 
											
												
													
														|  |      const data = reactive({
 |  |      const data = reactive({
 | 
											
												
													
														|  | -      data: {},
 |  | 
 | 
											
												
													
														|  | -      show: false
 |  | 
 | 
											
												
													
														|  | 
 |  | +      data: {} as any,
 | 
											
												
													
														|  | 
 |  | +      show: false,
 | 
											
												
													
														|  | 
 |  | +      isPlay: false, // 是否在播放
 | 
											
												
													
														|  |      });
 |  |      });
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      const audio = ref(null);
 |  |      const audio = ref(null);
 | 
											
										
											
												
													
														|  | @@ -41,35 +35,48 @@ export default defineComponent({
 | 
											
												
													
														|  |      );
 |  |      );
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      const play = () => {
 |  |      const play = () => {
 | 
											
												
													
														|  | -      const audios = document.getElementsByTagName('audio');
 |  | 
 | 
											
												
													
														|  | 
 |  | +      const audios = document.getElementsByTagName("audio");
 | 
											
												
													
														|  |        for (const audio of audios) {
 |  |        for (const audio of audios) {
 | 
											
												
													
														|  |          if (!audio.paused) {
 |  |          if (!audio.paused) {
 | 
											
												
													
														|  | 
 |  | +          const parentNode: any = audio.parentNode;
 | 
											
												
													
														|  | 
 |  | +          parentNode.querySelector(".icon-voice").classList.remove("icon-voice-active");
 | 
											
												
													
														|  |            audio.pause();
 |  |            audio.pause();
 | 
											
												
													
														|  |            audio.load();
 |  |            audio.load();
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |        }
 |  |        }
 | 
											
												
													
														|  |        const audioPlayer: any = audio.value;
 |  |        const audioPlayer: any = audio.value;
 | 
											
												
													
														|  | 
 |  | +      const parentNode: any = audioPlayer.parentNode;
 | 
											
												
													
														|  |        if (audioPlayer.paused) {
 |  |        if (audioPlayer.paused) {
 | 
											
												
													
														|  |          audioPlayer.play();
 |  |          audioPlayer.play();
 | 
											
												
													
														|  |          data.show = true;
 |  |          data.show = true;
 | 
											
												
													
														|  | 
 |  | +        parentNode.querySelector(".icon-voice").classList.add("icon-voice-active");
 | 
											
												
													
														|  |        } else {
 |  |        } else {
 | 
											
												
													
														|  |          audioPlayer.pause();
 |  |          audioPlayer.pause();
 | 
											
												
													
														|  |          audioPlayer.load();
 |  |          audioPlayer.load();
 | 
											
												
													
														|  |          data.show = false;
 |  |          data.show = false;
 | 
											
												
													
														|  | 
 |  | +        parentNode.querySelector(".icon-voice").classList.remove("icon-voice-active");
 | 
											
												
													
														|  | 
 |  | +      }
 | 
											
												
													
														|  | 
 |  | +    };
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    const onStopAnimation = (e: any) => {
 | 
											
												
													
														|  | 
 |  | +      const parentNode = e.target.parentNode;
 | 
											
												
													
														|  | 
 |  | +      if (parentNode) {
 | 
											
												
													
														|  | 
 |  | +        parentNode.querySelector(".icon-voice").classList.remove("icon-voice-active");
 | 
											
												
													
														|  |        }
 |  |        }
 | 
											
												
													
														|  |      };
 |  |      };
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      return {
 |  |      return {
 | 
											
												
													
														|  |        ...toRefs(data),
 |  |        ...toRefs(data),
 | 
											
												
													
														|  |        audio,
 |  |        audio,
 | 
											
												
													
														|  | -      play
 |  | 
 | 
											
												
													
														|  | 
 |  | +      play,
 | 
											
												
													
														|  | 
 |  | +      onStopAnimation,
 | 
											
												
													
														|  |      };
 |  |      };
 | 
											
												
													
														|  | -  }
 |  | 
 | 
											
												
													
														|  | 
 |  | +  },
 | 
											
												
													
														|  |  });
 |  |  });
 | 
											
												
													
														|  |  </script>
 |  |  </script>
 | 
											
												
													
														|  |  <style lang="scss" scoped>
 |  |  <style lang="scss" scoped>
 | 
											
												
													
														|  | -@import url('../../../styles/common.scss');
 |  | 
 | 
											
												
													
														|  | -@import url('../../../styles/icon.scss');
 |  | 
 | 
											
												
													
														|  | 
 |  | +@import url("../../../styles/common.scss");
 | 
											
												
													
														|  | 
 |  | +@import url("../../../styles/icon.scss");
 | 
											
												
													
														|  |  .message-audio {
 |  |  .message-audio {
 | 
											
												
													
														|  |    display: flex;
 |  |    display: flex;
 | 
											
												
													
														|  |    align-items: center;
 |  |    align-items: center;
 | 
											
										
											
												
													
														|  | @@ -78,7 +85,7 @@ export default defineComponent({
 | 
											
												
													
														|  |    max-width: 100%;
 |  |    max-width: 100%;
 | 
											
												
													
														|  |    overflow: hidden;
 |  |    overflow: hidden;
 | 
											
												
													
														|  |    .icon {
 |  |    .icon {
 | 
											
												
													
														|  | -    margin: 0 4Px;
 |  | 
 | 
											
												
													
														|  | 
 |  | +    margin: 0 4px;
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |    audio {
 |  |    audio {
 | 
											
												
													
														|  |      width: 0;
 |  |      width: 0;
 |