register.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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').focus(function(){
  87. let val = $(this).val();
  88. if(val.indexOf('用户名')>-1||val.indexOf('下划线')>-1||val.indexOf('客户')>-1||val.indexOf('手机')>-1){
  89. $(this).val('').css({color:'#333'})
  90. }
  91. })
  92. $('#photo_num').focus(function(){
  93. if(($(this).val()).indexOf('验证码')>-1){
  94. $(this).val('')
  95. }
  96. $(this).css({color:'#333'})
  97. })
  98. $('#userpassword,#userpassword2').focus(function(){
  99. let passVal =$(this).val();
  100. if(passVal.indexOf('密码')){
  101. $(this).attr('type','password').val('').css({color:'#333'})
  102. }
  103. })
  104. /*失去焦点处理 */
  105. blurFun();
  106. function blurFun(){
  107. $('#username').blur(function(){
  108. let nameRax = /^[a-zA-Z0-9_-]{6,32}$/;
  109. if(!$(this).val().trim()){
  110. $(this).val('请填写用户名').css({color:'#f00'})
  111. }else if(!nameRax.test($(this).val())){
  112. $(this).val('6-32位字母/数字/下划线').css({color:'#f00'})
  113. }
  114. })
  115. $('#userpassword').blur(function () {
  116. var pass_pattern = /^[a-zA-Z\d_]{6,12}$/;
  117. var pass1 = $(this).val().trim();
  118. var tt = $('#userpassword2').val().trim();
  119. if (!pass1|| !pass_pattern.test(pass1)) {
  120. $(this).attr('type',"text")
  121. $(this).val('请输入6-12位数字母开头密码').css({color:'#f00'});
  122. return;
  123. }else{
  124. $(this).attr('type','password');
  125. };
  126. if (pass1 || tt !== pass1) {
  127. $('#userpassword2').attr('type',"text")
  128. $('#userpassword2').val('两次密码不一致').css({color:'#f00'});
  129. return;
  130. };
  131. });
  132. $('#customerName').blur(function(){
  133. if(!$(this).val().trim()){
  134. $(this).val('请填写客户名称').css({color:'#f00'})
  135. }
  136. });
  137. $('#usePhoto').blur(function(){
  138. if(!$(this).val().trim()){
  139. $(this).val('请填写手机号码').css({color:'#f00'})
  140. }
  141. });
  142. $('#userpassword2').blur(function () {
  143. var orepeat = $(this).val();
  144. var passw = $('#userpassword').val();
  145. if (passw !== orepeat || passw == '') {
  146. $(this).attr('type','text')
  147. $(this).val('两次密码不一致').css({color:'#f00'})
  148. }
  149. });
  150. }
  151. //表单提交
  152. $("#form_register").submit(function (e) {
  153. var user = $("#username").val(),
  154. usePhoto = $('#usePhoto').val(),
  155. password1 = $("#userpassword").val(),
  156. password2 = $("#userpassword2").val(),
  157. customerName = $('#customerName').val(),
  158. mobileCode = $('#photo_num').val(); //手机验证码
  159. e.preventDefault();
  160. if(user.indexOf('用户名')>-1||customerName.indexOf('客户')>-1||password1.indexOf('密码')>-1||password2.indexOf('密码')>-1||usePhoto.indexOf('手机')>-1||mobileCode.indexOf('验证码')>-1){
  161. $('#msg').val('请填写必填项');
  162. msg();
  163. return;
  164. } else {
  165. $.ajax({
  166. type: "POST",
  167. dataType: "json",
  168. url: globalConfig.context + "/register",
  169. data: {
  170. "username": user,
  171. "password": password1,
  172. "unitName": customerName,
  173. "mobile": usePhoto,
  174. "mobileCode": mobileCode
  175. },
  176. success: function (rest) {
  177. if (rest.error && rest.error.length) {
  178. $('#msg').val(rest.error[0].message);
  179. msg();
  180. } else {
  181. var data = rest.data;
  182. console.log(data)
  183. $('#msg').val("注册成功!");
  184. msg();
  185. setTimeout(()=>{
  186. window.location.href = globalConfig.context + "/user/signIn.html";
  187. },2000)
  188. }
  189. }
  190. })
  191. }
  192. })
  193. var tt = 30;
  194. $('#photo').click(function () {
  195. var ophoto = $('#usePhoto').val().trim();
  196. if (ophoto) {
  197. $.ajax({
  198. type: "GET",
  199. url: globalConfig.context + "/open/getMCode",
  200. data: {
  201. "mobile": ophoto,
  202. "sign": false,
  203. },
  204. success: function (data) {
  205. if (data.error && data.error.length) {
  206. $('#msg').val(data.error[0].message);
  207. msg();
  208. } else {
  209. $('#msg').val('发送成功');
  210. //验证码倒计时
  211. $('#photo').attr('disabled', true);
  212. var timer = setInterval(function () {
  213. tt -= 1;
  214. $('#photo').val("发送" + '(' + tt + 's' + ')');
  215. $('#photo').css({
  216. color: '#cccccc'
  217. })
  218. if (tt == 0) {
  219. clearInterval(timer);
  220. $('#photo').attr('disabled', false);
  221. tt = 30;
  222. $('#photo').css({
  223. color: '#f18101'
  224. })
  225. $('#photo').val('重新发送');
  226. }
  227. }.bind(this), 1000);
  228. msg();
  229. }
  230. return true;
  231. }
  232. });
  233. } else {
  234. $('#msg').val('请填写手机号码!');
  235. msg();
  236. }
  237. });
  238. //提示框渐隐函数
  239. function msg() {
  240. $('.smg').addClass('active')
  241. var lit = $('#msg').val();
  242. setTimeout(function () {
  243. $('.smg').removeClass('active')
  244. $('#msg').val('');
  245. }, 2000)
  246. }
  247. });