register.js 8.7 KB

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