account.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. (function (app) {
  2. app.controller('loginCtrl', ["$scope", "userService", "storage", "$state", "msg", "$http", "util","$timeout",
  3. function ($scope, userService, storage, $state, msg, $http, util, $timeout) {
  4. $scope.vm = {
  5. mobile: '',
  6. verify_code: '',
  7. waitSeconds: "获取验证码"
  8. };
  9. $scope.login = function () {
  10. msg.loading('登录中...');
  11. userService.login($scope.vm.mobile, $scope.vm.verify_code).then(function (result) {
  12. msg.hide();
  13. storage.setObject('user', result.data.data.user);
  14. storage.set('token', result.data.data.token);
  15. $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.data.token;
  16. $state.go('app.home');
  17. }, function (error) {
  18. // msg.hide();
  19. // msg.error(error.data.message);
  20. });
  21. }
  22. //获取验证码
  23. $scope.getVerifyCode = function () {
  24. // if (!util.isMobile($scope.vm.mobile)) {
  25. // msg.text('请输入正确的手机号');
  26. // return;
  27. // }
  28. if ($scope.vm.waitSeconds!="获取验证码") {
  29. msg.text('请稍后再试', true);
  30. return;
  31. }
  32. $scope.vm.waitSeconds = "正在发送";
  33. userService.getVerifyCode($scope.vm.mobile).then(function (result) {
  34. wait(50);
  35. // $scope.returncode = result.data;
  36. msg.success(result.data.data.verify_code);
  37. }, function (error) {
  38. $scope.vm.waitSeconds = "获取验证码";
  39. wait(0);
  40. // msg.error(error.data.message);
  41. });
  42. };
  43. var wait = function (seconds) {
  44. if (seconds > 0) {
  45. $scope.vm.waitSeconds = "" + seconds + "秒";
  46. } else {
  47. $scope.vm.waitSeconds = "获取验证码";
  48. }
  49. $timeout(function () {
  50. if (seconds >= 1)
  51. wait(seconds - 1);
  52. }, 1000);
  53. };
  54. $scope.clear = function(){
  55. document.getElementById("tel").value = "";
  56. }
  57. }]);
  58. })(angular.module('app.controllers'));