config.js
4.46 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
(function(angular) {
/* global angular */
function config($provide, $urlRouterProvider, $ocLazyLoadProvider, $uibModalProvider, $httpProvider, localStorageServiceProvider, routeConfigProvider) {
// reset $uibmoal windowTemplateUrl (提升z-index)
$uibModalProvider.options.windowTemplateUrl = 'js/bootstrap/uibmodal-window.html';
// 禁用弹窗遮罩,改成自定义的 class 类 modal 实现
$uibModalProvider.options.backdrop = false;
// $ocLazyLoad.load 方法扩展
$provide.decorator('$ocLazyLoad', ['$delegate', function($delegate) {
$delegate.loadEx = function() {
var args = Array.prototype.slice.call(arguments);
var result = [];
if (args.length > 1 && args[0] instanceof Array) {
args = [args.reduce(function(a, b) {
return a.concat(b);
}, [])];
}
angular.copy(args, result);
return Function.prototype.apply.call(this.load, this, result);
};
return $delegate;
}]);
$ocLazyLoadProvider.config({
// Set to true if you want to see what and when is dynamically loaded
debug: false
});
// PLUGINS 插件定义在constant.js中
// 配置路由
$urlRouterProvider.otherwise("/home/index");
// no-cache for ie
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
// Enables Request.IsAjaxRequest() in ASP.NET MVC
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
//禁用IE对ajax的缓存
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$httpProvider.interceptors.push(function($q) {
return {
// 'responseError': function(rejection) {
// if(rejection.data === null){
// window.location.href = 'logout';
// }
//
// return $q.reject(rejection);
// },
'request': function(request){
if(routeConfigProvider.dataDesensitization){
request.headers['Data-Desensitization'] = 'on';
}
request.headers['Authorization'] = window.sessionStorage.getItem('Authorization');
return request || $q.when(request);
},
'response': function(response) {
var data = response.data || {};
var deferred = $q.defer();
var headers = response.headers();
if (data.error == "登录用户为空") {
deferred.reject(response);
var origin = window.location.origin;
var path = origin + "/#/login/login";
window.location = path;
} else if (headers.sessionstatus == 'timeout') {
window.location.href = 'login';
} else if (data.errId == "401") {
window.location.href = 'login';
} else {
deferred.resolve(response);
}
return deferred.promise;
}
};
});
localStorageServiceProvider
.setPrefix('inspinia')
.setStorageType('sessionStorage')
.setDefaultToCookie(false)
.setNotify(true, true);
}
function getParent(obj, name) {
var str = name
str.unshift(obj.name)
if (obj.parentObj) {
getParent(obj.parentObj, str)
return str
} else {
return str
}
}
angular
.module('inspinia')
.config(config)
.run(function($rootScope, $state, localStorageService) {
$('head').append('<meta name="renderer" content="webkit" />')
$rootScope.$state = $state;
$rootScope.$on('$stateChangeStart', function(event, toState, toParams) {
$rootScope.isHome = toState.name == 'home.index' ? true : false
var routerList = $rootScope.curUserMenuList
var title = toState.data.pageTitle
angular.forEach(routerList, function(e) {
if (e.name == title) {
$rootScope.breadcrumb = getParent(e, [])
}
})
})
window.onbeforeunload = function(e) {
if (localStorageService.get('isLogout')) {
localStorageService.set('currentState', null)
localStorageService.set('isLogout', false)
} else {
localStorageService.set('currentState', angular.toJson({
current: $state.current,
params: $state.params
}));
}
//return '网站重新加载';
}
});
})(angular);