裂变星小程序-25.03.04
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
4.6 KiB

  1. <template>
  2. <view class="page">
  3. <navbar leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <video class="video"
  6. id="video"
  7. :src="detail.vio"
  8. autoplay
  9. play-btn-position="center"
  10. :controls="!timeIsUp"
  11. :show-fullscreen-btn="false"
  12. :show-center-play-btn="true"
  13. @timeupdate="onTimeupdate"
  14. @ended="onTimeEnd"
  15. ></video>
  16. <view class="info">
  17. <view class="author">{{ detail.author || '' }}</view>
  18. <view class="title">{{ detail.headTitle || '' }}</view>
  19. <view class="desc">{{ detail.textDetails || '' }}</view>
  20. </view>
  21. </view>
  22. <uv-overlay :show="timeIsUp" @click="onPlay" zIndex="998">
  23. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-video.png"></popupUnlock>
  24. <popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
  25. </uv-overlay>
  26. </view>
  27. </template>
  28. <script>
  29. import { mapState } from 'vuex'
  30. import popupUnlock from '../components/popupUnlock.vue'
  31. import popupQrCode from '../components/popupQrCode.vue'
  32. export default {
  33. components: {
  34. popupUnlock,
  35. popupQrCode,
  36. },
  37. data() {
  38. return {
  39. id: null,
  40. detail: {
  41. id: null,
  42. headTitle: null,
  43. indexImage: null,
  44. vio: null,
  45. timeNum: 0,
  46. num: 0,
  47. wxCodeImage: null,
  48. textDetails: null,
  49. },
  50. timeIsUp: false,
  51. isLocked: true,
  52. videoContext: null
  53. }
  54. },
  55. computed: {
  56. ...mapState(['userInfo']),
  57. },
  58. onShow() {
  59. if (this.id && uni.getStorageSync('token')) {
  60. this.initData()
  61. }
  62. },
  63. async onLoad(option) {
  64. const { id, state, shareId } = option
  65. if (shareId) {
  66. uni.setStorageSync('shareId', shareId)
  67. }
  68. if (state) {
  69. uni.setStorageSync('state', state)
  70. }
  71. if (id) {
  72. uni.setStorageSync('id', id)
  73. }
  74. this.id = id
  75. if(uni.getStorageSync('token')){
  76. this.initData()
  77. }else{
  78. uni.navigateTo({
  79. url: '/pages_order/auth/wxLogin'
  80. })
  81. }
  82. },
  83. onShareAppMessage(res) {
  84. const {
  85. headTitle,
  86. indexImage,
  87. } = this.detail
  88. let o = {
  89. title : headTitle,
  90. imageUrl: indexImage,
  91. query: `id=${this.id}&state=1&shareId=${this.userInfo.id}`,
  92. }
  93. this.refreshLockStatus()
  94. return o
  95. },
  96. methods: {
  97. async fetchDetails(id) {
  98. try {
  99. this.detail = await this.$fetch('getVideoShareInfo', { id })
  100. } catch (err) {
  101. }
  102. },
  103. async initData() {
  104. await this.fetchDetails(this.id)
  105. this.videoContext = uni.createVideoContext('video');
  106. },
  107. async fetchCheckShare() {
  108. try {
  109. return await this.$fetch('checkVideoShare', { id: this.id })
  110. } catch (err) {
  111. return {}
  112. }
  113. },
  114. async refreshLockStatus() {
  115. const result = await this.fetchCheckShare()
  116. const { title, open } = result
  117. console.log('--open', open)
  118. this.$refs.popupUnlock.close();
  119. if (open) {
  120. this.isLocked = false
  121. this.timeIsUp = false
  122. this.videoContext.play()
  123. return
  124. }
  125. title && uni.showToast({
  126. title,
  127. icon: 'none'
  128. })
  129. },
  130. async onPlay() {
  131. if (!this.isLocked) {
  132. return
  133. }
  134. const result = await this.fetchCheckShare()
  135. const { open, need_num, num } = result
  136. console.log('--open', open)
  137. if (open) { // 转发已达标
  138. this.isLocked = false
  139. this.timeIsUp = false
  140. this.videoContext.play()
  141. } else {
  142. this.videoContext.pause()
  143. this.timeIsUp = true
  144. uni.showToast({
  145. title: `还需转发${need_num - num}`,
  146. icon: 'none',
  147. })
  148. this.$refs.popupUnlock.open();
  149. }
  150. },
  151. async onTimeupdate(e) {
  152. const { currentTime } = e.target
  153. if (currentTime >= this.detail.timeNum && this.isLocked) {
  154. this.videoContext.pause()
  155. this.timeIsUp = true
  156. this.onPlay()
  157. }
  158. },
  159. onTimeEnd() {
  160. this.$refs.popupQrCode.open()
  161. },
  162. },
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .video {
  167. width: 100%;
  168. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  169. }
  170. .info {
  171. color: #FFFFFF;
  172. font-size: 28rpx;
  173. position: fixed;
  174. left: 40rpx;
  175. bottom: 100rpx;
  176. .title {
  177. font-size: 32rpx;
  178. margin: 5rpx 0;
  179. }
  180. }
  181. </style>