| qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame^] | 1 | var app = { |
| 2 | |
| 3 | // Application Constructor |
| 4 | initialize: function() { |
| 5 | document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); |
| 6 | }, |
| 7 | |
| 8 | onDeviceReady: function() { |
| 9 | this.receivedEvent('deviceready'); |
| 10 | }, |
| 11 | |
| 12 | // Update DOM on a Received Event |
| 13 | receivedEvent: function(id) { |
| 14 | var phone = window.localStorage.getItem("phone"); |
| 15 | if(!isEmpty(phone)){ |
| 16 | $("#phone").val(phone) |
| 17 | } |
| 18 | }, |
| 19 | toRegister :function(){ |
| 20 | window.location = "register.html"; |
| 21 | }, |
| 22 | toForget :function(){ |
| 23 | window.location = "findpwd.html"; |
| 24 | }, |
| 25 | login: function(){ |
| 26 | //loading("正在处理"); |
| 27 | var phone = $("#phone").val() |
| 28 | var pwd = $("#pwd").val() |
| 29 | if(isEmpty(phone)||isEmpty(pwd)){ |
| 30 | return; |
| 31 | } |
| 32 | //loadingElement('loginBtn', '登录中...') |
| 33 | $.showLoading("登录中"); |
| 34 | var param={ |
| 35 | "username":phone, |
| 36 | "password":pwd |
| 37 | } |
| 38 | Login(param,function(ok,ret){ |
| 39 | console.log(ret) |
| 40 | if(ok){ |
| 41 | if(ret.code!=200){ |
| 42 | $.alert(ret.msg, "错误"); |
| 43 | //closeLoading('loginBtn') |
| 44 | //showOk(ret.msg) |
| 45 | $.hideLoading(); |
| 46 | }else{ |
| 47 | window.localStorage.setItem("phone",phone); |
| 48 | window.localStorage.setItem("phoneX",ret.phone); |
| 49 | window.localStorage.setItem("token",ret.token); |
| 50 | window.localStorage.setItem("tenantid",ret.tenantid); |
| 51 | window.localStorage.setItem("tokenexpire",ret.expire); |
| 52 | window.localStorage.setItem("tokentime",ret.now); |
| 53 | window.localStorage.setItem("userid",ret.userid); |
| 54 | window.localStorage.setItem("signed",ret.signed); |
| 55 | window.localStorage.setItem("paypwdset",ret.paypwdset); |
| 56 | window.localStorage.setItem("name",ret.name); |
| 57 | window.location = "main.html"; |
| 58 | } |
| 59 | }else{ |
| 60 | //$.alert("请求失败了"+ret.status+",请稍后再试", "错误"); |
| 61 | //closeLoading('loginBtn') |
| 62 | //showOk("请求失败了"+ret.status+",请稍后再试") |
| 63 | $.alert("请求失败了"+ret.status+",请稍后再试", "错误"); |
| 64 | $.hideLoading(); |
| 65 | } |
| 66 | }) |
| 67 | } |
| 68 | }; |
| 69 | app.initialize(); |