123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 'use strict';
- var app = angular.module('app', [ 'ui.router', 'ngFileUpload', 'toaster', 'ngAnimate', 'cgBusy' ])
- //集成underscore.js
- .constant('_', window._)
- .run(
- ['$rootScope', '$state', '$stateParams',
- function ($rootScope, $state,$stateParams) {
- $rootScope.$state = $state;
- $rootScope.$stateParams = $stateParams;
- $rootScope.favors = [];
- $rootScope._ = window._;
- }
- ]
- );
- app.factory('frameAjaxInterceptor', function($rootScope, $q, $location) {
-
- return {
- 'request' : function(config,data,value) {
- return config;
- },
- 'requestError' : function(rejection) {
- return $q.reject(rejection);
- },
- 'response' : function(response) {
- if (response.data.success == undefined)
- return response;
- if (response.data.success == false) {
- var d = dialog({
- title : '错误提示',
- content : response.data.errorMsg,
- ok : function() {
- if(response.data.login==false){
- window.location = 'index.html';
- }
- },
- okValue : '确定',
- width : 350
- });
- d.showModal();
- return $q.reject(response);
- }
- return response;
- },
- 'responseError' : function(rejection) {
- var d = dialog({
- title : '请求错误',
- content : '服务器发生内部错误,请联系系统管理员',
- ok : function() {
- },
- okValue : '确定',
- width : 350
- });
- d.showModal();
- 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) + '&';
- }
- // console.log(query);
- } 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)) + '&';
- }
- }
- // console.log(query);
- return query.length ? query.substr(0, query.length - 1) : query;
- };
- return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
- // return $.param(data);
- } ];
- $httpProvider.interceptors.push('frameAjaxInterceptor');
- } ]);
- $(function(){
- var overwrite = $.fn.bootstrapValidator;
- $.fn.bootstrapValidator = function(options){
- $.fn.bootstrapValidator = overwrite;
- options.message='验证失败,请检查';
- options.feedbackIcons= {
- valid: 'glyphicon glyphicon-ok',
- invalid: 'glyphicon glyphicon-remove',
- validating: 'glyphicon glyphicon-refresh'
- };
- var validtor = overwrite.apply(this,arguments);
- return validtor;
- }
- })
|