UNPKG

enc-framework

Version:

enc-framework 核心组件.

52 lines (50 loc) 1.37 kB
import SessionContextHodler from '../utils/ajm-session' class Monitor { constructor(loginApi,options){ this.$loginApi = loginApi; this.options = options || {} this.refshTime= this.options.refshTime || 30*60 ; this.startTime = 0; this.maxTime = 60*30 ; } // 启动 start(){ this.interval = setInterval(() =>{ if(!SessionContextHodler.getContext().getTokenInfo()){ this.stop() }else{ this.listenToken(); //this.listenkey_house() this.startTime++; } }, 1000) } //监听token listenToken(){ let tokenInfo = SessionContextHodler.getContext().getTokenInfo()||{}; let expiresTime = tokenInfo.expires_in; let params = {refresh_token:tokenInfo.refresh_token} if( expiresTime - this.startTime < this.refshTime && !this.executing){ this.executing = true; this.$loginApi.refreshToken(params).then(() => { this.startTime=0 this.executing = false; }); } } //重置倒计时 // resetTime=()=>{ // this.maxTime = 60*30; // } resetTime(){ this.maxTime = 60*30; } //监听屏幕操作 listenkey_house(){ } // 停止 stop(){ clearInterval(this.interval) } } export default Monitor;