裂变星小程序-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. ></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. <loginPopup ref="loginPopup" @login="initData"/>
  25. </uv-overlay>
  26. </view>
  27. </template>
  28. <script>
  29. import { mapState } from 'vuex'
  30. import loginPopup from '@/components/config/loginPopup.vue'
  31. import popupUnlock from '../components/popupUnlock.vue'
  32. import popupQrCode from '../components/popupQrCode.vue'
  33. export default {
  34. components: {
  35. popupUnlock,
  36. popupQrCode,
  37. loginPopup,
  38. },
  39. data() {
  40. return {
  41. id: null,
  42. detail: {
  43. id: null,
  44. headTitle: null,
  45. indexImage: null,
  46. vio: null,
  47. timeNum: 0,
  48. num: 0,
  49. wxCodeImage: null,
  50. textDetails: null,
  51. },
  52. timeIsUp: false,
  53. isLocked: true,
  54. videoContext: null
  55. }
  56. },
  57. computed: {
  58. ...mapState(['userInfo']),
  59. },
  60. onShow() {
  61. if (this.id && uni.getStorageSync('token')) {
  62. this.initData()
  63. }
  64. },
  65. async onLoad(option) {
  66. const { id, state, shareId } = option
  67. if (shareId) {
  68. uni.setStorageSync('shareId', shareId)
  69. }
  70. if (state) {
  71. uni.setStorageSync('state', state)
  72. }
  73. if (id) {
  74. uni.setStorageSync('id', id)
  75. }
  76. this.id = id
  77. if(uni.getStorageSync('token')){
  78. this.initData()
  79. }else{
  80. this.$refs.loginPopup.open()
  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. try {
  116. console.log('--refreshLockStatus')
  117. const result = await this.fetchCheckShare()
  118. const { title, open } = result
  119. console.log('--open', open)
  120. this.$refs.popupUnlock.close();
  121. console.log('--close')
  122. if (open) {
  123. this.isLocked = false
  124. this.$refs.popupQrCode.open()
  125. return
  126. }
  127. title && uni.showToast({
  128. title,
  129. icon: 'none'
  130. })
  131. } catch (err) {
  132. console.log('--err', err)
  133. }
  134. },
  135. async onPlay() {
  136. if (!this.isLocked) {
  137. this.$refs.popupQrCode.open()
  138. return
  139. }
  140. const result = await this.fetchCheckShare()
  141. const { open, need_num, num } = result
  142. if (open) { // 转发已达标
  143. this.isLocked = false
  144. this.$refs.popupQrCode.open()
  145. } else {
  146. uni.showToast({
  147. title: `还需转发${need_num - num}`,
  148. icon: 'none',
  149. })
  150. this.$refs.popupUnlock.open();
  151. }
  152. },
  153. async onTimeupdate(e) {
  154. const { currentTime } = e.target
  155. // todo: check
  156. if (currentTime >= this.detail.timeNum) {
  157. this.videoContext.pause()
  158. this.timeIsUp = true
  159. this.onPlay()
  160. }
  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>