audioBackground.vue 1.66 KB
<!--
 * @Date: 2023-06-12 11:23:10
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-09-20 17:40:03
 * @FilePath: /map-demo/src/components/audioBackground.vue
 * @Description: 文件描述
-->
<template>
  <div v-if="audio_src" class="audio-background-page">
    <div @click="handleAudio" :class="['icon', audio_status === 'pause' ? 'play' : 'pause']"></div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'pinia'
import { mainStore } from '@/store'
import $ from 'jquery';

export default {
  data () {
    return {
    }
  },
  mounted () {

  },
  computed: {
    ...mapState(mainStore, ['audio_entity', 'audio_src', 'audio_status'])
  },
  methods: {
    ...mapActions(mainStore, ['changeAudio', 'changeAudioSrc', 'changeAudioStatus']),
    handleAudio () {
      if (this.audio_status === 'play') {
        this.audio_entity.pause();
        this.changeAudioStatus('pause');
      } else {
        this.audio_entity.play();
        this.changeAudioStatus('play');
      }
    }
  }
}
</script>

<style lang="less" scoped>
.audio-background-page {
  position: fixed;
  right: 1.25rem;
  bottom: 7rem;
  .icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background-size: contain;
  }

  .play {
    background-image: url('https://cdn.ipadbiz.cn/xys/map/%E6%92%AD%E6%94%BE%E6%9A%82%E5%81%9C@2x.png');
  }
  .pause {
    background-image: url('https://cdn.ipadbiz.cn/xys/map/%E6%92%AD%E6%94%BE@2x.png');
    animation: rotate 4s linear infinite;
  }

  @keyframes rotate {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }

  .paused {
    animation-play-state: paused;
  }
}
</style>