AudioPlay.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div class="audio-wrapper">
  3. <span class="audio-play" @click="playAudio">
  4. <SvgIcon size="20" icon-class="audio" />
  5. </span>
  6. <audio ref="audio" :src="url" preload="metadata"></audio>
  7. </div>
  8. </template>
  9. <script>
  10. import { GetFileURLMap } from '@/api/app';
  11. export default {
  12. name: 'AudioPlay',
  13. props: {
  14. fileId: {
  15. type: String,
  16. required: true
  17. }
  18. },
  19. data() {
  20. return {
  21. url: ''
  22. };
  23. },
  24. watch: {
  25. fileId: {
  26. handler(val) {
  27. if (!val) return;
  28. GetFileURLMap({ file_id_list: [val] }).then(({ url_map }) => {
  29. this.url = url_map[val];
  30. });
  31. },
  32. immediate: true
  33. }
  34. },
  35. methods: {
  36. playAudio() {
  37. this.$refs.audio.play();
  38. }
  39. }
  40. };
  41. </script>
  42. <style lang="scss" scoped>
  43. .audio-wrapper {
  44. .audio-play {
  45. display: flex;
  46. align-items: center;
  47. justify-content: center;
  48. width: 40px;
  49. height: 40px;
  50. cursor: pointer;
  51. background-color: $main-color;
  52. border-radius: 50%;
  53. }
  54. }
  55. </style>