commons.js
19.6 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
angular.module("xn/template/dialog/confirm.html", []).run(["$templateCache", function($templateCache) {
"use strict";
$templateCache.put("xn/template/dialog/confirm.html",
"<div class=\"modal-header\">\n" +
" <h3>{{dialogOptions.headerText}}</h3>\n" +
" <div class=\"xn-close xn-cursor\" data-ng-click=\"dialogOptions.close()\">\n" +
" <i class=\"icon icon-delete\"></i>\n" +
" </div>\n" +
" </div>\n" +
" <div class=\"modal-body\" ng-if=\"dialogOptions.type!='delete'\">\n" +
" <p>{{dialogOptions.bodyText}}</p>\n" +
" </div>\n" +
" <div class=\"modal-body\" ng-if=\"dialogOptions.type=='delete'\">\n" +
" <div class=\"xn-exclamation\"><span>!</span></div>\n" +
" <div class=\"xn-body-text\">\n" +
" <h4>{{dialogOptions.bodyText}}</h4>\n" +
" <p></p>\n" +
" </div>\n" +
" </div>\n" +
"<div class=\"modal-footer\">\n" +
" <button type=\"button\"class=\"btn\"\n" +
" data-ng-click=\"dialogOptions.cancel()\">{{dialogOptions.closeButtonText}}\n" +
" </button>\n" +
" <button class=\"btn btn-danger\"\n" +
" data-ng-click=\"dialogOptions.callback();\">{{dialogOptions.actionButtonText}}\n" +
" </button>\n" +
" </div>");
}]);
angular.module("xn/template/dialog/info.html", []).run(["$templateCache", function($templateCache) {
"use strict";
$templateCache.put("xn/template/dialog/info.html",
"<div class=\"modal-header\">\n" +
" <h3>{{dialogOptions.headerText}}</h3>\n" +
" </div>\n" +
" <div class=\"modal-body\">\n" +
" <p>{{dialogOptions.bodyText}}</p>\n" +
" </div>\n" +
"<div class=\"modal-footer\">\n" +
" <button type=\"button\"class=\"btn\"\n" +
" data-ng-click=\"dialogOptions.close()\">{{dialogOptions.closeButtonText}}\n" +
" </button>\n" +
" </div>");
}]);
angular.module("xn/template/dialog/error.html", []).run(["$templateCache", function($templateCache) {
"use strict";
$templateCache.put("xn/template/dialog/error.html",
"<div class=\"modal-header\">\n" +
" <h3>{{dialogOptions.headerText}}</h3>\n" +
" </div>\n" +
" <div class=\"modal-body\">\n" +
" <p>{{dialogOptions.bodyText}}</p>\n" +
" </div>\n" +
"<div class=\"modal-footer\">\n" +
" <button type=\"button\"class=\"btn\"\n" +
" data-ng-click=\"dialogOptions.close()\">{{dialogOptions.closeButtonText}}\n" +
" </button>\n" +
" </div>");
}]);
angular.module("xn/template/dialog/warn.html", []).run(["$templateCache", function($templateCache) {
"use strict";
$templateCache.put("xn/template/dialog/warn.html",
"<div class=\"modal-header\">\n" +
" <h3>{{dialogOptions.headerText}}</h3>\n" +
" </div>\n" +
" <div class=\"modal-body\">\n" +
" <p>{{dialogOptions.bodyText}}</p>\n" +
" </div>\n" +
"<div class=\"modal-footer\">\n" +
" <button type=\"button\"class=\"btn\"\n" +
" data-ng-click=\"dialogOptions.close()\">{{dialogOptions.closeButtonText}}\n" +
" </button>\n" +
" </div>");
}]);
angular.module("xn/template/dialog/success.html", []).run(["$templateCache", function($templateCache) {
"use strict";
$templateCache.put("xn/template/dialog/success.html",
"<div class=\"modal-header\">\n" +
" <h3>{{dialogOptions.headerText}}</h3>\n" +
" </div>\n" +
" <div class=\"modal-body\">\n" +
" <p>{{dialogOptions.bodyText}}</p>\n" +
" </div>\n" +
"<div class=\"modal-footer\">\n" +
" <button type=\"button\"class=\"btn\"\n" +
" data-ng-click=\"dialogOptions.close()\">{{dialogOptions.closeButtonText}}\n" +
" </button>\n" +
" </div>");
}]);
angular.module("xn.service.tpl", [
"xn/template/dialog/confirm.html",
"xn/template/dialog/info.html",
"xn/template/dialog/error.html",
"xn/template/dialog/warn.html",
"xn/template/dialog/success.html"
]);
angular.module("xn.service.common", ["xn.service.tpl", "ui.bootstrap"])
.service("toolsService",[function () {
"use strict";
/**
* 获取网址上的参数
* @param name 网址上的参数.例如(id)
* @param url 网址连接。
* @returns {*} 返回网址参数的值
*/
this.parameter = function (name, url) {
var parameterString = null;
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
parameterString = url.substr(url.indexOf("?"), url.length);//获取截取?以后的字符串
var r = parameterString.substr(1).match(reg);
if (r != null){
return unescape(r[2]);
}
return null;
};
}
])
.service("dialogService",["$modal","$timeout","$document","$http",
function ($modal,$timeout,$document,$http) {
"use strict";
this.confirm = function (customDialogDefaults, customDialogOptions) {
var dialogDefaults = {
backdrop: true,
keyboard: true,
backdropClick: true,
dialogFade: true,
templateUrl: "xn/template/dialog/confirm.html",
size:"sm"
};
var dialogOptions = {
closeButtonText: "关闭",
actionButtonText: "确定",
headerText: "继续...?",
bodyText: "执行这个操作?"
};
//Create temp objects to work with since we're in a singleton service
var tempDialogDefaults = {};
var tempDialogOptions = {};
//Map angular-ui dialog custom defaults to dialog defaults defined in this service
angular.extend(tempDialogDefaults, dialogDefaults, customDialogDefaults);
//Map dialog.html $scope custom properties to defaults defined in this service
angular.extend(tempDialogOptions, dialogOptions, customDialogOptions);
if (!tempDialogDefaults.controller) {
tempDialogDefaults.controller =["$scope","$modalInstance", function ($scope, $modalInstance) {
$scope.dialogOptions = tempDialogOptions;
$scope.dialogOptions.close = function (result) {
$modalInstance.close(result);
};
$scope.dialogOptions.cancel = function () {
$modalInstance.close();
if(customDialogOptions.cancel){
customDialogOptions.cancel();
}
};
$scope.dialogOptions.callback = function () {
$modalInstance.close();
customDialogOptions.callback();
};
}];
}
$modal.open(tempDialogDefaults);
};
this.info=function(message){
var dialogOptions = {
closeButtonText: "关闭",
headerText: "提示信息",
bodyText: message
};
$modal.open({
backdrop: true,
keyboard: true,
backdropClick: true,
dialogFade: true,
size:"sm",
templateUrl: "xn/template/dialog/info.html",
controller:["$scope","$modalInstance", function ($scope, $modalInstance) {
$scope.dialogOptions=dialogOptions;
$scope.dialogOptions.close = function () {
$modalInstance.close();
};
}]
});
};
this.success=function(message){
var dialogOptions = {
closeButtonText: "关闭",
headerText: "成功信息",
bodyText: message
};
$modal.open({
backdrop: true,
keyboard: true,
backdropClick: true,
dialogFade: true,
size:"sm",
templateUrl: "xn/template/dialog/success.html",
controller:["$scope","$modalInstance",function ($scope, $modalInstance) {
$scope.dialogOptions=dialogOptions;
$scope.dialogOptions.close = function () {
$modalInstance.close();
};
}]
});
};
this.error=function(message){
var dialogOptions = {
closeButtonText: "关闭",
headerText: "错误信息",
bodyText: message
};
$modal.open({
backdrop: true,
keyboard: true,
backdropClick: true,
dialogFade: true,
size:"sm",
templateUrl: "xn/template/dialog/error.html",
controller:["$scope","$modalInstance", function ($scope, $modalInstance) {
$scope.dialogOptions=dialogOptions;
$scope.dialogOptions.close = function () {
$modalInstance.close();
};
}]
});
};
this.warn=function(message){
var dialogOptions = {
closeButtonText: "关闭",
headerText:"警告信息",
bodyText: message
};
$modal.open({
backdrop: true,
keyboard: true,
backdropClick: true,
dialogFade: true,
size:"sm",
templateUrl: "xn/template/dialog/warn.html",
controller:["$scope","$modalInstance", function ($scope, $modalInstance) {
$scope.dialogOptions=dialogOptions;
$scope.dialogOptions.close = function () {
$modalInstance.close();
};
}]
});
};
this.tip=function(message, modalUrl,time){
var dialogDefaults = {
headerText:"信息提示",
bodyText:message,
show:"show",
size:"sm",
top:"30%",
removeTime:1000,
stopTime:3000,
autoClose:false
};
var tipbox="";
var errorDump="";
if(time != 0 && time){
dialogDefaults.stopTime = time;
}else if(time===0){
dialogDefaults.autoClose=true;
}
var modalId="modal"+new Date().getTime();
if(dialogDefaults.bodyText.length==1){
if(dialogDefaults.bodyText[0].type!="STACK_DUMP"){
tipbox += "<p>"+dialogDefaults.bodyText[0].message+"</p>\n";
}else{
errorDump += dialogDefaults.bodyText[0].message;
}
}else {
for( var i=0;i < dialogDefaults.bodyText.length;i++ ){
if(dialogDefaults.bodyText[i].type!="STACK_DUMP"){
tipbox += "<p><span>"+(i+1)+".</span>"+dialogDefaults.bodyText[i].message+"</p>\n";
}else{
errorDump += dialogDefaults.bodyText[i].message;
}
}
}
var closeDom="";
if(dialogDefaults.autoClose){
closeDom= "<button type=\"button\" class=\"btn btn-link btn-tip-close\" style='margin-left: 10px;display: inline-block;float: right'\">" +
"关闭" +
" </button>";
}
if(errorDump!=""){
errorDump = escape(errorDump);
tipbox +="<form action='/api/errorHandler.do' method='post' target='_blank'>" +
"<div class=\"modal-foot xn-text-right xn-padding-bottom xn-padding-right\">" +
"<input type='submit' value='更多' class='btn btn-link' />" +
"<input type='hidden' name='error' value='" + errorDump + "' />" +
"</div></form>" ;
}else {
tipbox +="<div class=\"modal-foot xn-text-right xn-padding-bottom xn-padding-right\"></div>";
}
var tip="<div id='"+modalId+"' class=\"modal ng-isolate-scope xn-modal xn-modal-sm\" >\n"+
"<div class=\"modal-content \">\n"+
"<div class=\"modal-header\">\n"+closeDom+
" <h3>"+dialogDefaults.headerText+"</h3>\n" +
" </div>\n" +
"<div class=\"modal-body\">\n" +
tipbox+
"</div>"+
"</div>" +
"</div>";
//消息明细获取
var body = $document.find("body").eq(0);
body.append(tip);
body.find("#"+modalId).css({ top: dialogDefaults.top,opacity:dialogDefaults.show });
body.find("#"+modalId).fadeIn(dialogDefaults.show);
var remove=function(){
body.find("#"+modalId).remove();
if( !(modalUrl==undefined || modalUrl==null)){
window.location = modalUrl;
}
};
var closeModal=function(){
body.find("#"+modalId).animate({ "top": "0", "opacity":"hide"},dialogDefaults.removeTime);
$timeout(remove ,dialogDefaults.removeTime);
};
if(!dialogDefaults.autoClose){
(function timeout (){
$timeout(closeModal,dialogDefaults.stopTime);
})();
}else {
$("#"+modalId).on("click",".btn-tip-close",function(){
closeModal();
})
}
};
}
])
.factory('permissionService',["$rootScope", function ($rootScope) {
var permissionList;
return {
setPermissions: function(permissions) {
console.log("XN:permissionService ,设置权限列表集合"+permissions)
permissionList = permissions;
$rootScope.$broadcast('permissionsChanged')
},
hasPermission: function (permission) {
console.log("XN:权限项判断, value="+permission);
console.log("XN:权限项判断, permissionList="+permissionList);
permission = permission.trim().toLowerCase();
return _.some(permissionList, function(item) {
console.log("遍历项="+item);
if(_.isString(item))
return item.trim().toLowerCase() === permission
});
}
};
}]);
var httpInterceptor= function($q,$injector,$location,XN_BEGIN_REQUEST,XN_END_REQUEST){
"use strict";
var $http, rootScope;
var interceptor={
request:function(config){
/* console.log("XN:提交请求的成功,信息如下:");
console.log(config);*/
config.requestTimestamp = new Date().getTime();
// get $rootScope via $injector because of circular dependency problem
rootScope = rootScope || $injector.get('$rootScope');
// send notification a request has started
rootScope.$broadcast(XN_BEGIN_REQUEST);
return config;
},
response:function(response){
/* console.log("XN:服务器响应成功,信息如下:");*/
/* console.log(response);*/
/* console.log(response.data);*/
response.config.responseTimestamp = new Date().getTime();
var time = response.config.responseTimestamp - response.config.requestTimestamp;
console.log('请求共花费了: ' + (time / 1000) + '秒.');
// get $http via $injector because of circular dependency problem
$http = $http || $injector.get('$http');
// don't send notification until all requests are complete
if ($http.pendingRequests.length < 1) {
// get $rootScope via $injector because of circular dependency problem
rootScope = rootScope || $injector.get('$rootScope');
// send a notification requests are complete
rootScope.$broadcast(XN_END_REQUEST);
}
return response ;
},
requestError:function(rejection){
/* console.log("XN:提交服务器请求失败,信息如下:");
console.log(rejection);*/
return $q.reject(rejection);
},
responseError:function(rejection){
/* console.log("XN:服务器响应失败,信息如下:");
console.log(rejection);*/
// get $http via $injector because of circular dependency problem
$http = $http || $injector.get('$http');
// don't send notification until all requests are complete
if ($http.pendingRequests.length < 1) {
// get $rootScope via $injector because of circular dependency problem
rootScope = rootScope || $injector.get('$rootScope');
// send a notification requests are complete
rootScope.$broadcast(XN_END_REQUEST);
}
switch (rejection.status)
{
case 401:
console.error("XN:服务器返回401错误");
break;
case 403:
console.error("XN:服务器返回403错误");
break;
case 404:
console.error("XN:服务器返回404错误");
break;
case 500:
console.error("XN:服务器返回500错误");
break;
default :
console.error("XN:服务器返回错误");
break;
}
return $q.reject(rejection);
}
};
return interceptor;
};
angular.module("xn.service.interceptor", ["xn.service.common"])
.constant('XN_BEGIN_REQUEST', 'XN_BEGIN_REQUEST')
.constant('XN_END_REQUEST', 'XN_END_REQUEST')
.factory("httpInterceptor",["$q","$injector","$location","XN_BEGIN_REQUEST","XN_END_REQUEST"
,httpInterceptor]);