Browse Source

修复自动实现loading效果的Bug

suntg 7 years ago
parent
commit
a75d4db814
1 changed files with 30 additions and 36 deletions
  1. 30 36
      src/main/webapp/resources/js/common/controllers/commonCtrls.js

+ 30 - 36
src/main/webapp/resources/js/common/controllers/commonCtrls.js

@@ -16,42 +16,36 @@ define([ 'app/app' ], function(app) {
 			if(--i < 1) Loading.hide();
 			if(--i < 1) Loading.hide();
 		};
 		};
 
 
-		var url = arguments[0].url;
-		return {
-			request: function(cfg){
-				if(cfg.url) {
-					if(cfg.url.indexOf('api/chat/message') < 0) {
-						startLoading();
-					}
-				}
-				return cfg;
-			},
-			requestError: function(rejection) {
-				if(url && url.indexOf('api/chat/message') < 0) {
-					endLoading();
-				}
-				// endLoading();
-				return $q.reject(rejection);
-			},
-			response: function(res) {
-				if(res.config.url) {
-					if(res.config.url.indexOf('api/chat/message') < 0) {
-						endLoading();
-					}
-				}
-				return res;
-			},
-			responseError: function(rejection) {
-				if(url && url.indexOf('api/chat/message') < 0) {
-					endLoading();
-				}
-				// endLoading();
-				if(rejection.status == 401) {
-					window.location.href = rejection.data.loginUrl || 'index';
-				}
-				return $q.reject(rejection);
-			}
-		}
+        var im_api_url = 'api/chat/message';
+        return {
+            request: function(cfg){
+                if(cfg.url && cfg.url.indexOf(im_api_url) < 0) {
+                    startLoading();
+                }
+                return cfg;
+            },
+            requestError: function(rejection) {
+                if(rejection.config.url && rejection.config.url.indexOf(im_api_url) < 0) {
+                    endLoading();
+                }
+                return $q.reject(rejection);
+            },
+            response: function(res) {
+                if(res.config.url && res.config.url.indexOf(im_api_url) < 0) {
+                    endLoading();
+                }
+                return res;
+            },
+            responseError: function(rejection) {
+                if(rejection.config.url && rejection.config.url.indexOf(im_api_url) < 0) {
+                    endLoading();
+                }
+                if(rejection.status == 401) {
+                    window.location.href = rejection.data.loginUrl || 'index';
+                }
+                return $q.reject(rejection);
+            }
+        }
 	}]);
 	}]);
 
 
 	// 修改页面标题
 	// 修改页面标题