説明なし

login.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. mui.init();
  2. mui.plusReady(function() {
  3. var usercode = localStorage.getItem("user"); //获取本地存储
  4. var psw = localStorage.getItem("psw"); //获取本地存储s
  5. if(usercode != null) //如果缓存中有数据,则加载出来
  6. {
  7. document.getElementById("account").value = usercode;
  8. document.getElementById("password").value = localStorage.getItem("psw");
  9. }
  10. document.getElementById("login").addEventListener('tap', function() {
  11. var username = document.getElementById('account').value;
  12. var password = document.getElementById('password').value;
  13. var data = {
  14. "Username": username,
  15. "Password": password,
  16. " extensionphone": 1
  17. };
  18. if(!username) {
  19. plus.nativeUI.toast('输入账号');
  20. } else if(!password) {
  21. plus.nativeUI.toast('密码不能为空');
  22. } else {
  23. if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
  24. mui.toast("网络连接中断!");
  25. }
  26. // 调用ajax
  27. mui.ajax(huayi.config.callcenter_url + '/WorkorderApp/login', {
  28. data: data,
  29. dataType: 'json', //服务器返回json格式数据
  30. type: 'post', //HTTP请求类型
  31. timeout: 10000, //超时时间设置为10秒
  32. success: function(data) {
  33. if(data.state == "success") {
  34. localStorage.setItem("token", data.data.token);
  35. localStorage.setItem("user", username);
  36. localStorage.setItem("psw", password);
  37. var nwaiting = plus.nativeUI.showWaiting();
  38. webviewShow = plus.webview.create("Leader-index.html"); //后台创建webview并打开show.html
  39. document.getElementById('account').value = "";
  40. document.getElementById('password').value = "";
  41. } else {
  42. mui.alert(data.message);
  43. document.getElementById('account').value = "";
  44. document.getElementById('password').value = "";
  45. }
  46. },
  47. error: function(xhr, type, errorThrown) {}
  48. });
  49. }
  50. });
  51. });