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

212 lines
4.6 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. ></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. </uv-overlay>
  25. </view>
  26. </template>
  27. <script>
  28. import { mapState } from 'vuex'
  29. import popupUnlock from '../components/popupUnlock.vue'
  30. import popupQrCode from '../components/popupQrCode.vue'
  31. export default {
  32. components: {
  33. popupUnlock,
  34. popupQrCode,
  35. },
  36. data() {
  37. return {
  38. id: null,
  39. detail: {
  40. id: null,
  41. headTitle: null,
  42. indexImage: null,
  43. vio: null,
  44. timeNum: 0,
  45. num: 0,
  46. wxCodeImage: null,
  47. textDetails: null,
  48. },
  49. timeIsUp: false,
  50. isLocked: true,
  51. videoContext: null
  52. }
  53. },
  54. computed: {
  55. ...mapState(['userInfo']),
  56. },
  57. onShow() {
  58. if (this.id && uni.getStorageSync('token')) {
  59. this.initData()
  60. }
  61. },
  62. async onLoad(option) {
  63. console.log('--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. await this.fetchDetails(this.id)
  111. this.videoContext = uni.createVideoContext('video');
  112. },
  113. async fetchCheckShare() {
  114. try {
  115. return await this.$fetch('checkVideoShare', { id: this.id })
  116. } catch (err) {
  117. return {}
  118. }
  119. },
  120. async refreshLockStatus() {
  121. const result = await this.fetchCheckShare()
  122. const { title, open } = result
  123. console.log('--open', open)
  124. this.$refs.popupUnlock.close();
  125. if (open) {
  126. this.isLocked = false
  127. this.$refs.popupQrCode.open()
  128. return
  129. }
  130. title && uni.showToast({
  131. title,
  132. icon: 'none'
  133. })
  134. },
  135. async onPlay() {
  136. if (!this.isLocked) {
  137. this.$refs.popupQrCode.open()
  138. return
  139. }
  140. const result = await this.fetchCheckShare()
  141. const { open, need_num, num } = result
  142. console.log('--open', open)
  143. if (open) { // 转发已达标
  144. this.isLocked = false
  145. this.$refs.popupQrCode.open()
  146. } else {
  147. uni.showToast({
  148. title: `还需转发${need_num - num}`,
  149. icon: 'none',
  150. })
  151. this.$refs.popupUnlock.open();
  152. }
  153. },
  154. async onTimeupdate(e) {
  155. const { currentTime } = e.target
  156. // todo: check
  157. if (currentTime >= this.detail.timeNum) {
  158. this.videoContext.pause()
  159. this.timeIsUp = true
  160. this.onPlay()
  161. }
  162. },
  163. },
  164. }
  165. </script>
  166. <style scoped lang="scss">
  167. .video {
  168. width: 100%;
  169. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  170. }
  171. .info {
  172. color: #FFFFFF;
  173. font-size: 28rpx;
  174. position: fixed;
  175. left: 40rpx;
  176. bottom: 100rpx;
  177. .title {
  178. font-size: 32rpx;
  179. margin: 5rpx 0;
  180. }
  181. }
  182. </style>