register.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var app = new Vue({
  2. el: '#app',
  3. data: {
  4. codeTime: 60,
  5. codeStatus: false,
  6. codeSubmitStatus: false,
  7. submitStatus: false,
  8. timeId: null,
  9. formData: {
  10. mobile: '',
  11. code: '',
  12. password: '',
  13. confirmPassword: ''
  14. }
  15. },
  16. mounted: function () {
  17. var _this = this;
  18. $(document).on('keydown', function (event) {
  19. if (event.keyCode == 13) {
  20. _this.doRegister();
  21. }
  22. })
  23. },
  24. methods: {
  25. // 获取验证码
  26. getCode: function () {
  27. var _this = this;
  28. if (_this.codeStatus || _this.codeSubmitStatus) {
  29. return false;
  30. }
  31. if(!_this.checkForm(0)){
  32. return false;
  33. }
  34. _this.codeSubmitStatus = true;
  35. $.post('/weixin/code/send', {mobile: _this.formData.mobile, type: 1}, function (res) {
  36. _this.codeSubmitStatus = false;
  37. if (res.code == 'success') {
  38. _this.cutdown();
  39. _this.codeStatus = true;
  40. $.toast(res.message, 'text');
  41. } else {
  42. $.toast(res.message, 'text');
  43. }
  44. }, "json");
  45. },
  46. // 倒计时
  47. cutdown: function () {
  48. var _this = this;
  49. clearInterval(_this.timeId);
  50. _this.timeId = setInterval(function () {
  51. _this.codeTime--;
  52. if(_this.codeTime <=0){
  53. _this.codeStatus = false;
  54. clearInterval(_this.timeId);
  55. }
  56. }, 1000);
  57. },
  58. // 注册
  59. doRegister: function(){
  60. var _this = this;
  61. if(_this.submitStatus){
  62. return false;
  63. }
  64. if(!_this.checkForm(1)){
  65. return false;
  66. }
  67. _this.submitStatus = true;
  68. $.showLoading("注册中...");
  69. $.post('/weixin/register/doRegister', _this.formData, function (res) {
  70. $.hideLoading();
  71. _this.submitStatus = false;
  72. if (res.code == 'success') {
  73. $.showLoading(res.message);
  74. setTimeout(function(){
  75. location.href = '/weixin/login/index';
  76. }, 500);
  77. } else {
  78. $.toast(res.message, 'text');
  79. }
  80. }, "json");
  81. },
  82. // 验证表单
  83. checkForm: function(type){
  84. if (this.formData.mobile == '' || this.formData.mobile == null) {
  85. $.toast("请输入手机号码", 'text');
  86. return false;
  87. }
  88. var patternMobile = /1[3-9][0-9]{9}/;
  89. if (!patternMobile.test(this.formData.mobile)) {
  90. $.toast("请输入正确的手机号码", 'text');
  91. return false;
  92. }
  93. if(type == 1){
  94. /*if(this.formData.code == '' || this.formData.code == null){
  95. $.toast("请输入手机验证码", 'text');
  96. return false;
  97. }
  98. var codePattern = /[0-9]{4,6}/;
  99. if(!codePattern.test(this.formData.code)){
  100. $.toast("手机验证码格式不正确", 'text');
  101. return false;
  102. }*/
  103. if(this.formData.password == '' || this.formData.password == null){
  104. $.toast("请输入登录密码", 'text');
  105. return false;
  106. }
  107. var passwordPattern = /^[0-9a-zA-Z][0-9a-zA-Z\_\!\@\#\$\%\^\&\*\(\)]{2,19}/;
  108. if(!passwordPattern.test(this.formData.password)){
  109. $.toast("登录密码格式不正确", 'text');
  110. return false;
  111. }
  112. if(this.formData.password != this.formData.confirmPassword){
  113. $.toast("确认密码不正确", 'text');
  114. return false;
  115. }
  116. }
  117. return true;
  118. }
  119. }
  120. })