account.js 2.7 KB

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