audio-mixin.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * 音频播放 mixin
  3. * 代理 audioStore,实现跨页面音频持久化播放
  4. * 退出页面后音频继续播放,再次进入页面恢复播放状态
  5. */
  6. import { useAudioStore } from '@/stores/audio'
  7. export default {
  8. computed: {
  9. _audioStore() {
  10. return useAudioStore()
  11. },
  12. audiolist() {
  13. return this._audioStore.audiolist
  14. },
  15. curAudioInx: {
  16. get() { return this._audioStore.curAudioInx },
  17. set(val) { this._audioStore.curAudioInx = val }
  18. },
  19. totalTime() {
  20. return this._audioStore.totalTime
  21. },
  22. currentTime() {
  23. return this._audioStore.currentTime
  24. },
  25. ispause() {
  26. return this._audioStore.ispause
  27. },
  28. isShowDrawer3: {
  29. get() { return this._audioStore.isShowDrawer3 },
  30. set(val) { this._audioStore.isShowDrawer3 = val }
  31. }
  32. },
  33. methods: {
  34. initAudio() {
  35. this._audioStore.initAudio()
  36. },
  37. formatTime(totalSeconds) {
  38. return this._audioStore.formatTime(totalSeconds)
  39. },
  40. changeAudio(url, inx) {
  41. this._audioStore.changeAudio(url, inx)
  42. },
  43. playAudio() {
  44. this._audioStore.playAudio()
  45. },
  46. /** 供 ble-mixin 模式切换时调用 */
  47. _stopAudioOnModeChange() {
  48. this._audioStore.stopAudio()
  49. },
  50. /** 页面离开时解绑事件(音频继续播放) */
  51. detachAudio() {
  52. this._audioStore.detachEvents()
  53. },
  54. /** 彻底销毁(一般不调用,仅供极端场景) */
  55. destroyAudio() {
  56. this._audioStore.destroyAudio()
  57. }
  58. }
  59. }