zhongduxiu.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view class="container">
  3. <view class="changeAudio" :class="[audioState?'changeAudioPlay':'']" @click="changeAudio">
  4. <image :src="audioImgA" v-show="audioState" mode="aspectFit"></image>
  5. <image :src="audioImgB" v-show="!audioState" mode="aspectFit"></image>
  6. </view>
  7. <view class="h5box">
  8. <web-view :webview-styles="webviewStyles" :src="webUrl"></web-view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. audioImgA: "https://dadu.ispush.com/static/zhongduxiu/img/audioOn.png",
  17. audioImgB: "https://dadu.ispush.com/static/zhongduxiu/img/audioOff.png",
  18. audioUrl: "",
  19. webUrl: "https://dadu.ispush.com/api/getHtml",
  20. audioState: false,
  21. innerAudioContext: ""
  22. }
  23. },
  24. methods: {
  25. createAudio() {
  26. this.innerAudioContext = uni.createInnerAudioContext()
  27. this.innerAudioContext.autoplay = true
  28. this.innerAudioContext.loop = true
  29. this.innerAudioContext.src = `${this.$g.baseUrl}/static/zhongduxiu/audio/audio.mp3`
  30. },
  31. changeAudio() {
  32. if (this.audioState) {
  33. this.innerAudioContext.pause()
  34. } else {
  35. this.innerAudioContext.play()
  36. }
  37. this.audioState = !this.audioState
  38. },
  39. },
  40. created() {
  41. this.createAudio()
  42. },
  43. onHide() {
  44. this.audioState = false
  45. this.innerAudioContext.pause()
  46. clearInterval(this.T)
  47. },
  48. onShow(){
  49. if (this.innerAudioContext) {
  50. this.audioState = true
  51. this.innerAudioContext.play()
  52. }
  53. }
  54. }
  55. </script>
  56. <style scoped>
  57. .conatiner {
  58. position: relative;
  59. width: 100vw;
  60. height: 100vh;
  61. }
  62. .container .changeAudio {
  63. position: absolute;
  64. right: 45rpx;
  65. top: 105rpx;
  66. width: 47rpx;
  67. height: 47rpx;
  68. }
  69. .container .changeAudio image {
  70. width: 100%;
  71. height: 100%;
  72. }
  73. .container .changeAudioPlay {
  74. animation: 1s changeAudioAnime linear infinite;
  75. }
  76. @keyframes changeAudioAnime {
  77. from {
  78. transform: rotate(0deg);
  79. }
  80. to {
  81. transform: rotate(360deg);
  82. }
  83. }
  84. .container .h5box{
  85. position: absolute;
  86. top: 0;
  87. left: 0;
  88. width: 100vw;
  89. height: 100vh;
  90. }
  91. </style>