123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 'use strict';
- angular.module('app', [ 'ngSanitize','ngStorage', 'oc.lazyLoad', 'ui.router' ]);
- var app = angular.module('app').config([ '$controllerProvider', '$compileProvider', '$filterProvider', '$provide', function($controllerProvider, $compileProvider, $filterProvider, $provide) {
- app.controller = $controllerProvider.register;
- app.directive = $compileProvider.directive;
- app.filter = $filterProvider.register;
- app.factory = $provide.factory;
- app.service = $provide.service;
- app.constant = $provide.constant;
- app.value = $provide.value;
- } ]);
- app.factory('frameAjaxInterceptor', function($rootScope, $q, $location) {
- return {
- 'request' : function(config) {
- // 判断是否弹出等待框
- var wait = config.wait || 0;
- if (wait > 0) {
- $.showLoading('业务提交中,请稍后...');
- }
- return config;
- },
- 'requestError' : function(rejection) {
- return $q.reject(rejection);
- },
- 'response' : function(response) {
- var wait = (response.config || {}).wait || 0;
- $.hideLoading();
- if (response.data.success == undefined)
- return response;
- if (response.data.success == false) {
- if (response.data.login == false) {
- $.alert("请退出重新进入公众号!", function() {
- WeixinJSBridge.call('closeWindow');
- });
- return;
- } else {
- if(response.data.errorMsg.indexOf('请在【我的->报考材料】') > -1) {
- $.alert(response.data.errorMsg, '提示');
- return response;
- } else {
- $.alert(response.data.errorMsg, '提示');
- }
- }
- return $q.reject(response);
- }
- return response;
- },
- 'responseError' : function(rejection) {
- var wait = (rejection.config || {}).wait || 0;
- if (wait > 0) {
- $.hideLoading();
- }
- // toaster.error('', "服务器发生内部错误,请联系系统管理员");
- return $q.reject(rejection);
- }
- };
- }).config([ '$httpProvider', function($httpProvider) {
- // 设置http默认信息
- $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
- $httpProvider.defaults.headers.post['Accept'] = 'application/json, text/javascript, */*; q=0.01';
- $httpProvider.defaults.headers.post['X-Requested-With'] = 'XMLHttpRequest';
- $httpProvider.defaults.transformRequest = [ function(data) {
- var param = function(obj) {
- var query = '';
- var name, value, fullSubName, subName, subValue, innerObj, i;
- for (name in obj) {
- value = obj[name];
- if (value instanceof Array) {
- for (i = 0; i < value.length; ++i) {
- subValue = $.trim(value[i]);
- fullSubName = name + '[]';
- innerObj = {};
- innerObj[fullSubName] = subValue;
- query += param(innerObj) + '&';
- }
- } else if (value instanceof Date) {
- query += encodeURIComponent(name) + '=' + encodeURIComponent($.trim(value.toJSON())) + '&';
- } else if (value instanceof Object) {
- for (subName in value) {
- subValue = $.trim(value[subName]);
- fullSubName = name + '[' + subName + ']';
- innerObj = {};
- innerObj[fullSubName] = subValue;
- query += param(innerObj) + '&';
- }
- } else if (value !== undefined && value !== null) {
- query += encodeURIComponent(name) + '=' + encodeURIComponent($.trim(value)) + '&';
- }
- }
- return query.length ? query.substr(0, query.length - 1) : query;
- };
- return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
- } ];
- $httpProvider.interceptors.push('frameAjaxInterceptor');
- } ]);
|