account.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. $scope.loginbywx = function () {
  23. var scope = "snsapi_userinfo", state = "_" + (+new Date());
  24. Wechat.auth(scope, state, function (response) {
  25. alert(JSON.stringify(response));
  26. }, function (reason) {
  27. alert("Failed: " + reason);
  28. });
  29. }
  30. //获取验证码
  31. $scope.getVerifyCode = function () {
  32. // if (!util.isMobile($scope.vm.mobile)) {
  33. // msg.text('请输入正确的手机号');
  34. // return;
  35. // }
  36. if ($scope.vm.waitSeconds!="获取验证码") {
  37. msg.text('请稍后再试', true);
  38. return;
  39. }
  40. $scope.vm.waitSeconds = "正在发送";
  41. userService.getVerifyCode($scope.vm.mobile).then(function (result) {
  42. wait(50);
  43. // $scope.returncode = result.data;
  44. msg.success(result.data.data.verify_code);
  45. }, function (error) {
  46. $scope.vm.waitSeconds = "获取验证码";
  47. wait(0);
  48. // msg.error(error.data.message);
  49. });
  50. };
  51. var wait = function (seconds) {
  52. if (seconds > 0) {
  53. $scope.vm.waitSeconds = "" + seconds + "秒";
  54. } else {
  55. $scope.vm.waitSeconds = "获取验证码";
  56. }
  57. $timeout(function () {
  58. if (seconds >= 1)
  59. wait(seconds - 1);
  60. }, 1000);
  61. };
  62. $scope.clear = function(){
  63. document.getElementById("tel").value = "";
  64. }
  65. }]);
  66. })(angular.module('app.controllers'));