account.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. (function (app) {
  2. app.controller('loginCtrl', ["$scope", "userService","$ionicNavBarDelegate", "storage", "$state", "msg", "$http", "util","$timeout",
  3. function ($scope, userService,$ionicNavBarDelegate, storage, $state, msg, $http, util, $timeout) {
  4. //$ionicNavBarDelegate.showBackButton(false);
  5. $scope.vm = {
  6. mobile: '',
  7. verify_code: '',
  8. waitSeconds: "获取验证码"
  9. };
  10. $scope.login = function () {
  11. msg.loading('登录中...');
  12. userService.login($scope.vm.mobile, $scope.vm.verify_code).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. $scope.user=storage.getObject('user');
  18. $state.go('app.home');
  19. }, function (error) {
  20. // msg.hide();
  21. // msg.error(error.data.message);
  22. });
  23. };
  24. //$scope.loginbywx = function () {
  25. // var scope = "snsapi_userinfo", state = "_" + (+new Date());
  26. // Wechat.auth(scope, state, function (response) {
  27. //
  28. // alert(JSON.stringify(response));
  29. // }, function (reason) {
  30. // alert("Failed: " + reason);
  31. // });
  32. //};
  33. $scope.loginbywx = function(){
  34. $state.go("loginAccount")
  35. };
  36. //获取验证码
  37. $scope.getVerifyCode = function () {
  38. // if (!util.isMobile($scope.vm.mobile)) {
  39. // msg.text('请输入正确的手机号');
  40. // return;
  41. // }
  42. if ($scope.vm.waitSeconds!="获取验证码") {
  43. msg.text('请稍后再试', true);
  44. return;
  45. }
  46. $scope.vm.waitSeconds = "正在发送";
  47. userService.getVerifyCode($scope.vm.mobile).then(function (result) {
  48. wait(50);
  49. // $scope.returncode = result.data;
  50. if(result.data.data.verify_code)msg.success(result.data.data.verify_code);
  51. }, function (error) {
  52. $scope.vm.waitSeconds = "获取验证码";
  53. wait(0);
  54. // msg.error(error.data.message);
  55. });
  56. };
  57. var wait = function (seconds) {
  58. if (seconds > 0) {
  59. $scope.vm.waitSeconds = "" + seconds + "秒";
  60. } else {
  61. $scope.vm.waitSeconds = "获取验证码";
  62. }
  63. $timeout(function () {
  64. if (seconds >= 1)
  65. wait(seconds - 1);
  66. }, 1000);
  67. };
  68. $scope.clear = function(){
  69. document.getElementById("tel").value = "";
  70. }
  71. }]);
  72. })(angular.module('app.controllers'));