login.js 6.3 KB

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