|
@@ -8,14 +8,38 @@
|
|
$ionicConfigProvider.backButton.text('后退').icon('ion-chevron-left');
|
|
$ionicConfigProvider.backButton.text('后退').icon('ion-chevron-left');
|
|
$ionicConfigProvider.form.checkbox("circle");
|
|
$ionicConfigProvider.form.checkbox("circle");
|
|
$ionicConfigProvider.templates.maxPrefetch(0);
|
|
$ionicConfigProvider.templates.maxPrefetch(0);
|
|
|
|
+ }]).factory('myHttpInterceptor', ["$q", 'data', function ($q, data) { //$http拦截器定义
|
|
|
|
+ var initInjector = angular.injector(['ng']);
|
|
|
|
+ var $http = initInjector.get('$http');
|
|
|
|
+ return {
|
|
|
|
+ 'request': function (config) {
|
|
|
|
+ return config;
|
|
|
|
+ },
|
|
|
|
+ 'requestError': function (rejection) {
|
|
|
|
+ return $q.reject(rejection);
|
|
|
|
+ },
|
|
|
|
+ 'response': function (response) {
|
|
|
|
+ return response;
|
|
|
|
+ },
|
|
|
|
+ 'responseError': function (rejection) {
|
|
|
|
+ if (rejection.status == 401) {
|
|
|
|
+ data.remove('user');
|
|
|
|
+ data.remove('token');
|
|
|
|
+ $http.defaults.headers.common["Authorization"] = undefined;
|
|
|
|
+ window.location.href = '#/account/login';
|
|
|
|
+ return $q.reject('');
|
|
|
|
+ }
|
|
|
|
+ return $q.reject(rejection);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}])
|
|
}])
|
|
.config(["$httpProvider", "$windowProvider", function ($httpProvider, $windowProvider) {
|
|
.config(["$httpProvider", "$windowProvider", function ($httpProvider, $windowProvider) {
|
|
var win = $windowProvider.$get();
|
|
var win = $windowProvider.$get();
|
|
var token=win.localStorage['token'];
|
|
var token=win.localStorage['token'];
|
|
- ////http配置
|
|
|
|
if (token) {
|
|
if (token) {
|
|
$httpProvider.defaults.headers.common['Authorization'] = 'Bearer ' + token;
|
|
$httpProvider.defaults.headers.common['Authorization'] = 'Bearer ' + token;
|
|
}
|
|
}
|
|
|
|
+ $httpProvider.interceptors.push('myHttpInterceptor');
|
|
}])
|
|
}])
|
|
.run(["$ionicPlatform", "$location", "msg", "$rootScope", "$timeout", "$ionicHistory", "userService", "$state", "$http",
|
|
.run(["$ionicPlatform", "$location", "msg", "$rootScope", "$timeout", "$ionicHistory", "userService", "$state", "$http",
|
|
function ($ionicPlatform, $location, msg, $rootScope, $timeout, $ionicHistory, userService, $state, $http) {
|
|
function ($ionicPlatform, $location, msg, $rootScope, $timeout, $ionicHistory, userService, $state, $http) {
|