説明なし

login.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. <<<<<<< HEAD
  12. alert("111")
  13. =======
  14. >>>>>>> dc8886372f33ab5a85b88d764e008237f3ac82e1
  15. var username = document.getElementById('account').value;
  16. var password = document.getElementById('password').value;
  17. var data = {
  18. "Username": username,
  19. "Password": password,
  20. " extensionphone": 1
  21. };
  22. if(!username) {
  23. plus.nativeUI.toast('输入账号');
  24. } else if(!password) {
  25. plus.nativeUI.toast('密码不能为空');
  26. } else {
  27. if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
  28. mui.toast("网络连接中断!");
  29. }
  30. // 调用ajax
  31. mui.ajax(huayi.config.callcenter_url + '/WorkorderApp/login', {
  32. data: data,
  33. dataType: 'json', //服务器返回json格式数据
  34. type: 'post', //HTTP请求类型
  35. timeout: 10000, //超时时间设置为10秒
  36. success: function(data) {
  37. if(data.state == "success") {
  38. localStorage.setItem("token", data.data.token);
  39. localStorage.setItem("user", username);
  40. localStorage.setItem("psw", password);
  41. var nwaiting = plus.nativeUI.showWaiting();
  42. webviewShow = plus.webview.create("Leader-index.html"); //后台创建webview并打开show.html
  43. document.getElementById('account').value = "";
  44. document.getElementById('password').value = "";
  45. } else {
  46. mui.alert(data.message);
  47. document.getElementById('account').value = "";
  48. document.getElementById('password').value = "";
  49. }
  50. },
  51. error: function(xhr, type, errorThrown) {}
  52. });
  53. }
  54. });
  55. //监听系统通知栏消息点击事件
  56. plus.push.addEventListener('click', function(msg){
  57. //处理点击消息的业务逻辑代码
  58. plus.webview.create('personal.html')
  59. }, false);
  60. //监听接收透传消息事件
  61. plus.push.addEventListener('receive', function(msg){
  62. //处理透传消息的业务逻辑代码
  63. }, false);
  64. });