BannerView.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <iframe
  3. ref="bannerIframe"
  4. frameborder="0"
  5. class="banner-iframe"
  6. src="https://sit-wuxicishan.4dage.com/unityPcBanner"
  7. />
  8. <div
  9. v-show="showVideo && videoUrl"
  10. class="banner-video"
  11. >
  12. <video
  13. ref="startupVideoRef"
  14. :src="`/videos/${videoUrl}`"
  15. autoplay
  16. :muted="$isSafari"
  17. controls="false"
  18. x5-playsinline="true"
  19. playsinline="true"
  20. webkit-playsinline="true"
  21. x-webkit-airplay="true"
  22. x5-video-player-type="h5-page"
  23. @ended="onEnded"
  24. />
  25. <button
  26. v-if="isShowPlayBtn"
  27. class="banner-video__play"
  28. @click="onClickPlayVideo"
  29. >
  30. 播放
  31. </button>
  32. <div
  33. class="banner-video__skip"
  34. @click="onEnded"
  35. >
  36. 跳过
  37. </div>
  38. </div>
  39. </template>
  40. <script setup>
  41. import { ref, onMounted, inject, nextTick } from "vue"
  42. import { useRouter } from "vue-router"
  43. const router = useRouter()
  44. const $isSafari = inject('$isSafari')
  45. let checkedIdx = 0
  46. const videoUrl = ref('')
  47. const showVideo = ref(false)
  48. const startupVideoRef = ref(null)
  49. const bannerIframe = ref(null)
  50. const VIDEO_MAP = [
  51. 'ysdt.mp4',
  52. 'xszc.mp4',
  53. 'csbwg.mp4'
  54. ]
  55. const isShowPlayBtn = ref($isSafari.value)
  56. function onClickPlayVideo() {
  57. startupVideoRef.value.play()
  58. isShowPlayBtn.value = false
  59. }
  60. const onEnded = () => {
  61. switch (checkedIdx) {
  62. case 0:
  63. router.push({
  64. name: 'HomeView'
  65. })
  66. break
  67. case 1:
  68. router.push({
  69. name: 'CityOfXishan'
  70. })
  71. break
  72. case 2:
  73. router.push({
  74. name: 'MuseumView'
  75. })
  76. break
  77. }
  78. showVideo.value = false
  79. }
  80. onMounted(() => {
  81. if (!bannerIframe.value) return
  82. bannerIframe.value.contentWindow.OnClickScene = function(v) {
  83. videoUrl.value = VIDEO_MAP[v]
  84. showVideo.value = true
  85. checkedIdx = v
  86. }
  87. })
  88. </script>
  89. <style lang="less" scoped>
  90. .banner-iframe {
  91. position: fixed;
  92. top: 0;
  93. left: 0;
  94. width: 100%;
  95. height: 100%;
  96. z-index: 998;
  97. }
  98. .banner-video {
  99. position: fixed;
  100. top: 0;
  101. left: 0;
  102. width: 100%;
  103. height: 100%;
  104. z-index: 999;
  105. video {
  106. width: inherit;
  107. height: inherit;
  108. object-fit: cover;
  109. pointer-events: none;
  110. &::-webkit-media-controls-enclosure {
  111. display: none !important;
  112. }
  113. }
  114. &__play{
  115. position: absolute;
  116. left: 50%;
  117. top: 50%;
  118. transform: translate(-50%, -50%);
  119. font-size: 20px;
  120. color: white;
  121. width: 117px;
  122. height: 51px;
  123. letter-spacing: 4px;
  124. line-height: 42px;
  125. background: url('@/assets/images/btn0@2x-min.png') no-repeat center / contain;
  126. }
  127. &__skip {
  128. position: absolute;
  129. right: 30px;
  130. bottom: 30px;
  131. display: flex;
  132. justify-content: center;
  133. font-size: 20px;
  134. color: white;
  135. width: 117px;
  136. height: 51px;
  137. letter-spacing: 4px;
  138. line-height: 42px;
  139. cursor: pointer;
  140. background: url('@/assets/images/btn0@2x-min.png') no-repeat center / contain;
  141. }
  142. }
  143. </style>