12345678910111213141516171819202122232425262728293031323334353637 |
- (function (app) {
- app.controller('loginCtrl', function ($scope, userService, storage,$ionicHistory, $state, msg, $http) {
- $scope.vm = {
- mobile: '',
- verify_code: '',
- waitSeconds: "获取验证码"
- };
- $scope.login = function () {
- $state.go('app.home');
- return;
- msg.loading('登录中...');
- userService.login($scope.vm.mobile, $scope.vm.password).then(function (result) {
- msg.hide();
- 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.borrow');
- }, function (erro) {
- console.log("login erro:"+JSON.stringify(erro));
- msg.hide();
- msg.error(erro.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'));
|