app.js 3.8 KB

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