forget.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.doSubmit();
  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: 2}, 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. doSubmit: function(){
  60. var _this = this;
  61. if(_this.submitStatus){
  62. return false;
  63. }
  64. if(!_this.checkForm(1)){
  65. return false;
  66. }
  67. if(confirm('确定重置登录密码?')){
  68. _this.submitStatus = true;
  69. $.showLoading("重置密码中...");
  70. $.post('/weixin/login/doForget', _this.formData, function (res) {
  71. _this.submitStatus = false;
  72. $.hideLoading();
  73. if (res.code == 'success') {
  74. $.showLoading(res.message);
  75. setTimeout(function(){
  76. location.href = '/weixin/login/index';
  77. }, 500);
  78. } else {
  79. $.toast(res.message, 'text');
  80. }
  81. }, "json");
  82. }
  83. },
  84. // 验证表单
  85. checkForm: function(type){
  86. if (this.formData.mobile == '' || this.formData.mobile == null) {
  87. $.toast("请输入手机号码", 'text');
  88. return false;
  89. }
  90. var patternMobile = /1[3-9][0-9]{9}/;
  91. if (!patternMobile.test(this.formData.mobile)) {
  92. $.toast("请输入正确的手机号码", 'text');
  93. return false;
  94. }
  95. if(type == 1){
  96. if(this.formData.code == '' || this.formData.code == null){
  97. $.toast("请输入手机验证码", 'text');
  98. return false;
  99. }
  100. var codePattern = /[0-9]{4,6}/;
  101. if(!codePattern.test(this.formData.code)){
  102. $.toast("手机验证码格式不正确", 'text');
  103. return false;
  104. }
  105. if(this.formData.password == '' || this.formData.password == null){
  106. $.toast("请设置登录密码", 'text');
  107. return false;
  108. }
  109. var passwordPattern = /^[0-9a-zA-Z][0-9a-zA-Z\_\!\@\#\$\%\^\&\*\(\)]{2,19}/;
  110. if(!passwordPattern.test(this.formData.password)){
  111. $.toast("登录密码格式不正确", 'text');
  112. return false;
  113. }
  114. if(this.formData.password != this.formData.confirmPassword){
  115. $.toast("确认密码不正确", 'text');
  116. return false;
  117. }
  118. }
  119. return true;
  120. }
  121. }
  122. })