app.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. 'use strict';
  2. var app = angular.module('app', [ 'ui.router', 'ngFileUpload', 'toaster', 'ngAnimate', 'cgBusy' ])
  3. //集成underscore.js
  4. .constant('_', window._)
  5. .run(
  6. ['$rootScope', '$state', '$stateParams',
  7. function ($rootScope, $state,$stateParams) {
  8. $rootScope.$state = $state;
  9. $rootScope.$stateParams = $stateParams;
  10. $rootScope.favors = [];
  11. $rootScope._ = window._;
  12. }
  13. ]
  14. );
  15. app.factory('frameAjaxInterceptor', function($rootScope, $q, $location) {
  16. return {
  17. 'request' : function(config,data,value) {
  18. return config;
  19. },
  20. 'requestError' : function(rejection) {
  21. return $q.reject(rejection);
  22. },
  23. 'response' : function(response) {
  24. if (response.data.success == undefined)
  25. return response;
  26. if (response.data.success == false) {
  27. var d = dialog({
  28. title : '错误提示',
  29. content : response.data.errorMsg,
  30. ok : function() {
  31. if(response.data.login==false){
  32. window.location = 'index.html';
  33. }
  34. },
  35. okValue : '确定',
  36. width : 350
  37. });
  38. d.showModal();
  39. return $q.reject(response);
  40. }
  41. return response;
  42. },
  43. 'responseError' : function(rejection) {
  44. var d = dialog({
  45. title : '请求错误',
  46. content : '服务器发生内部错误,请联系系统管理员',
  47. ok : function() {
  48. },
  49. okValue : '确定',
  50. width : 350
  51. });
  52. d.showModal();
  53. return $q.reject(rejection);
  54. }
  55. };
  56. }).config([ '$httpProvider', function($httpProvider) {
  57. // 设置http默认信息
  58. $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
  59. $httpProvider.defaults.headers.post['Accept'] = 'application/json, text/javascript, */*; q=0.01';
  60. $httpProvider.defaults.headers.post['X-Requested-With'] = 'XMLHttpRequest';
  61. $httpProvider.defaults.transformRequest = [ function(data) {
  62. var param = function(obj) {
  63. var query = '';
  64. var name, value, fullSubName, subName, subValue, innerObj, i;
  65. for (name in obj) {
  66. value = obj[name];
  67. if (value instanceof Array) {
  68. for (i = 0; i < value.length; ++i) {
  69. subValue = $.trim(value[i]);
  70. fullSubName = name + '[]';
  71. innerObj = {};
  72. innerObj[fullSubName] = subValue;
  73. query += param(innerObj) + '&';
  74. }
  75. // console.log(query);
  76. } else if (value instanceof Date) {
  77. query += encodeURIComponent(name) + '=' + encodeURIComponent($.trim(value.toJSON())) + '&';
  78. } else if (value instanceof Object) {
  79. for (subName in value) {
  80. subValue = $.trim(value[subName]);
  81. fullSubName = name + '[' + subName + ']';
  82. innerObj = {};
  83. innerObj[fullSubName] = subValue;
  84. query += param(innerObj) + '&';
  85. }
  86. } else if (value !== undefined && value !== null) {
  87. query += encodeURIComponent(name) + '=' + encodeURIComponent($.trim(value)) + '&';
  88. }
  89. }
  90. // console.log(query);
  91. return query.length ? query.substr(0, query.length - 1) : query;
  92. };
  93. return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
  94. // return $.param(data);
  95. } ];
  96. $httpProvider.interceptors.push('frameAjaxInterceptor');
  97. } ]);
  98. $(function(){
  99.   var overwrite = $.fn.bootstrapValidator;
  100.   $.fn.bootstrapValidator = function(options){
  101.     $.fn.bootstrapValidator = overwrite;
  102. options.message='验证失败,请检查';
  103.   options.feedbackIcons= {
  104.         valid: 'glyphicon glyphicon-ok',
  105.         invalid: 'glyphicon glyphicon-remove',
  106.         validating: 'glyphicon glyphicon-refresh'
  107.          };
  108.     var validtor = overwrite.apply(this,arguments);
  109.     return validtor;
  110.   }
  111. })