y595705120 3 rokov pred
rodič
commit
d03e4cc376

+ 5 - 1
src/containers/center/center.vue

@@ -25,7 +25,11 @@ export default {
   	...mapGetters("user", ["userInfo"])
   	...mapGetters("user", ["userInfo"])
   },
   },
   beforeMount(){
   beforeMount(){
-     this.loadBaseInfo()
+     this.loadBaseInfo().then(res=>{
+       if( !res.uid ){
+         this.$router.push('/')
+       }
+     })
   },
   },
   methods: {
   methods: {
     ...mapActions("user", ["loadBaseInfo", "doLogout"]),
     ...mapActions("user", ["loadBaseInfo", "doLogout"]),

+ 39 - 21
src/containers/center/play/components/media.vue

@@ -1,12 +1,12 @@
 <template>
 <template>
   <div>
   <div>
+    <!-- @timeupdate="onPlayerTimeupdate($event)" -->
     <video-player
     <video-player
       class="video-player vjs-custom-skin"
       class="video-player vjs-custom-skin"
       ref="videoPlayer"
       ref="videoPlayer"
       :playsinline="true"
       :playsinline="true"
       @pause="onPlayerPause($event)"
       @pause="onPlayerPause($event)"
       @play="onPlayerStart($event)"
       @play="onPlayerStart($event)"
-      @timeupdate="onPlayerTimeupdate($event)"
       @ready="playerReadied"
       @ready="playerReadied"
       @ended="onPlayerEnded($event)"
       @ended="onPlayerEnded($event)"
       :globalOptions="{controls:true}"
       :globalOptions="{controls:true}"
@@ -109,10 +109,8 @@
       }
       }
     },
     },
     beforeDestroy() {
     beforeDestroy() {
-      if (this.timer) {
-        console.log("beforeDestroy")
-        clearInterval(this.timer); //关闭
-      }
+      this.stopTick()
+      this.reportErr("play", 'destroy');
     },
     },
     computed: {
     computed: {
       player() {
       player() {
@@ -121,21 +119,27 @@
     },
     },
     created() {
     created() {
       this.startTick()
       this.startTick()
+      // this.startMonitor()
     },
     },
     methods: {
     methods: {
       startTick(){
       startTick(){
-        console.log("startTick")
-        let tick = this.tick;
+        let tick = this.tryTick;
         if( this.timer ) clearInterval(this.timer);
         if( this.timer ) clearInterval(this.timer);
         this.timer = setInterval(tick, 5 * 1000);
         this.timer = setInterval(tick, 5 * 1000);
       },
       },
       stopTick(){
       stopTick(){
-        console.log("stopTick")
         if( this.timer ) clearInterval(this.timer);
         if( this.timer ) clearInterval(this.timer);
       },
       },
+      tryTick(){
+        let that = this;
+        try {
+          that.tick()
+        }catch(err){
+          that.reportErr("play", ''+err.message )
+        }
+      },
       playerReadied(player) {
       playerReadied(player) {
         let that = this;
         let that = this;
-        console.log("init", this.media.position);
         if( this.media.position){
         if( this.media.position){
           this.setposition( this.media.position );
           this.setposition( this.media.position );
         }else{
         }else{
@@ -158,19 +162,22 @@
         let player = this.$refs.videoPlayer.player;
         let player = this.$refs.videoPlayer.player;
         player.currentTime( position );
         player.currentTime( position );
         if( this.media.isFinish) return;
         if( this.media.isFinish) return;
-        if( this.media.position >= this.media.duration-30 && !this.media.isFinish){
+        if( this.media.position >= this.media.duration-10 && !this.media.isFinish){
           this.tick( true )
           this.tick( true )
         }
         }
         this.onPlay = true
         this.onPlay = true
       },
       },
       onPlayerPause(event) {
       onPlayerPause(event) {
+        this.reportErr("play", 'pause' );
         this.stopTick()
         this.stopTick()
         this.onPlay = false
         this.onPlay = false
       },
       },
       onPlayerEnded( event ){
       onPlayerEnded( event ){
+        this.reportErr("play", 'end' );
         this.tick( true )
         this.tick( true )
       },
       },
       onClose(){
       onClose(){
+        this.reportErr("play", 'close')
         this.doPause()
         this.doPause()
         this.$emit("close")
         this.$emit("close")
       },
       },
@@ -178,7 +185,6 @@
         this.stopTick()
         this.stopTick()
         let myPlayer = this.$refs.videoPlayer.player;
         let myPlayer = this.$refs.videoPlayer.player;
         myPlayer && myPlayer.pause()
         myPlayer && myPlayer.pause()
-        console.log("doPause")
         this.onPlay = false
         this.onPlay = false
       },
       },
       doPlay(){
       doPlay(){
@@ -191,18 +197,30 @@
         this.tickNum = 0
         this.tickNum = 0
       },
       },
       onPlayerStart() {
       onPlayerStart() {
+        this.reportErr("play", 'start');
         this.startTick();
         this.startTick();
         this.onPlay = true
         this.onPlay = true
       },
       },
       startMonitor() {
       startMonitor() {
         let that = this
         let that = this
-        window.onblur = function() {
-          that.doPause()
-        }
-        window.onfocus = function () {
-          that.doPlay()
-        }
+        document.addEventListener("visibilitychange", function() {
+          // || document.hidden
+          if( document.visibilityState == "hidden"){
+            that.doPause( )
+          }else{
+            that.doPlay()
+          }
+        });
       },
       },
+      // startMonitor() {
+      //   let that = this
+      //   window.onblur = function() {
+      //     that.doPause()
+      //   }
+      //   window.onfocus = function () {
+      //     that.doPlay()
+      //   }
+      // },
       tickWait(){
       tickWait(){
         this.doPause()
         this.doPause()
         let that = this
         let that = this
@@ -222,6 +240,9 @@
           }
           }
         })
         })
       },
       },
