1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
(function() { 'use strict'; angular .module('app.oy_httpinterceptor', []); })();
(function() { 'use strict';
angular .module('app.oy_httpinterceptor') .factory('oy_httpinterceptor_config',oy_httpinterceptor_factory) ; oy_httpinterceptor_factory.$inject = [ '$rootScope', '$q', '$injector','$window']; function oy_httpinterceptor_factory($rootScope, $q, $injector,$window) { var httpInterceptor = { 'responseError': function (response) { if(response.status == -1){ response.status = 200; } return $q.reject("网络连接错误!"); }, 'response': function (response) { return response; }, 'request': function (config) { let url = config.url;
if (url && config.method.toLowerCase() != 'GET'.toLowerCase() && url.indexOf('.html') < 0) { config.params = config.params || {}; config.params.timestamp = new Date().getTime(); }
if(angular.isObject(config.data)) { var param = []; angular.forEach(config.data, function(value, key) { this.push(key + '=' + value); }, param); config.data = param.join('&'); }
config.headers = config.headers || {}; config.headers['Content-Type'] = "application/x-www-form-urlencoded";
return config; }, 'requestError': function (config) { return $q.reject("网络连接错误!"); } } return httpInterceptor; }
})();
(function() { 'use strict';
angular .module('app.oy_httpinterceptor') .config(oy_httpinterceptor_config) ; oy_httpinterceptor_config.$inject = ['$httpProvider']; function oy_httpinterceptor_config($httpProvider) { $httpProvider.interceptors.push('oy_httpinterceptor_config'); } })();
|