angular.init.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. 'use strict';
  2. angular.module('app', [ 'ngSanitize','ngStorage', 'oc.lazyLoad', 'ui.router' ]);
  3. var app = angular.module('app').config([ '$controllerProvider', '$compileProvider', '$filterProvider', '$provide', function($controllerProvider, $compileProvider, $filterProvider, $provide) {
  4. app.controller = $controllerProvider.register;
  5. app.directive = $compileProvider.directive;
  6. app.filter = $filterProvider.register;
  7. app.factory = $provide.factory;
  8. app.service = $provide.service;
  9. app.constant = $provide.constant;
  10. app.value = $provide.value;
  11. } ]);
  12. app.factory('frameAjaxInterceptor', function($rootScope, $q, $location) {
  13. return {
  14. 'request' : function(config) {
  15. // 判断是否弹出等待框
  16. var wait = config.wait || 0;
  17. if (wait > 0) {
  18. $.showLoading('业务提交中,请稍后...');
  19. }
  20. return config;
  21. },
  22. 'requestError' : function(rejection) {
  23. return $q.reject(rejection);
  24. },
  25. 'response' : function(response) {
  26. var wait = (response.config || {}).wait || 0;
  27. $.hideLoading();
  28. if (response.data.success == undefined)
  29. return response;
  30. if (response.data.success == false) {
  31. if (response.data.login == false) {
  32. $.alert("请退出重新进入公众号!", function() {
  33. WeixinJSBridge.call('closeWindow');
  34. });
  35. return;
  36. } else {
  37. if(response.data.errorMsg.indexOf('请在【我的->报考材料】') > -1) {
  38. $.alert(response.data.errorMsg, '提示');
  39. return response;
  40. } else {
  41. $.alert(response.data.errorMsg, '提示');
  42. }
  43. }
  44. return $q.reject(response);
  45. }
  46. return response;
  47. },
  48. 'responseError' : function(rejection) {
  49. var wait = (rejection.config || {}).wait || 0;
  50. if (wait > 0) {
  51. $.hideLoading();
  52. }
  53. // toaster.error('', "服务器发生内部错误,请联系系统管理员");
  54. return $q.reject(rejection);
  55. }
  56. };
  57. }).config([ '$httpProvider', function($httpProvider) {
  58. // 设置http默认信息
  59. $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
  60. $httpProvider.defaults.headers.post['Accept'] = 'application/json, text/javascript, */*; q=0.01';
  61. $httpProvider.defaults.headers.post['X-Requested-With'] = 'XMLHttpRequest';
  62. $httpProvider.defaults.transformRequest = [ function(data) {
  63. var param = function(obj) {
  64. var query = '';
  65. var name, value, fullSubName, subName, subValue, innerObj, i;
  66. for (name in obj) {
  67. value = obj[name];
  68. if (value instanceof Array) {
  69. for (i = 0; i < value.length; ++i) {
  70. subValue = $.trim(value[i]);
  71. fullSubName = name + '[]';
  72. innerObj = {};
  73. innerObj[fullSubName] = subValue;
  74. query += param(innerObj) + '&';
  75. }
  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. return query.length ? query.substr(0, query.length - 1) : query;
  91. };
  92. return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
  93. } ];
  94. $httpProvider.interceptors.push('frameAjaxInterceptor');
  95. } ]);