blob: 82aa5bb81ed220ec5ede2f3f15e58d110b8a5005 [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);
},
onDeviceReady: function() {
var firstload = window.localStorage.getItem("firstload");
/*if(isEmpty(firstload)||firstload!='yes'){
app.toPage("startload.html")
return;
}*/
var uid = window.localStorage.getItem("token");
if (isEmpty(uid)) {
//window.location = "login.html";
this.toPage("login.html")
} else {
//尝试登陆
V1Infor(function(ok, ret) {
console.log(ret)
if (ok) {
if(ret.code==200){
if(!isEmpty(ret.token)){
window.localStorage.setItem("token",ret.token);
}
//window.location = "main.html";
app.toPage("main.html")
}else{
//window.location = "login.html";
app.toPage("login.html")
}
} else {
//alert('无法请求到服务器,请检查网络并稍后再试');
if (ret.status == 401) {
//need login
//window.location = "login.html";
app.toPage("login.html")
} else {
//TODO ,没有网络
app.toPage("main.html")
//window.location = "main.html";
}
}
})
}
},
toPage:function(page){
setTimeout(function() {
//window.location=page;
window.location=page;
},1000)
}
};
app.initialize();