register.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import '../css/bootstrap.less';
  2. import 'bootstrap/dist/js/bootstrap.js';
  3. import '../css/public.css';
  4. import '../css/register.css';
  5. import './public.js';
  6. import { DH_NOT_SUITABLE_GENERATOR } from 'constants';
  7. $(function () {
  8. //查看技淘网协议
  9. var hht = $(window).height();
  10. $('.login_').height(hht);
  11. $('.head_login_').click(function (e) {
  12. e.preventDefault();
  13. $('.login_').fadeIn(800)
  14. })
  15. $('.login_close_').click(function () {
  16. $('.login_').fadeOut(800)
  17. })
  18. //登陆
  19. var hht = $(window).height();
  20. $('.login').height(hht);
  21. $('.login').hide()
  22. $('.head_login').click(function (e) {
  23. e.preventDefault();
  24. $('.login').fadeIn(800)
  25. })
  26. $('.login_close').click(function () {
  27. $('.login').fadeOut(800)
  28. })
  29. //点击账号后面那个×,清空账号
  30. $(".log_del").click(function () {
  31. $("#username").focus().val("").css('color','#666');
  32. });
  33. var xieyi = $('#protocol').prop("checked", false);
  34. $('.sub').attr('disabled', true)
  35. $('.sub').css({
  36. background: '#CCCCCC',
  37. border: 'none'
  38. })
  39. $('#protocol').click(function () {
  40. var Cheack_no = $(this).prop('checked')
  41. if (Cheack_no) {
  42. $(this).parent().removeClass('cheackeds_no').addClass('cheackeds');
  43. $('.sub').attr('disabled', false);
  44. $('.sub').css({
  45. background: '#F18101',
  46. border: 'none'
  47. })
  48. } else {
  49. $(this).prop('checked', false)
  50. $(this).parent().addClass('cheackeds_no').removeClass('cheackeds');
  51. $('.sub').attr('disabled', true)
  52. $('.sub').css({
  53. background: '#CCCCCC',
  54. border: 'none'
  55. })
  56. }
  57. })
  58. //手机号码
  59. let oldPhoto='';
  60. $('#photo').attr('disabled', true);
  61. function photo1() {
  62. var pho_pattern = /^1[3|4|5|7|8][0-9]{9}$/;
  63. $("#usePhoto").keyup(function () {
  64. oldPhoto = $(this).val();
  65. if (pho_pattern.test(oldPhoto)) {
  66. $('#photo').attr('disabled', false);
  67. $("#photo").css("color", "#F18101");
  68. } else if (!pho_pattern.test(oldPhoto)) {
  69. $('#photo').attr('disabled', true);
  70. $("#photo").css("color", "#ccc");
  71. }
  72. });
  73. }
  74. photo1();
  75. //手机验证码
  76. function photo_num() {
  77. $('#photo_num').blur(function () {
  78. var phoa = $(this).val();
  79. if (phoa == '') {
  80. $(this).val('验证码不能为空').css({color:'#f00'});
  81. }
  82. })
  83. }
  84. photo_num();
  85. /* 获得焦点处理 */
  86. $('#username,#customerName,#usePhoto,#photo_num').focus(function(){
  87. let val = $(this).val();
  88. if(val.indexOf('用户名')>-1||val.indexOf('下划线')>-1||val.indexOf('客户')>-1||val.indexOf('手机')>-1||val.indexOf('验证码')>-1){
  89. $(this).val('').css({color:'#333'})
  90. }
  91. })
  92. $('#userpassword,#userpassword2').focus(function(){
  93. let passVal =$(this).val();
  94. if(passVal.indexOf('密码')){
  95. $(this).attr('type','password').val('').css({color:'#333'})
  96. }
  97. })
  98. /*失去焦点处理 */
  99. blurFun();
  100. function blurFun(){
  101. $('#username').blur(function(){
  102. let nameRax = /^[a-zA-Z0-9_-]{6,32}$/;
  103. if(!$(this).val().trim()){
  104. $(this).val('请填写用户名').css({color:'#f00'})
  105. }else if(!nameRax.test($(this).val())){
  106. $(this).val('6-32位字母/数字/下划线').css({color:'#f00'})
  107. }
  108. })
  109. $('#userpassword').blur(function () {
  110. var pass_pattern = /^[a-zA-Z\d_]{6,12}$/;
  111. var pass1 = $(this).val().trim();
  112. var tt = $('#userpassword2').val().trim();
  113. if (!pass1|| !pass_pattern.test(pass1)) {
  114. $(this).attr('type',"text")
  115. $(this).val('请输入6-12位数字母开头密码').css({color:'#f00'});
  116. return;
  117. }else{
  118. $(this).attr('type','password');
  119. };
  120. if (pass1 || tt !== pass1) {
  121. $('#userpassword2').attr('type',"text")
  122. $('#userpassword2').val('两次密码不一致').css({color:'#f00'});
  123. return;
  124. };
  125. });
  126. $('#customerName').blur(function(){
  127. if(!$(this).val().trim()){
  128. $(this).val('请填写客户名称').css({color:'#f00'})
  129. }
  130. });
  131. $('#usePhoto').blur(function(){
  132. if(!$(this).val().trim()){
  133. $(this).val('请填写手机号码').css({color:'#f00'})
  134. }
  135. });
  136. $('#userpassword2').blur(function () {
  137. var orepeat = $(this).val();
  138. var passw = $('#userpassword').val();
  139. if (passw !== orepeat || passw == '') {
  140. $(this).attr('type','text')
  141. $(this).val('两次密码不一致').css({color:'#f00'})
  142. }
  143. });
  144. }
  145. //表单提交
  146. $("#form_register").submit(function (e) {
  147. var user = $("#username").val(),
  148. usePhoto = $('#usePhoto').val(),
  149. password1 = $("#userpassword").val(),
  150. password2 = $("#userpassword2").val(),
  151. customerName = $('#customerName').val(),
  152. mobileCode = $('#photo_num').val(); //手机验证码
  153. e.preventDefault();
  154. if(user.indexOf('用户名')>-1||customerName.indexOf('客户')>-1||password1.indexOf('密码')>-1||password2.indexOf('密码')>-1||usePhoto.indexOf('手机')>-1||mobileCode.indexOf('验证码')>-1){
  155. $('#msg').val('请填写必填项');
  156. msg();
  157. return;
  158. } else {
  159. $.ajax({
  160. type: "POST",
  161. dataType: "json",
  162. url: globalConfig.context + "/register",
  163. data: {
  164. "username": user,
  165. "password": password1,
  166. "unitName": customerName,
  167. "mobile": usePhoto,
  168. "mobileCode": mobileCode
  169. },
  170. success: function (rest) {
  171. if (rest.error && rest.error.length) {
  172. $('#msg').val(rest.error[0].message);
  173. msg();
  174. } else {
  175. var data = rest.data;
  176. console.log(data)
  177. $('#msg').val("注册成功!");
  178. msg();
  179. setTimeout(()=>{
  180. window.location.href = globalConfig.context + "/user/signIn.html";
  181. },2000)
  182. }
  183. }
  184. })
  185. }
  186. })
  187. var tt = 30;
  188. $('#photo').click(function () {
  189. var ophoto = $('#usePhoto').val().trim();
  190. if (ophoto) {
  191. $.ajax({
  192. type: "GET",
  193. url: globalConfig.context + "/open/getMCode",
  194. data: {
  195. "mobile": ophoto,
  196. "sign": false,
  197. },
  198. success: function (data) {
  199. if (data.error && data.error.length) {
  200. $('#msg').val(data.error[0].message);
  201. msg();
  202. } else {
  203. $('#msg').val('发送成功');
  204. //验证码倒计时
  205. $('#photo').attr('disabled', true);
  206. var timer = setInterval(function () {
  207. tt -= 1;
  208. $('#photo').val("发送" + '(' + tt + 's' + ')');
  209. $('#photo').css({
  210. color: '#cccccc'
  211. })
  212. if (tt == 0) {
  213. clearInterval(timer);
  214. $('#photo').attr('disabled', false);
  215. tt = 30;
  216. $('#photo').css({
  217. color: '#f18101'
  218. })
  219. $('#photo').val('重新发送');
  220. }
  221. }.bind(this), 1000);
  222. msg();
  223. }
  224. return true;
  225. }
  226. });
  227. } else {
  228. $('#msg').val('请填写手机号码!');
  229. msg();
  230. }
  231. });
  232. //提示框渐隐函数
  233. function msg() {
  234. $('.smg').addClass('active')
  235. var lit = $('#msg').val();
  236. setTimeout(function () {
  237. $('.smg').removeClass('active')
  238. $('#msg').val('');
  239. }, 2000)
  240. }
  241. });