blob: ba4ea86d7152bc5540ebb811409f1bd5d09c1f66 [file] [log] [blame]
qiaoweif044a742019-07-10 16:04:20 +08001var app = {
2 /*
3 thirdapp:
4 closeBrowser(){
5 if(history.length==1){
6 window.open('mobile/close');
7 }else{
8 history.back();
9 }
10 }
11 <a href="javascript:;" onclick="closeBrowser()">Close</a>
12
13
14 client:
15 var ref = window.open(encodeURI(url), '_blank','location=no');
16 ref.addEventListener('loadstart', function(event) {
17 if (event.url.match("mobile/close")) {
18 ref.close();
19 }
20 });
21 */
22 // Application Constructor
23 initialize: function() {
24 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
25 },
26
27 onDeviceReady: function() {
28 var uid = window.localStorage.getItem("token");
29 if (isEmpty(uid)) {
30 window.location = "login.html";
31 } else {
32 //尝试登陆
33 V1Infor(function(ok, ret) {
34 console.log(ret)
35 if (ok) {
36 if(ret.code==200){
37 var exp = window.localStorage.getItem("tokenexpire");
38 var t = parseInt(exp);
39 //token 小于10分钟了,需要刷新
40 console.log((ret.now-t))
41 if(ret.now-t>1000*60*10){
42 window.location = "login.html";
43 }else{
44
45 window.location = "main.html";
46 }
47 }
48 } else {
49 //alert('无法请求到服务器,请检查网络并稍后再试');
50 if (ret.status == 401) {
51 //need login
52 window.location = "login.html";
53 } else {
54 //TODO ,没有网络
55
56 window.location = "main.html";
57 }
58 }
59 })
60 }
61 }
62};
63app.initialize();