blob: fe23a8d93e79e6c3ace0cefd885a7cea126c3e33 [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);
qiaoweiaa6f1f62019-08-07 10:26:16 +080025 document.addEventListener('jpush.receiveRegistrationId', function (event) {
26 console.log(event.registrationId)
27 }, false)
qiaoweif044a742019-07-10 16:04:20 +080028 },
29
30 onDeviceReady: function() {
31 var uid = window.localStorage.getItem("token");
32 if (isEmpty(uid)) {
33 window.location = "login.html";
34 } else {
35 //尝试登陆
36 V1Infor(function(ok, ret) {
37 console.log(ret)
38 if (ok) {
39 if(ret.code==200){
40 var exp = window.localStorage.getItem("tokenexpire");
41 var t = parseInt(exp);
42 //token 小于10分钟了,需要刷新
43 console.log((ret.now-t))
44 if(ret.now-t>1000*60*10){
45 window.location = "login.html";
46 }else{
qiaoweif044a742019-07-10 16:04:20 +080047 window.location = "main.html";
48 }
qiaowei60c27e42019-07-11 16:43:54 +080049 }else{
50 window.location = "login.html";
qiaoweif044a742019-07-10 16:04:20 +080051 }
52 } else {
53 //alert('无法请求到服务器,请检查网络并稍后再试');
54 if (ret.status == 401) {
55 //need login
56 window.location = "login.html";
57 } else {
58 //TODO ,没有网络
59
60 window.location = "main.html";
61 }
62 }
63 })
64 }
65 }
66};
67app.initialize();