Browse Source

feat: 优化小程序播放问题

xiansin 2 years ago
parent
commit
bd3e262bb1

+ 1 - 1
mini/components/Recharge/index.vue

xqd
@@ -22,7 +22,7 @@
                   <view v-if="list.origin_price" class="origin-price cross-center">原价{{ list.origin_price }}金币</view>
                 </view>
               </view>
-              <view class="buy-num">{{ buyNum }}人购买</view>
+              <view class="buy-num">{{ $util.tranNumber(buyNum) }}人购买</view>
             </view>
           </view>
           <view class="static-text main-between cross-center">

+ 16 - 2
mini/pages/episode/play.vue

xqd xqd xqd xqd xqd xqd xqd
@@ -49,6 +49,7 @@
               object-fit="contain"
               @timeupdate="timeupdate"
               @ended="ended"
+              @play="play($event,item)"
             />
           </swiper-item>
         </swiper>
@@ -197,6 +198,12 @@ export default {
       this.progress = 100
       // #endif
     },
+    play(e, item) {
+      console.log('-->data', e, item)
+      // #ifdef  MP-KUAISHOU
+      this.handlePlay(item)
+      // #endif
+    },
     // 播放
     handlePlay(item) {
       this.currentEpisode = item
@@ -204,6 +211,10 @@ export default {
       if (!this.checkBeforePlay(item)) {
         // 余额是否购买
         if (!this.checkOverage(item)) {
+          // #ifdef  MP-KUAISHOU
+          // 如果没有购买,那把视频链接设置为空 停止播放,使用 pause 和 stop 在真机上不生效 只能采用这种方式
+          item.url = ''
+          // #endif
           this.rechargeShow = true
           return
         }
@@ -214,6 +225,8 @@ export default {
       this.isPlaying = true
       item.isPlaying = true
       // #ifdef MP-KUAISHOU
+      item.url = item.src
+      this.$forceUpdate()
       setTimeout(() => {
         this.videoContext.play()
       }, 1000)
@@ -225,7 +238,7 @@ export default {
       this.watched(this.id, this.currentEpisode.id)
     },
     // 暂停
-    handlePause(item, isAll) {
+    handlePause(item, isAll = false) {
       if (!this.isPlaying) return
       item.isPlaying = false
       this.isPlaying = false
@@ -260,7 +273,7 @@ export default {
     async handleBuy() {
       await this.$api.user.episode.buyHandle(this.id, this.currentEpisode.id).then(async res => {
         this.$hideLoading()
-        if (typeof res.overage !== 'undefined') {
+        if (typeof res.data.overage !== 'undefined') {
           this.rechargeShow = true
         } else {
           this.$u.toast('购买成功')
@@ -362,6 +375,7 @@ export default {
           obj.isPlaying = false
           obj.index = index
           obj.progress = 0
+          obj.src = obj.url
         })
         this.lists = this.episode.lists
         // 初始化 Swiper 剧集

+ 10 - 1
mini/store/modules/user.js

xqd xqd xqd
@@ -1,4 +1,4 @@
-import { getToken, setToken } from '@/utils/auth'
+import { getToken, setToken, removeToken } from '@/utils/auth'
 import Cache from '@/utils/cache'
 const getDefaultState = () => {
   return {
@@ -17,6 +17,12 @@ const mutations = {
   SET_INFO: (state, info) => {
     Cache.set('userInfo', info)
     state.info = info
+  },
+  CLEAR_INFO: (state) => {
+    removeToken()
+    Cache.remove('userInfo')
+    state.token = null
+    state.info = null
   }
 }
 
@@ -26,6 +32,9 @@ const actions = {
   },
   info({ commit }, info) {
     commit('SET_INFO', info)
+  },
+  clear({ commit }) {
+    commit('CLEAR_INFO')
   }
 }
 

+ 1 - 2
mini/utils/request/responseInterceptors.js

xqd
@@ -28,8 +28,7 @@ module.exports = vm => {
       if (typeof error.data.status_code !== 'undefined') {
         if (error.data.status_code === 401 || error.data.status_code === 402) {
           if (!Cache.get('isLogin')) {
-            removeToken(null)
-            Cache.set('isLogin', 1)
+            removeToken()
             uni.reLaunch({
               url: '/pages/login'
             })