mui.init(); mui.plusReady(function() { var usercode = localStorage.getItem("user"); //获取本地存储 var psw = localStorage.getItem("psw"); //获取本地存储s if(usercode != null) //如果缓存中有数据,则加载出来 { document.getElementById("account").value = usercode; document.getElementById("password").value = localStorage.getItem("psw"); } document.getElementById("login").addEventListener('tap', function() { var username = document.getElementById('account').value; var password = document.getElementById('password').value; var data = { "Username": username, "Password": password, " extensionphone": 1 }; if(!username) { plus.nativeUI.toast('输入账号'); } else if(!password) { plus.nativeUI.toast('密码不能为空'); } else { if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) { mui.toast("网络连接中断!"); } // 调用ajax mui.ajax(huayi.config.callcenter_url + '/WorkorderApp/login', { data: data, dataType: 'json', //服务器返回json格式数据 type: 'post', //HTTP请求类型 timeout: 10000, //超时时间设置为10秒 success: function(data) { if(data.state == "success") { localStorage.setItem("token", data.data.token); localStorage.setItem("user", username); localStorage.setItem("psw", password); var nwaiting = plus.nativeUI.showWaiting(); webviewShow = plus.webview.create("Leader-index.html"); //后台创建webview并打开show.html document.getElementById('account').value = ""; document.getElementById('password').value = ""; } else { mui.alert(data.message); document.getElementById('account').value = ""; document.getElementById('password').value = ""; } }, error: function(xhr, type, errorThrown) {} }); } }); });