暫無描述

login.js 2.2KB

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