Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. var mobileRE = /^(((13[0-9]{1})|(14[57]{1})|(15[0-9]{1})|(17[678]{1})|(18[0-9]{1}))+\d{8})$/;
  2. var passwordRE = /^[A-Za-z0-9]{6,20}$/;
  3. var BASE_PATH = '${basePath}';
  4. var j_captchaUrl = '${basePath}/jcaptcha'; // 获取验证码的后端地址
  5. var app = new Vue({
  6. el: '#app',
  7.  
  8. data: {
  9. mobile: '',
  10. j_captcha: '',
  11. vaildCode: '',
  12. password: '',
  13. conpassword: '',
  14. j_captchaUrl: j_captchaUrl
  15. },
  16.  
  17. computed: {
  18. validation: function() {
  19. return {
  20. mobile: mobileRE.test(this.mobile),
  21. j_captcha: !!this.j_captcha.trim(),
  22. vaildCode: !!this.vaildCode.trim(),
  23. password: passwordRE.test(this.password),
  24. conpassword: passwordRE.test(this.conpassword)
  25. }
  26. },
  27. isValid: function() {
  28. var validation = this.validation;
  29. return Object.keys(validation).every(function(key) {
  30. console.log('[' + key + ']' + validation[key]);
  31. return validation[key];
  32. })
  33. }
  34. },
  35.  
  36. methods: {
  37. // 用户注册
  38. register: function() {
  39. if (this.password !== this.conpassword) {
  40. alert('两次输入密码不一致,请重新输入!');
  41. return false;
  42. }
  43.  
  44. if (this.isValid) {
  45. $.ajax(BASE_PATH + '/doregister', {
  46. data: {
  47. mobile: this.mobile,
  48. vaildCode: this.vaildCode,
  49. password: this.password
  50. },
  51. dataType: 'json',
  52. type: 'post',
  53. timeout: 10000,
  54. success: function(data) {
  55. if (data.success) {
  56. // 3秒后自动跳转到首页!
  57. setTimeout(function() {
  58. window.location.href = BASE_PATH;
  59. },
  60. 3000);
  61. } else {
  62. if (data.respinfo) {
  63. alert(data.respinfo);
  64. } else {
  65. alert('注册失败!');
  66. }
  67. }
  68. },
  69. error: function(xhr, type, errorThrown) {
  70. console.log(type);
  71. alert('注册失败!');
  72. },
  73. beforeSend: function() {},
  74. complete: function() {}
  75. });
  76. } else {
  77. if (!this.validation.mobile) {
  78. alert('请输入有效的手机号码!');
  79. } else if (!this.validation.j_captcha) {
  80. alert('请输入图片验证码!');
  81. } else if (!this.validation.vaildCode) {
  82. alert('请输入短信验证码!');
  83. } else if (!this.validation.password) {
  84. alert('请输入有效的密码,格式为6至20位的字母和数字!');
  85. } else if (!this.validation.conpassword) {
  86. alert('请输入有效的密码,格式为6至20位的字母和数字!');
  87. }
  88. }
  89. },
  90. // 发送短信验证码
  91. send: function() {
  92. if (this.validation.mobile) {
  93. // 调用倒计时插件
  94. $('#btn-code').timer();
  95.  
  96. $.ajax(BASE_PATH + '/doSendRegVaild', {
  97. data: {
  98. mobile: this.mobile
  99. },
  100. dataType: 'json',
  101. type: 'post',
  102. timeout: 10000,
  103. success: function(data) {
  104. if (data.success) {
  105. if (data.respinfo) {
  106. alert(data.respinfo);
  107. } else {
  108. alert('验证码获取成功!');
  109. }
  110. } else {
  111. if (data.respinfo) {
  112. alert(data.respinfo);
  113. } else {
  114. alert('验证码获取失败!');
  115. }
  116. }
  117. },
  118. error: function(xhr, type, errorThrown) {
  119. console.log(type) alert('验证码获取失败!');
  120. },
  121. beforeSend: function() {},
  122. complete: function() {}
  123. });
  124. } else {
  125. alert('请输入有效的手机号码!');
  126. }
  127. },
  128. // 检测输入的图片验证码是否正确
  129. check: function() {
  130. var self = this;
  131. $.ajax(BASE_PATH + '/verifycaptcha', {
  132. data: {
  133. j_captcha: this.j_captcha
  134. },
  135. dataType: 'json',
  136. type: 'get',
  137. timeout: 10000,
  138. success: function(data) {
  139. console.log(data.success);
  140. if (data.success) {
  141.  
  142. } else {
  143. alert('图片验证码输入错误!');
  144. self.j_captcha = ''self.changej_captcha();
  145. }
  146. },
  147. error: function(xhr, type, errorThrown) {
  148. console.log(type);
  149. alert('验证码获取失败!');
  150. },
  151. beforeSend: function() {},
  152. complete: function() {}
  153. });
  154. },
  155. // 重新获取验证码
  156. changej_captcha: function() {
  157. this.j_captchaUrl = j_captchaUrl + '?' + Math.random();
  158. },
  159. }
  160. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement