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

216 lines
4.2 KiB

  1. <template>
  2. <view class="page">
  3. <navbar leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <video class="video" id="video" :src="detail.vio" autoplay play-btn-position="center" :controls="!timeIsUp"
  6. :show-fullscreen-btn="false" :show-center-play-btn="true" @timeupdate="onTimeupdate"
  7. @ended="onTimeEnd"></video>
  8. <view class="info">
  9. <view class="author">{{ detail.author || '' }}</view>
  10. <view class="title">{{ detail.headTitle || '' }}</view>
  11. <view class="desc">{{ detail.textDetails || '' }}</view>
  12. </view>
  13. </view>
  14. <uv-overlay :show="timeIsUp" @click="onPlay" zIndex="998">
  15. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-video.png"></popupUnlock>
  16. </uv-overlay>
  17. <popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. mapState
  23. } from 'vuex'
  24. import popupUnlock from '../components/popupUnlock.vue'
  25. import popupQrCode from '../components/popupQrCode.vue'
  26. export default {
  27. components: {
  28. popupUnlock,
  29. popupQrCode,
  30. },
  31. data() {
  32. return {
  33. id: null,
  34. detail: {
  35. id: null,
  36. headTitle: null,
  37. indexImage: null,
  38. vio: null,
  39. timeNum: 0,
  40. num: 0,
  41. wxCodeImage: null,
  42. textDetails: null,
  43. },
  44. timeIsUp: false,
  45. isLocked: true,
  46. videoContext: null,
  47. }
  48. },
  49. computed: {
  50. ...mapState(['userInfo']),
  51. },
  52. onShow() {
  53. // if (this.id && uni.getStorageSync('token')) {
  54. // this.detail.id ? this.refreshLockStatus() : this.initData()
  55. // }
  56. if (this.detail.id) { // 转发后返回页面的场景
  57. this.refreshLockStatus()
  58. }
  59. },
  60. async onLoad(option) {
  61. const {
  62. id,
  63. state,
  64. shareId
  65. } = option
  66. if (shareId) {
  67. uni.setStorageSync('shareId', shareId)
  68. }
  69. if (state) {
  70. uni.setStorageSync('state', state)
  71. }
  72. if (id) {
  73. uni.setStorageSync('id', id)
  74. }
  75. this.id = id
  76. // if(uni.getStorageSync('token')){
  77. // this.initData()
  78. // }else{
  79. // uni.navigateTo({
  80. // url: '/pages_order/auth/wxLogin'
  81. // })
  82. // }
  83. this.initData()
  84. },
  85. onShareAppMessage(res) {
  86. const {
  87. headTitle,
  88. indexImage,
  89. } = this.detail
  90. let o = {
  91. title: headTitle,
  92. imageUrl: indexImage,
  93. query: `id=${this.id}&state=1&shareId=${this.userInfo.id}`,
  94. }
  95. //调用增加分享次数的方法
  96. const params = {
  97. id: this.id,
  98. state: "1",
  99. }
  100. // this.$fetch('addLogShareInfo', params)
  101. shareLog.insert(this.id)
  102. return o
  103. },
  104. methods: {
  105. async fetchDetails(id) {
  106. try {
  107. this.detail = await this.$fetch('getVideoShareInfo', {
  108. id
  109. })
  110. } catch (err) {
  111. }
  112. },
  113. async initData() {
  114. this.isLocked = true
  115. await this.fetchDetails(this.id)
  116. this.videoContext = uni.createVideoContext('video');
  117. },
  118. async refreshLockStatus() {
  119. this.isLocked = false
  120. this.timeIsUp = false
  121. setTimeout(async () => {
  122. const result = await this.fetchCheckShare()
  123. const {
  124. open,
  125. need_num,
  126. num
  127. } = result
  128. console.log('--open', open)
  129. if (open) { // 转发已达标
  130. this.videoContext.play()
  131. this.isLocked = false
  132. return
  133. }
  134. uni.showToast({
  135. title: `还需转发${need_num - num}`,
  136. icon: 'none',
  137. })
  138. })
  139. },
  140. async fetchCheckShare() {
  141. try {
  142. return await shareLog.check(this.id, this.detail.num)
  143. } catch (err) {
  144. return {}
  145. }
  146. },
  147. async onPlay() {
  148. if (!this.isLocked) {
  149. return
  150. }
  151. this.videoContext.pause()
  152. this.timeIsUp = true
  153. this.$refs.popupUnlock.open();
  154. },
  155. async onTimeupdate(e) {
  156. const {
  157. currentTime
  158. } = e.target
  159. if (currentTime >= this.detail.timeNum && this.isLocked) {
  160. this.videoContext.pause()
  161. this.timeIsUp = true
  162. this.onPlay()
  163. }
  164. },
  165. onTimeEnd() {
  166. this.$refs.popupQrCode.open()
  167. },
  168. },
  169. }
  170. </script>
  171. <style scoped lang="scss">
  172. .video {
  173. width: 100%;
  174. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  175. }
  176. .info {
  177. color: #FFFFFF;
  178. font-size: 28rpx;
  179. position: fixed;
  180. left: 40rpx;
  181. bottom: 100rpx;
  182. .title {
  183. font-size: 32rpx;
  184. margin: 5rpx 0;
  185. }
  186. }
  187. </style>