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

199 lines
4.5 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. // todo: get times and check is unlocked
  94. this.refreshLockStatus()
  95. return o
  96. },
  97. methods: {
  98. async fetchDetails(id) {
  99. try {
  100. this.detail = await this.$fetch('getVideoShareInfo', { id })
  101. } catch (err) {
  102. }
  103. },
  104. async initData() {
  105. await this.fetchDetails(this.id)
  106. this.videoContext = uni.createVideoContext('video');
  107. },
  108. async fetchCheckShare() {
  109. try {
  110. return await this.$fetch('checkVideoShare', { id: this.id })
  111. } catch (err) {
  112. return {}
  113. }
  114. },
  115. async refreshLockStatus() {
  116. const result = await this.fetchCheckShare()
  117. const { title, open } = result
  118. if (open) {
  119. this.isLocked = false
  120. this.$refs.popupUnlock.close();
  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. if (open) { // 转发已达标
  137. this.isLocked = false
  138. this.$refs.popupQrCode.open()
  139. } else {
  140. uni.showToast({
  141. title: `还需转发${need_num - num}`,
  142. icon: 'none',
  143. })
  144. this.$refs.popupUnlock.open();
  145. }
  146. },
  147. async onTimeupdate(e) {
  148. const { currentTime } = e.target
  149. // todo: check
  150. if (currentTime >= this.detail.timeNum) {
  151. this.videoContext.pause()
  152. this.timeIsUp = true
  153. this.onPlay()
  154. }
  155. },
  156. },
  157. }
  158. </script>
  159. <style scoped lang="scss">
  160. .video {
  161. width: 100%;
  162. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  163. }
  164. .info {
  165. color: #FFFFFF;
  166. font-size: 28rpx;
  167. position: fixed;
  168. left: 40rpx;
  169. bottom: 100rpx;
  170. .title {
  171. font-size: 32rpx;
  172. margin: 5rpx 0;
  173. }
  174. }
  175. </style>