StartUp.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="start-up">
  3. <button
  4. v-show="canStart"
  5. class="start"
  6. @click="onClickStart"
  7. >
  8. 开始
  9. </button>
  10. <div
  11. v-show="isShowVideo"
  12. class="video-wrap"
  13. >
  14. <video
  15. ref="videoEl"
  16. src="@/assets/videos/start-up-video.mp4"
  17. playsinline
  18. webkit-playsinline="true"
  19. x5-video-player-type="h5"
  20. @canplaythrough="store.commit('declareCanStart')"
  21. @ended="onVideoEnd"
  22. />
  23. <button
  24. class="skip"
  25. @click="onClickSkip"
  26. >
  27. 跳过
  28. </button>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup>
  33. import { ref, computed, watch, onMounted } from "vue"
  34. import { useRoute, useRouter } from "vue-router"
  35. import { useStore } from "vuex"
  36. const route = useRoute()
  37. const router = useRouter()
  38. const store = useStore()
  39. const canStart = computed(() => {
  40. return store.state.canStart
  41. })
  42. function onClickStart() {
  43. isShowVideo.value = true
  44. videoEl.value.play()
  45. }
  46. const isShowVideo = ref(false)
  47. const videoEl = ref(null)
  48. function onClickSkip() {
  49. videoEl.value.pause()
  50. store.commit('setHaveShownStartUp', true)
  51. }
  52. function onVideoEnd() {
  53. store.commit('setHaveShownStartUp', true)
  54. }
  55. const haveShownStartUp = computed(() => {
  56. return store.state.haveShownStartUp
  57. })
  58. watch(haveShownStartUp, (v) => {
  59. if (!v) {
  60. videoEl.value.currentTime = 0
  61. videoEl.value.play()
  62. }
  63. })
  64. </script>
  65. <style lang="less" scoped>
  66. .start-up{
  67. position: absolute;
  68. left: 0;
  69. top: 0;
  70. width: 100%;
  71. height: 100%;
  72. background-image: url(@/assets/images/start-up-bg.jpg);
  73. background-size: cover;
  74. background-repeat: no-repeat;
  75. background-position: center center;
  76. background-color: black;
  77. >button.start{
  78. position: absolute;
  79. left: 50%;
  80. top: 50%;
  81. transform: translate(-50%, -50%);
  82. }
  83. >.video-wrap{
  84. position: absolute;
  85. left: 0;
  86. top: 0;
  87. width: 100%;
  88. height: 100%;
  89. >video{
  90. position: absolute;
  91. left: 0;
  92. top: 0;
  93. width: 100%;
  94. height: 100%;
  95. background-color: black;
  96. }
  97. >button.skip{
  98. position: absolute;
  99. right: 100px;
  100. bottom: 100px;
  101. color: blue;
  102. }
  103. }
  104. }
  105. </style>