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

188 lines
4.1 KiB

2 months ago
2 months ago
2 months ago
2 months ago
  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. @ended="onTimeEnd"
  15. ></video>
  16. <view class="info">
  17. <view class="author">{{ detail.author || '' }}</view>
  18. <view class="title">{{ detail.headTitle || '' }}</view>
  19. <view class="desc">{{ detail.textDetails || '' }}</view>
  20. </view>
  21. </view>
  22. <uv-overlay :show="timeIsUp" @click="onPlay" zIndex="998">
  23. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-video.png"></popupUnlock>
  24. </uv-overlay>
  25. <popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
  26. </view>
  27. </template>
  28. <script>
  29. import { mapState } from 'vuex'
  30. import popupUnlock from '../components/popupUnlock.vue'
  31. import popupQrCode from '../components/popupQrCode.vue'
  32. export default {
  33. components: {
  34. popupUnlock,
  35. popupQrCode,
  36. },
  37. data() {
  38. return {
  39. id: null,
  40. detail: {
  41. id: null,
  42. headTitle: null,
  43. indexImage: null,
  44. vio: null,
  45. timeNum: 0,
  46. num: 0,
  47. wxCodeImage: null,
  48. textDetails: null,
  49. },
  50. timeIsUp: false,
  51. isLocked: true,
  52. videoContext: null,
  53. }
  54. },
  55. computed: {
  56. ...mapState(['userInfo']),
  57. },
  58. onShow() {
  59. // if (this.id && uni.getStorageSync('token')) {
  60. // this.detail.id ? this.refreshLockStatus() : this.initData()
  61. // }
  62. if (this.detail.id) { // 转发后返回页面的场景
  63. this.refreshLockStatus()
  64. }
  65. },
  66. async onLoad(option) {
  67. const { id, state, shareId } = option
  68. if (shareId) {
  69. uni.setStorageSync('shareId', shareId)
  70. }
  71. if (state) {
  72. uni.setStorageSync('state', state)
  73. }
  74. if (id) {
  75. uni.setStorageSync('id', id)
  76. }
  77. this.id = id
  78. // if(uni.getStorageSync('token')){
  79. // this.initData()
  80. // }else{
  81. // uni.navigateTo({
  82. // url: '/pages_order/auth/wxLogin'
  83. // })
  84. // }
  85. this.initData()
  86. },
  87. onShareAppMessage(res) {
  88. const {
  89. headTitle,
  90. indexImage,
  91. } = this.detail
  92. let o = {
  93. title : headTitle,
  94. imageUrl: indexImage,
  95. query: `id=${this.id}&state=1&shareId=${this.userInfo.id}`,
  96. }
  97. //调用增加分享次数的方法
  98. const params = {
  99. id:this.id,
  100. state:"1",
  101. }
  102. this.$fetch('addLogShareInfo', params)
  103. return o
  104. },
  105. methods: {
  106. async fetchDetails(id) {
  107. try {
  108. this.detail = await this.$fetch('getVideoShareInfo', { id })
  109. } catch (err) {
  110. }
  111. },
  112. async initData() {
  113. this.isLocked = true
  114. await this.fetchDetails(this.id)
  115. this.videoContext = uni.createVideoContext('video');
  116. },
  117. refreshLockStatus() {
  118. this.isLocked = false
  119. this.timeIsUp = false
  120. setTimeout(() => {
  121. this.videoContext.play()
  122. console.log('--play')
  123. })
  124. },
  125. async onPlay() {
  126. if (!this.isLocked) {
  127. return
  128. }
  129. this.videoContext.pause()
  130. this.timeIsUp = true
  131. this.$refs.popupUnlock.open();
  132. },
  133. async onTimeupdate(e) {
  134. const { currentTime } = e.target
  135. if (currentTime >= this.detail.timeNum && this.isLocked) {
  136. this.videoContext.pause()
  137. this.timeIsUp = true
  138. this.onPlay()
  139. }
  140. },
  141. onTimeEnd() {
  142. this.$refs.popupQrCode.open()
  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>