gg.vue 2.6 KB

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