83 lines
2.2 KiB
JavaScript
83 lines
2.2 KiB
JavaScript
var refresh_err_cnt = 0
|
|
|
|
function zeroFill(i){
|
|
if (i >= 0 && i <= 9) {
|
|
return '0' + i;
|
|
} else {
|
|
return i;
|
|
}
|
|
}
|
|
function checkUser(){
|
|
if (localStorage.getItem("online_user") == '') {
|
|
location.href = "login.html";
|
|
}else{
|
|
axios.post('/deescloud/refreshUser', {
|
|
username: localStorage.getItem("online_user"),
|
|
uuid: localStorage.getItem("uuid"),
|
|
})
|
|
.then(function (response) {
|
|
|
|
if (response.status != 200) {
|
|
//location.href="login.html";
|
|
refresh_err_cnt+=1;
|
|
console.log("refresh_err_cnt:",refresh_err_cnt);
|
|
if (refresh_err_cnt>3) {
|
|
localStorage.setItem("refresh_err_cnt",refresh_err_cnt);
|
|
refresh_err_cnt = 0;
|
|
location.href="login.html";
|
|
}
|
|
}else if (response.status == 200 && response.data.r !=0) {
|
|
localStorage.setItem("catch-error",'response r!=0');
|
|
location.href="login.html";
|
|
}else if (response.status == 200 && response.data.r ==0) {
|
|
if (refresh_err_cnt > 0) {
|
|
refresh_err_cnt = 0;
|
|
}
|
|
}
|
|
|
|
})
|
|
.catch(function (error) {
|
|
|
|
refresh_err_cnt+=1;
|
|
console.log("refresh_err_cnt:",refresh_err_cnt);
|
|
if (refresh_err_cnt>3) {
|
|
var date = new Date();//当前时间
|
|
var month = zeroFill(date.getMonth() + 1);//月
|
|
var day = zeroFill(date.getDate());//日
|
|
var hour = zeroFill(date.getHours());//时
|
|
var minute = zeroFill(date.getMinutes());//分
|
|
var second = zeroFill(date.getSeconds());//秒
|
|
|
|
//当前时间
|
|
var curTime = date.getFullYear() + '-' + month + '-' + day
|
|
+ " " + hour + ':' + minute + ':' + second;
|
|
|
|
localStorage.setItem("catch-error",curTime+error);
|
|
refresh_err_cnt = 0;
|
|
location.href="login.html";
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
{
|
|
let url = decodeURI(window.location.href);
|
|
let argsIndex = url .split("?user=");
|
|
console.log("current html argsIndex:",argsIndex);
|
|
let arg = argsIndex[1];
|
|
console.log("current html arg:",arg);
|
|
|
|
let argsIndex1 = url .split("uuid=");
|
|
console.log("current html argsIndex1:",argsIndex1);
|
|
let arg1= argsIndex1[1];
|
|
console.log("current html arg1:",arg1);
|
|
if (arg == undefined ||arg1 == undefined) {
|
|
console.log("user uuid error!")
|
|
}else{
|
|
localStorage.setItem("online_user",arg);
|
|
localStorage.setItem("uuid",arg1);
|
|
}
|
|
|
|
checkUser();
|
|
}
|