blob: fe23a8d93e79e6c3ace0cefd885a7cea126c3e33 [file] [log] [blame]
var app = {
/*
thirdapp:
closeBrowser(){
if(history.length==1){
window.open('mobile/close');
}else{
history.back();
}
}
<a href="javascript:;" onclick="closeBrowser()">Close</a>
client:
var ref = window.open(encodeURI(url), '_blank','location=no');
ref.addEventListener('loadstart', function(event) {
if (event.url.match("mobile/close")) {
ref.close();
}
});
*/
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
document.addEventListener('jpush.receiveRegistrationId', function (event) {
console.log(event.registrationId)
}, false)
},
onDeviceReady: function() {
var uid = window.localStorage.getItem("token");
if (isEmpty(uid)) {
window.location = "login.html";
} else {
//尝试登陆
V1Infor(function(ok, ret) {
console.log(ret)
if (ok) {
if(ret.code==200){
var exp = window.localStorage.getItem("tokenexpire");
var t = parseInt(exp);
//token 小于10分钟了,需要刷新
console.log((ret.now-t))
if(ret.now-t>1000*60*10){
window.location = "login.html";
}else{
window.location = "main.html";
}
}else{
window.location = "login.html";
}
} else {
//alert('无法请求到服务器,请检查网络并稍后再试');
if (ret.status == 401) {
//need login
window.location = "login.html";
} else {
//TODO ,没有网络
window.location = "main.html";
}
}
})
}
}
};
app.initialize();