36 lines
876 B
JavaScript
36 lines
876 B
JavaScript
|
|
||
|
import { stationurl } from "../public/js/url.js";
|
||
|
var heartbeat=5;
|
||
|
var tokenTime=30000;
|
||
|
//设置token的保活
|
||
|
function setTokenActive(){
|
||
|
var loginJson=sessionStorage.getItem("unameInfoStr");
|
||
|
var loginInfo=JSON.parse(loginJson);
|
||
|
axios.defaults.headers.common['Authorization'] = loginInfo["session"];
|
||
|
setInterval(()=>{
|
||
|
var url=stationurl + "/firectrl/client/user/active";
|
||
|
heartbeat--;
|
||
|
if(heartbeat==0){
|
||
|
//登出以后,销毁session
|
||
|
layer.confirm("网络连接中断...请重新的登录", {
|
||
|
btn:[ '确定'],
|
||
|
title:false,
|
||
|
closeBtn:false,
|
||
|
shade: 0.5,
|
||
|
}, function(index) {
|
||
|
window.location.href="../login.html";
|
||
|
});
|
||
|
}
|
||
|
axios({
|
||
|
method:'post',
|
||
|
url:url,
|
||
|
}).then(res => {
|
||
|
heartbeat=5;
|
||
|
}).catch(function(error) {
|
||
|
console.log(error)
|
||
|
})
|
||
|
},tokenTime)
|
||
|
|
||
|
}
|
||
|
export {setTokenActive}
|