裂变星小程序-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.

205 lines
4.4 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. ></video>
  15. <view class="info">
  16. <view class="author">{{ detail.author || '' }}</view>
  17. <view class="title">{{ detail.headTitle || '' }}</view>
  18. <view class="desc">{{ detail.textDetails || '' }}</view>
  19. </view>
  20. </view>
  21. <uv-overlay :show="timeIsUp" @click="onPlay" zIndex="998">
  22. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-video.png"></popupUnlock>
  23. <popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
  24. </uv-overlay>
  25. </view>
  26. </template>
  27. <script>
  28. import { mapState } from 'vuex'
  29. import popupUnlock from '../components/popupUnlock.vue'
  30. import popupQrCode from '../components/popupQrCode.vue'
  31. export default {
  32. components: {
  33. popupUnlock,
  34. popupQrCode,
  35. },
  36. data() {
  37. return {
  38. id: null,
  39. detail: {
  40. id: null,
  41. headTitle: null,
  42. indexImage: null,
  43. vio: null,
  44. timeNum: 0,
  45. num: 0,
  46. wxCodeImage: null,
  47. textDetails: null,
  48. },
  49. timeIsUp: false,
  50. isLocked: true,
  51. videoContext: null
  52. }
  53. },
  54. computed: {
  55. ...mapState(['userInfo']),
  56. },
  57. onShow() {
  58. if (this.id && uni.getStorageSync('token')) {
  59. this.initData()
  60. }
  61. },
  62. async onLoad(option) {
  63. console.log('--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.$refs.popupQrCode.open()
  122. return
  123. }
  124. title && uni.showToast({
  125. title,
  126. icon: 'none'
  127. })
  128. },
  129. async onPlay() {
  130. if (!this.isLocked) {
  131. this.$refs.popupQrCode.open()
  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.$refs.popupQrCode.open()
  140. } else {
  141. uni.showToast({
  142. title: `还需转发${need_num - num}`,
  143. icon: 'none',
  144. })
  145. this.$refs.popupUnlock.open();
  146. }
  147. },
  148. async onTimeupdate(e) {
  149. const { currentTime } = e.target
  150. // todo: check
  151. if (currentTime >= this.detail.timeNum) {
  152. this.videoContext.pause()
  153. this.timeIsUp = true
  154. this.onPlay()
  155. }
  156. },
  157. },
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. .video {
  162. width: 100%;
  163. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  164. }
  165. .info {
  166. color: #FFFFFF;
  167. font-size: 28rpx;
  168. position: fixed;
  169. left: 40rpx;
  170. bottom: 100rpx;
  171. .title {
  172. font-size: 32rpx;
  173. margin: 5rpx 0;
  174. }
  175. }
  176. </style>