login.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. if (isSSo) {
  40. sessionStorage.setItem('isSSo', '1');//单点登录
  41. } else {
  42. sessionStorage.setItem('isSSo', '0');//正常登录
  43. }
  44. sessionStorage.setItem('loginUser', JSON.stringify(res.data.requester));
  45. //判断版本类别
  46. $.ajax({
  47. type: "POST",
  48. contentType: "application/json;charset=UTF-8",
  49. url: baseUrl + "sysinfo/data/fetchDataList/systemConfiguration",
  50. data: JSON.stringify({ "idx": 0, "sum": 1000, "systemConfiguration": { "keyconfig": "repairMain" } }),
  51. success: function (result) {
  52. if (result.status == 200) {
  53. sessionStorage.setItem("repair_main", JSON.stringify(result.list[0]));
  54. // --------------
  55. //判断是否自动建单
  56. $.ajax({
  57. type: "POST",
  58. contentType: "application/json;charset=UTF-8",
  59. url: baseUrl + "sysinfo/data/fetchDataList/systemConfiguration",
  60. data: JSON.stringify({ "idx": 0, "sum": 1000, "systemConfiguration": { "keyconfig": "reqHasCategory" } }),
  61. success: function (result) {
  62. if (result.status == 200) {
  63. sessionStorage.setItem("reqHasCategory", JSON.stringify(result.list[0]));
  64. window.location.href = 'index.html';
  65. }
  66. hasClick = false;
  67. },
  68. //请求失败,包含具体的错误信息
  69. error: function (e) {
  70. console.log(e.status);
  71. console.log(e.responseText);
  72. }
  73. });
  74. // --------------
  75. }
  76. hasClick = false;
  77. },
  78. //请求失败,包含具体的错误信息
  79. error: function (e) {
  80. console.log(e.status);
  81. console.log(e.responseText);
  82. }
  83. });
  84. } else {
  85. alert('用户名或密码错误,请重试!');
  86. hasClick = false;
  87. }
  88. },
  89. //请求失败,包含具体的错误信息
  90. error: function (e) {
  91. console.log(e.status);
  92. console.log(e.responseText);
  93. }
  94. });
  95. }
  96. // enter登录
  97. $(document).bind('keypress', function (e) {
  98. var keyCode;
  99. if (window.event) {
  100. keyCode = e.keyCode
  101. } else if (e.which) {
  102. keycode = e.which;
  103. }
  104. if (e.keyCode != 13) {
  105. return;
  106. }
  107. $("#login").trigger("click");
  108. return false;
  109. });
  110. })