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

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 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.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. this.refreshLockStatus()
  94. return o
  95. },
  96. methods: {
  97. async fetchDetails(id) {
  98. try {
  99. this.detail = await this.$fetch('getVideoShareInfo', { id })
  100. } catch (err) {
  101. }
  102. },
  103. async initData() {
  104. this.fetchCheckShare().then(result => {
  105. const { open } = result
  106. this.isLocked = !open
  107. })
  108. await this.fetchDetails(this.id)
  109. this.videoContext = uni.createVideoContext('video');
  110. },
  111. async fetchCheckShare() {
  112. try {
  113. return await this.$fetch('checkVideoShare', { id: this.id })
  114. } catch (err) {
  115. return {}
  116. }
  117. },
  118. async refreshLockStatus() {
  119. const result = await this.fetchCheckShare()
  120. const { title, open } = result
  121. console.log('--open', open)
  122. this.$refs.popupUnlock.close();
  123. if (open) {
  124. this.isLocked = false
  125. this.timeIsUp = false
  126. this.videoContext.play()
  127. return
  128. }
  129. title && uni.showToast({
  130. title,
  131. icon: 'none'
  132. })
  133. },
  134. async onPlay() {
  135. if (!this.isLocked) {
  136. return
  137. }
  138. const result = await this.fetchCheckShare()
  139. const { open, need_num, num } = result
  140. console.log('--open', open)
  141. if (open) { // 转发已达标
  142. this.isLocked = false
  143. this.timeIsUp = false
  144. this.videoContext.play()
  145. } else {
  146. this.videoContext.pause()
  147. this.timeIsUp = true
  148. uni.showToast({
  149. title: `还需转发${need_num - num}`,
  150. icon: 'none',
  151. })
  152. this.$refs.popupUnlock.open();
  153. }
  154. },
  155. async onTimeupdate(e) {
  156. const { currentTime } = e.target
  157. if (currentTime >= this.detail.timeNum && this.isLocked) {
  158. this.videoContext.pause()
  159. this.timeIsUp = true
  160. this.onPlay()
  161. }
  162. },
  163. onTimeEnd() {
  164. this.$refs.popupQrCode.open()
  165. },
  166. },
  167. }
  168. </script>
  169. <style scoped lang="scss">
  170. .video {
  171. width: 100%;
  172. height: calc(100vh - #{$navbar-height} - var(--status-bar-height) - 20rpx);
  173. }
  174. .info {
  175. color: #FFFFFF;
  176. font-size: 28rpx;
  177. position: fixed;
  178. left: 40rpx;
  179. bottom: 100rpx;
  180. .title {
  181. font-size: 32rpx;
  182. margin: 5rpx 0;
  183. }
  184. }
  185. </style>