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

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