12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- (function (app) {
- app.controller('loginCtrl', ["$scope", "userService", "storage", "$state", "msg", "$http", "util","$timeout",
- function ($scope, userService, storage, $state, msg, $http, util, $timeout) {
- $scope.vm = {
- mobile: '',
- verify_code: '',
- waitSeconds: "获取验证码"
- };
- $scope.login = function () {
- msg.loading('登录中...');
- userService.login($scope.vm.mobile, $scope.vm.verify_code).then(function (result) {
- msg.hide();
- debugger;
- storage.setObject('user', result.data.data.user);
- storage.set('token', result.data.data.token);
- $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.data.token;
- $state.go('app.home');
- }, function (erro) {
- msg.hide();
- msg.error(erro.data.message);
- });
- }
- //获取验证码
- $scope.getVerifyCode = function () {
- if (!util.isMobile($scope.vm.mobile)) {
- msg.text('请输入正确的手机号');
- return;
- }
- $scope.vm.waitSeconds = "正在发送";
- userService.getVerifyCode($scope.vm.mobile).then(function (result) {
- wait(50);
- $scope.returncode = result.data;
- }, function (error) {
- $scope.vm.waitSeconds = "获取验证码";
- wait(0);
- msg.error(error.data.Message);
- });
- };
- var wait = function (seconds) {
- if (seconds > 0) {
- $scope.vm.waitSeconds = "" + seconds + "秒";
- } else {
- $scope.vm.waitSeconds = "获取验证码";
- }
- $timeout(function () {
- if (seconds >= 1)
- wait(seconds - 1);
- }, 1000);
- };
- }]);
-
- })(angular.module('app.controllers'));
|