login.js 5.1 KB

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