gg.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="content">
  3. <view class="djs">
  4. 观看完视频后,可获得奖励
  5. </view>
  6. <video src="../../static/video/v1.mp4" class="gsjs" autoplay :muted="muted" :controls="false"
  7. :enable-progress-gesture="false" @play="vPlay" ref="vgg" @ended="vEnd" id="myVideo"></video>
  8. </view>
  9. </template>
  10. <script>
  11. import {
  12. ggGive
  13. } from '@/api/zero.js'
  14. export default {
  15. data() {
  16. return {
  17. // #ifdef APP-PLUS
  18. muted: false,
  19. // #endif
  20. // #ifdef H5
  21. muted: true,
  22. // #endif
  23. djs: 15,
  24. isEnd: false,
  25. id: 0,
  26. video: ''
  27. }
  28. },
  29. onLoad(opt) {
  30. this.id = opt.id
  31. },
  32. onShow() {
  33. },
  34. onReachBottom() {
  35. },
  36. onReady() {
  37. this.video = uni.createVideoContext('myVideo', this)
  38. },
  39. onHide() {
  40. try {
  41. this.video.pause()
  42. } catch (e) {
  43. //TODO handle the exception
  44. console.log('err', e)
  45. }
  46. },
  47. onBackPress(event) {
  48. console.log(event, 'black')
  49. let that = this
  50. if (!that.isEnd) {
  51. that.video.pause()
  52. uni.showModal({
  53. title: '温馨提醒',
  54. content: '观看完视频后,可获得奖励',
  55. cancelText: '跳过视频',
  56. confirmText: '继续观看',
  57. complete(e) {
  58. console.log(e)
  59. if (e.confirm) {
  60. // return
  61. that.video.play()
  62. } else {
  63. uni.redirectTo({
  64. url: '/pages/zero/ren'
  65. })
  66. }
  67. }
  68. })
  69. return true
  70. }
  71. },
  72. methods: {
  73. vPlay(e) {
  74. console.log(e, '开始播放')
  75. },
  76. vEnd() {
  77. this.isEnd = true
  78. console.log(this.id)
  79. //发放奖励
  80. ggGive({
  81. id: this.id
  82. }).then(res => {
  83. uni.showToast({
  84. title: '奖励发放成功',
  85. duration: 2000
  86. });
  87. setTimeout(() => {
  88. uni.navigateBack({
  89. fail() {
  90. uni.redirectTo({
  91. url: '/pages/zero/ren'
  92. })
  93. }
  94. })
  95. }, 1500)
  96. })
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. page {
  103. background-color: #000;
  104. height: 100%;
  105. }
  106. .content {
  107. position: absolute;
  108. top: 0;
  109. left: 0;
  110. background-color: #000;
  111. width: 100%;
  112. height: 100%;
  113. }
  114. .gsjs {
  115. width: 750rpx;
  116. position: absolute;
  117. top: 0;
  118. bottom: 0;
  119. margin: auto;
  120. }
  121. .djs {
  122. position: absolute;
  123. top: 20rpx;
  124. left: 20rpx;
  125. color: #fff;
  126. font-size: 28rpx;
  127. padding: 5rpx 10rpx;
  128. border: 1px solid #fff;
  129. border-radius: 20rpx;
  130. }
  131. </style>