+      reportErr( action, msg ){
+        httpServer("course.report", {action, msg})
+      },
       tick( force = false) {
       tick( force = false) {
         let media = this.media;
         let media = this.media;
         this.tickNum ++
         this.tickNum ++
@@ -242,13 +263,12 @@
 
 
         let isFinish = force?1:0
         let isFinish = force?1:0
         if( curTimes >= media.duration ) isFinish = 1;
         if( curTimes >= media.duration ) isFinish = 1;
-        console.log("tick", curTimes, isFinish)
          //  拉到后面
          //  拉到后面
         if( !isFinish ){
         if( !isFinish ){
           if ( !this.onPlay ) return;
           if ( !this.onPlay ) return;
         }
         }
         // 强制完成
         // 强制完成
-        let param ={id: media.id, position:curTimes ,isFinish};
+        let param ={id: media.id, position:curTimes, isFinish};
         httpServer("course.tick", param, true).then( res => {
         httpServer("course.tick", param, true).then( res => {
           if (res.code == 200) {
           if (res.code == 200) {
             let {skip, position, pause, closed} = res.data
             let {skip, position, pause, closed} = res.data
@@ -266,8 +286,6 @@
             Object.assign(param, res.data )
             Object.assign(param, res.data )
             this.$emit("update", param )
             this.$emit("update", param )
           }
           }
-        }).catch( res =>{
-          console.log( "tick", res)
         })
         })
       }
       }
     }
     }

+ 1 - 1
src/store/module/user.js

@@ -43,7 +43,7 @@ export const user = {
           let res = await httpServer("User.baseInfo", {})
           let res = await httpServer("User.baseInfo", {})
           if( res.code != 0 && res.code != 200){
           if( res.code != 0 && res.code != 200){
             commit('LoginOut', {} )
             commit('LoginOut', {} )
-            return true
+            return false
           }
           }
           localStorage.uid = res.data.uid
           localStorage.uid = res.data.uid
           localStorage.token  = res.data.token
           localStorage.token  = res.data.token