config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. var app = angular.module('app');
  3. app.constant('main_host', main_host);
  4. app.factory('frameAjaxInterceptor', function($q, $rootScope) {
  5. return {
  6. 'request': function(config) {
  7. return config;
  8. },
  9. 'requestError': function(rejection) {
  10. return $q.reject(rejection);
  11. },
  12. 'response': function(response) {
  13. return response;
  14. },
  15. 'responseError': function(rejection) {
  16. if (rejection.status == 504) {
  17. var d = dialog({
  18. title: '错误提示',
  19. content: "您超时间未操作,请重新登录本系统",
  20. ok: function() {
  21. document.location.href = '';
  22. },
  23. okValue: '确定'
  24. });
  25. d.showModal();
  26. return $q.reject(rejection);
  27. } else if (rejection.status == 500) {
  28. var d = dialog({
  29. title: '错误提示',
  30. content: (rejection.data && rejection.data.errorMsg ? rejection.data.errorMsg : "操作失败,请与管理员联系。"),
  31. ok: function() {
  32. //donothing
  33. },
  34. okValue: '确定'
  35. });
  36. d.showModal();
  37. return $q.reject(rejection);
  38. } else {
  39. return $q.reject(rejection);
  40. }
  41. }
  42. };
  43. }).config(['$httpProvider', function($httpProvider) {
  44. $httpProvider.interceptors.push('frameAjaxInterceptor');
  45. $httpProvider.defaults.cache = false;
  46. if (!$httpProvider.defaults.headers.get) {
  47. $httpProvider.defaults.headers.get = {};
  48. }
  49. // disable IE ajax request caching
  50. $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
  51. }])
  52. .run(['$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) {
  53. $rootScope.$state = $state;
  54. $rootScope.$stateParams = $stateParams;
  55. }])