login.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. $(document).ready(function() {
  2. // const lSPName = getLocalCache('project_name');
  3. const lSPCode = getLocalCache('project_code');
  4. if (lSPCode !== null) {
  5. // $('#project_name').text(lSPName);
  6. $('#project').val(lSPCode);
  7. $('#forget-project').val(lSPCode);
  8. $('#account').focus();
  9. $.ajax({
  10. type: 'get',
  11. url: '/project/name',
  12. data: { code: lSPCode },
  13. dataType: 'json',
  14. success: function (result) {
  15. if (result.err === 1) {
  16. $('#project_name').text('');
  17. $('#forget-project').val('');
  18. toast(result.msg, 'error', 'exclamation-circle');
  19. } else {
  20. $('#project_name').text(result.data);
  21. }
  22. }
  23. })
  24. }
  25. $("#login-tab a[data-toggle='tab']").on('shown.bs.tab', function () {
  26. let type = $(this).data('type');
  27. type = parseInt(type);
  28. type = isNaN(type) || type <= 0 ? 1 : type;
  29. $("input[name='type']:hidden").val(type);
  30. });
  31. // $('#username').blur(function () {
  32. // let account = $(this).val();
  33. // // 判断输入的邮箱/手机是否格式正确
  34. // if(/^1[3456789]\d{9}$/.test(account) || /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(account)) {
  35. // $('#error-msg').hide();
  36. // } else {
  37. // $('#error-msg').show();
  38. // $('#error-msg').text('账号格式有误');
  39. // }
  40. // })
  41. $('#project').blur(function () {
  42. if ($(this).val() == '') {
  43. $('#project_name').text('');
  44. $('#forget-project').val('');
  45. removeLocalCache('project_code');
  46. removeLocalCache('project_name');
  47. } else {
  48. const pcode = getLocalCache('project_code');
  49. if ($(this).val() !== pcode) {
  50. const pc = $(this).val();
  51. $.ajax({
  52. type: 'get',
  53. url: '/project/name',
  54. data: { code: pc },
  55. dataType: 'json',
  56. success: function (result) {
  57. setLocalCache('project_code', pc);
  58. if (result.err === 1) {
  59. $('#project_name').text('');
  60. $('#forget-project').val('');
  61. console.log(result.msg);
  62. toast(result.msg, 'error', 'exclamation-circle');
  63. removeLocalCache('project_name');
  64. } else {
  65. setLocalCache('project_name', result.data);
  66. $('#project_name').text(result.data);
  67. $('#forget-project').val(pc);
  68. }
  69. }
  70. })
  71. }
  72. }
  73. });
  74. $('#forget-btn').click(function () {
  75. let flag = true;
  76. if ($('#forget-project').val() == '') {
  77. $('#forget-project').addClass('is-invalid');
  78. $('#forget-project').siblings('div.invalid-feedback').html('项目编号不能为空。');
  79. flag = false;
  80. }
  81. if ($('#forget-name').val() == '') {
  82. $('#forget-name').addClass('is-invalid');
  83. $('#forget-name').siblings('div.invalid-feedback').html('登录账号不能为空。');
  84. flag = false;
  85. }
  86. if(flag) {
  87. $.ajax({
  88. type: 'post',
  89. url: '/reset/password',
  90. data: { code: $('#forget-project').val(), name: $('#forget-name').val() },
  91. dataType: 'json',
  92. beforeSend: function(xhr) {
  93. let csrfToken = csrf;
  94. xhr.setRequestHeader('x-csrf-token_j', csrfToken);
  95. },
  96. success: function (result) {
  97. if (result.err === 1) {
  98. if (result.index === 1) {
  99. $('#forget-project').addClass('is-invalid');
  100. $('#forget-project').siblings('div.invalid-feedback').html(result.msg);
  101. } else if (result.index === 2) {
  102. $('#forget-name').addClass('is-invalid');
  103. $('#forget-name').siblings('div.invalid-feedback').html(result.msg);
  104. } else {
  105. toast(result.msg, 'error');
  106. }
  107. } else {
  108. $('#fg-password-done').find('b').eq(0).text(result.data.name);
  109. $('#fg-password-done').find('b').eq(1).text(result.data.account);
  110. $('#fg-password-done').find('b').eq(2).text(result.data.mobile);
  111. setLocalCache('project_name', result.data.pName);
  112. setLocalCache('project_code', $('#forget-project').val());
  113. $('#fg-password').modal('hide');
  114. $('#fg-password-done').modal('show');
  115. $('#account').val($('#forget-name').val());
  116. $('#project').val($('#forget-project').val());
  117. $('#project_name').text(result.data.pName);
  118. $('#forget-name').val('');
  119. }
  120. }
  121. })
  122. }
  123. })
  124. $('input').focus(function () {
  125. if($(this).hasClass('is-invalid')) {
  126. $(this).removeClass('is-invalid');
  127. $(this).siblings('div.invalid-feedback').html('');
  128. }
  129. });
  130. $('#focus-pwd').click(function () {
  131. $('#project-password').focus();
  132. })
  133. });