account.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. (function (app) {
  2. app.controller('loginCtrl', function ($scope, userService, storage,$ionicHistory, $state, msg, $http) {
  3. $scope.vm = {
  4. mobile: '',
  5. verify_code: '',
  6. waitSeconds: "获取验证码"
  7. };
  8. $scope.login = function () {
  9. $state.go('app.home');
  10. return;
  11. msg.loading('登录中...');
  12. userService.login($scope.vm.mobile, $scope.vm.password).then(function (result) {
  13. msg.hide();
  14. storage.setObject('user', result.data.data.user);
  15. storage.set('token', result.data.data.token);
  16. $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.data.token;
  17. $state.go('app.borrow');
  18. }, function (erro) {
  19. console.log("login erro:"+JSON.stringify(erro));
  20. msg.hide();
  21. msg.error(erro.data.message);
  22. });
  23. }
  24. var wait = function (seconds) {
  25. if (seconds > 0) {
  26. $scope.vm.waitSeconds = "" + seconds + "秒";
  27. } else {
  28. $scope.vm.waitSeconds = "获取验证码";
  29. }
  30. $timeout(function () {
  31. if (seconds >= 1)
  32. wait(seconds - 1);
  33. }, 1000);
  34. };
  35. });
  36. })(angular.module('app.controllers'));