login.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. $(function () {
  2. var isSSo = location.search.length > 0;//是否单点登录
  3. if (isSSo) {
  4. $('.container').hide();
  5. login();
  6. }
  7. var hasClick = false; //是否已经点击过登录按钮
  8. // 兼容ie的placeholder
  9. $('input, textarea').placeholder();
  10. // 登录点击
  11. $('#login').on('click', login);
  12. // 登录方法
  13. function login() {
  14. if (hasClick) return;
  15. hasClick = true;
  16. var name = $('#name').val()
  17. var pwd = $('#pwd').val()
  18. var data = {
  19. username: name,
  20. password: pwd
  21. }
  22. // 单点登录 start
  23. var ssoStr = '';
  24. var ssoJson;
  25. if (isSSo) {
  26. ssoStr = location.search.replace('?', '').split('&')[0].split('=')[1];
  27. ssoStr = Base64.decode(decodeURIComponent(ssoStr));
  28. ssoJson = JSON.parse(ssoStr);
  29. }
  30. var postData = isSSo ? { username: ssoJson.a, password: ssoJson.r, t: false } : data;
  31. // 单点登录 end
  32. $.ajax({
  33. type: "POST",
  34. contentType: "application/json;charset=UTF-8",
  35. url: baseUrl + "auth/reqlogin",
  36. data: JSON.stringify(postData),
  37. success: function (res) {
  38. if (res.state == 200) {
  39. sessionStorage.setItem('loginUser', JSON.stringify(res.data.requester));
  40. //判断版本类别
  41. $.ajax({
  42. type: "POST",
  43. contentType: "application/json;charset=UTF-8",
  44. url: baseUrl + "sysinfo/data/fetchDataList/systemConfiguration",
  45. data: JSON.stringify({ "idx": 0, "sum": 1000, "systemConfiguration": { "keyconfig": "repairMain" } }),
  46. success: function (result) {
  47. if (result.status == 200) {
  48. sessionStorage.setItem("repair_main", JSON.stringify(result.list[0]));
  49. // --------------
  50. //判断是否自动建单
  51. $.ajax({
  52. type: "POST",
  53. contentType: "application/json;charset=UTF-8",
  54. url: baseUrl + "sysinfo/data/fetchDataList/systemConfiguration",
  55. data: JSON.stringify({ "idx": 0, "sum": 1000, "systemConfiguration": { "keyconfig": "ifCreate" } }),
  56. success: function (result) {
  57. if (result.status == 200) {
  58. sessionStorage.setItem("ifCreate", JSON.stringify(result.list[0]));
  59. window.location.href = 'index.html';
  60. }
  61. hasClick = false;
  62. },
  63. //请求失败,包含具体的错误信息
  64. error: function (e) {
  65. console.log(e.status);
  66. console.log(e.responseText);
  67. }
  68. });
  69. // --------------
  70. }
  71. hasClick = false;
  72. },
  73. //请求失败,包含具体的错误信息
  74. error: function (e) {
  75. console.log(e.status);
  76. console.log(e.responseText);
  77. }
  78. });
  79. } else {
  80. alert('用户名或密码错误,请重试!');
  81. hasClick = false;
  82. }
  83. },
  84. //请求失败,包含具体的错误信息
  85. error: function (e) {
  86. console.log(e.status);
  87. console.log(e.responseText);
  88. }
  89. });
  90. }
  91. // enter登录
  92. $(document).bind('keypress', function (e) {
  93. var keyCode;
  94. if (window.event) {
  95. keyCode = e.keyCode
  96. } else if (e.which) {
  97. keycode = e.which;
  98. }
  99. if (e.keyCode != 13) {
  100. return;
  101. }
  102. $("#login").trigger("click");
  103. return false;
  104. });
  105. })