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

223 lines
4.8 KiB

1 week 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.initData()
  61. }
  62. },
  63. async onLoad(option) {
  64. const { id, state, shareId } = option
  65. if (shareId) {
  66. uni.setStorageSync('shareId', shareId)
  67. }
  68. if (state) {
  69. uni.setStorageSync('state', state)
  70. }
  71. if (id) {
  72. uni.setStorageSync('id', id)
  73. }
  74. this.id = id
  75. if(uni.getStorageSync('token')){
  76. this.initData()
  77. }else{
  78. uni.navigateTo({
  79. url: '/pages_order/auth/wxLogin'
  80. })
  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. //调用增加分享次数的方法
  94. const params = {
  95. id:this.id,
  96. state:"1",
  97. }
  98. this.$fetch('addLogShareInfo', params)
  99. this.refreshLockStatus()
  100. return o
  101. },
  102. methods: {
  103. async fetchDetails(id) {
  104. try {
  105. this.detail = await this.$fetch('getVideoShareInfo', { id })
  106. } catch (err) {
  107. }
  108. },
  109. async initData() {
  110. this.fetchCheckShare().then(result => {
  111. const { open } = result
  112. this.isLocked = !open
  113. })
  114. await this.fetchDetails(this.id)
  115. this.videoContext = uni.createVideoContext('video');
  116. },
  117. async fetchCheckShare() {
  118. try {
  119. return await this.$fetch('checkVideoShare', { id: this.id })
  120. } catch (err) {
  121. return {}
  122. }
  123. },
  124. async refreshLockStatus() {
  125. const result = await this.fetchCheckShare()
  126. const { title, open } = result
  127. console.log('--open', open)
  128. this.$refs.popupUnlock.close();
  129. if (open) {
  130. this.isLocked = false
  131. this.timeIsUp = false
  132. this.videoContext.play()
  133. return
  134. }
  135. title && uni.showToast({
  136. title,
  137. icon: 'none'
  138. })
  139. },
  140. async onPlay() {
  141. if (!this.isLocked) {
  142. return
  143. }
  144. const result = await this.fetchCheckShare()
  145. const { open, need_num, num } = result
  146. console.log('--open', open)
  147. if (open) { // 转发已达标
  148. this.isLocked = false
  149. this.timeIsUp = false
  150. this.videoContext.play()
  151. } else {
  152. this.videoContext.pause()
  153. this.timeIsUp = true
  154. uni.showToast({
  155. title: `还需转发${need_num - num}`,
  156. icon: 'none',
  157. })
  158. this.$refs.popupUnlock.open();
  159. }
  160. },
  161. async onTimeupdate(e) {
  162. const { currentTime } = e.target
  163. if (currentTime >= this.detail.timeNum && this.isLocked) {
  164. this.videoContext.pause()
  165. this.timeIsUp = true
  166. this.onPlay()
  167. }
  168. },
  169. onTimeEnd() {
  170. this.$refs.popupQrCode.open()
  171. },
  172. },
  173. }
  174. </script>
  175. <style scoped lang="scss">
  176. .video {
  177. width: 100%;
  178. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  179. }
  180. .info {
  181. color: #FFFFFF;
  182. font-size: 28rpx;
  183. position: fixed;
  184. left: 40rpx;
  185. bottom: 100rpx;
  186. .title {
  187. font-size: 32rpx;
  188. margin: 5rpx 0;
  189. }
  190. }
  191. </style>