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

186 lines
4.2 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: 10,
  48. num: 10,
  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. async onLoad(option) {
  61. const { id, state, shareId } = option
  62. if (shareId) {
  63. uni.setStorageSync('shareId', shareId)
  64. }
  65. if (state) {
  66. uni.setStorageSync('state', state)
  67. }
  68. this.id = id
  69. if(uni.getStorageSync('token')){
  70. this.initData()
  71. }else{
  72. this.$refs.loginPopup.open()
  73. }
  74. },
  75. onShareAppMessage(res) {
  76. const {
  77. headTitle,
  78. indexImage,
  79. } = this.detail
  80. let o = {
  81. title : headTitle,
  82. imageUrl: indexImage,
  83. query: `id=${this.id}&state=1&shareId=${this.userInfo.id}`,
  84. }
  85. // todo: get times and check is unlocked
  86. this.refreshLockStatus()
  87. return o
  88. },
  89. methods: {
  90. async fetchDetails(id) {
  91. try {
  92. this.detail = await this.$fetch('getVideoShareInfo', { id })
  93. } catch (err) {
  94. }
  95. },
  96. async initData() {
  97. await this.fetchDetails(this.id)
  98. this.videoContext = uni.createVideoContext('video');
  99. },
  100. async fetchCheckShare(id) {
  101. try {
  102. return await this.$fetch('checkVideoShare', { id })
  103. } catch (err) {
  104. return {}
  105. }
  106. },
  107. async refreshLockStatus() {
  108. const result = await this.fetchCheckShare()
  109. const { title, open } = result
  110. if (open) {
  111. this.isLocked = false
  112. this.$refs.popupUnlock.close();
  113. this.$refs.popupQrCode.open()
  114. return
  115. }
  116. title && uni.showToast({
  117. title,
  118. icon: 'none'
  119. })
  120. },
  121. async onPlay() {
  122. if (!this.isLocked) {
  123. this.$refs.popupQrCode.open()
  124. return
  125. }
  126. const result = await this.fetchCheckShare()
  127. const { open } = result
  128. if (open) { // 转发已达标
  129. this.isLocked = false
  130. this.$refs.popupQrCode.open()
  131. } else {
  132. this.$refs.popupUnlock.open();
  133. }
  134. },
  135. async onTimeupdate(e) {
  136. const { currentTime } = e.target
  137. // todo: check
  138. if (currentTime >= this.detail.timeNum) {
  139. this.videoContext.pause()
  140. this.timeIsUp = true
  141. this.onPlay()
  142. }
  143. },
  144. },
  145. }
  146. </script>
  147. <style scoped lang="scss">
  148. .video {
  149. width: 100%;
  150. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  151. }
  152. .info {
  153. color: #FFFFFF;
  154. font-size: 28rpx;
  155. position: fixed;
  156. left: 40rpx;
  157. bottom: 100rpx;
  158. .title {
  159. font-size: 32rpx;
  160. margin: 5rpx 0;
  161. }
  162. }
  163. </style>