login.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var app = new Vue({
  2. el: '#app',
  3. data: {
  4. submitStatus: false,
  5. formData: {
  6. mobile: '',
  7. password: '',
  8. }
  9. },
  10. mounted: function () {
  11. var _this = this;
  12. $(document).on('keydown', function (event) {
  13. if (event.keyCode == 13) {
  14. _this.doLogin();
  15. }
  16. })
  17. },
  18. methods: {
  19. // 登录
  20. doLogin: function () {
  21. var _this = this;
  22. if (_this.submitStatus) {
  23. return false;
  24. }
  25. if (!_this.checkForm()) {
  26. return false;
  27. }
  28. _this.submitStatus = true;
  29. $.showLoading("登录中...");
  30. $.post('/weixin/login/doLogin', _this.formData, function (res) {
  31. _this.submitStatus = false;
  32. $.hideLoading();
  33. if (res.code == 'success') {
  34. $.showLoading(res.message);
  35. setTimeout(function () {
  36. var url = res.data.url ? res.data.url : '/weixin/index/index';
  37. location.href = url;
  38. }, 500);
  39. } else {
  40. $.toast(res.message, 'text');
  41. }
  42. }, "json");
  43. },
  44. // 验证表单
  45. checkForm: function () {
  46. if (this.formData.mobile == '' || this.formData.mobile == null) {
  47. $.toast("请输入手机号码", 'text');
  48. return false;
  49. }
  50. var patternMobile = /1[3-9][0-9]{9}/;
  51. if (!patternMobile.test(this.formData.mobile)) {
  52. $.toast("请输入正确的手机号码", 'text');
  53. return false;
  54. }
  55. if (this.formData.password == '' || this.formData.password == null) {
  56. $.toast("请输入登录密码", 'text');
  57. return false;
  58. }
  59. var passwordPattern = /^[0-9a-zA-Z][0-9a-zA-Z\_\!\@\#\$\%\^\&\*\(\)]{2,19}/;
  60. if (!passwordPattern.test(this.formData.password)) {
  61. $.toast("登录密码格式不正确", 'text');
  62. return false;
  63. }
  64. return true;
  65. }
  66. }
  67. })