Просмотр исходного кода

关于退出登录页面闪烁的问题处理

hejq 8 лет назад
Родитель
Сommit
4f6a98446f

+ 19 - 24
src/main/java/com/uas/platform/b2b/controller/SecurityController.java

@@ -1,29 +1,5 @@
 package com.uas.platform.b2b.controller;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.mobile.device.Device;
-import org.springframework.mobile.device.DeviceResolver;
-import org.springframework.mobile.device.LiteDeviceResolver;
-import org.springframework.mobile.device.site.SitePreference;
-import org.springframework.security.core.userdetails.UsernameNotFoundException;
-import org.springframework.ui.ModelMap;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.ResponseStatus;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.uas.platform.b2b.model.Enterprise;
 import com.uas.platform.b2b.model.SigninLog;
 import com.uas.platform.b2b.model.User;
@@ -37,6 +13,24 @@ import com.uas.sso.AuthToken;
 import com.uas.sso.SSOConfig;
 import com.uas.sso.SSOHelper;
 import com.uas.sso.SSOToken;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.mobile.device.Device;
+import org.springframework.mobile.device.DeviceResolver;
+import org.springframework.mobile.device.LiteDeviceResolver;
+import org.springframework.mobile.device.site.SitePreference;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.ui.ModelMap;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 @SuppressWarnings("deprecation")
 @RestController
@@ -54,6 +48,7 @@ public class SecurityController {
 	@ResponseStatus(value = HttpStatus.OK)
 	@ResponseBody
 	public ModelMap logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException {
+		response.setContentType("text/html;charset=UTF-8");
 		session.invalidate();
 		SSOHelper.clearLogin(request, response);
 		SystemSession.clear();

+ 1 - 2
src/main/webapp/WEB-INF/spring/webmvc.xml

@@ -67,8 +67,7 @@
 	<mvc:view-controller path="/public/app" view-name="client" />
 	<mvc:view-controller path="/authen" view-name="authen" />
 	<mvc:view-controller path="/login/proxy" view-name="proxyLogin" />
-	<mvc:view-controller path="/logout/proxy"
-		view-name="proxyLogout" />
+	<mvc:view-controller path="/logout/proxy" view-name="proxyLogout" />
 	<mvc:interceptors>
 		<mvc:interceptor>
 			<mvc:mapping path="/**"></mvc:mapping>

+ 1 - 1
src/main/webapp/WEB-INF/views/normal/proxyLogout.html

@@ -17,7 +17,7 @@
 				// 跳转登出页面
 				window.location.href = logoutUrl;
 			} else {
-				window.location.href = retUrl;
+                window.location.href = retUrl && retUrl !== 'null' ? retUrl : '/';
 			}
 	    });
 	}

+ 24 - 6
src/main/webapp/resources/js/common/services.js

@@ -117,19 +117,37 @@ define(['angular', 'toaster', 'big'], function(angular, big) {
                 return rootPath;
             },
             logout: function() {
-            	var config = {
+                var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
+                if(keys) {
+                    for(var i = keys.length; i--;)
+                        document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
+                }
+                var config = {
 					cache: false,
 					headers: {
         				'Cache-Control': 'no-cache',
-        				'Pragma': 'no-cache'
-					}
+        				'Pragma': 'no-cache',
+					},
+                    ifModified :true ,
 				};
 				var logout = $http.get(rootPath + "/logout", config);
 				logout.success(uncacheSession);
 				logout.success(function(data){
-					if (data.content) {
-						window.location.href = data.content;
-					}
+                    var pathName = document.location.pathname;
+                    var index = pathName.substr(1).indexOf("/");// platform-b2c/logout/proxy
+                    var result = pathName.substr(0,index);
+                    var uri = pathName.substr(13,index+1000) + document.location.hash;
+                    if (result == '/platform-b2b') {
+                        var contextPath = ''
+                        data.content = contextPath + uri;
+                    }
+                    if (data.content) {
+                        if (data.content == window.location.href) {
+                            // window.location.reload();
+                        } else {
+                            window.location.href = data.content;
+                        }
+                    }
 				});
 				return logout;
             },

+ 3 - 1
src/main/webapp/resources/js/index/app.js

@@ -12,7 +12,9 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         var httpInterceptor = {
             'responseError': function (response) {
                 if (response.status == 401) {// UNAUTHORIZED
-                    window.location.href = response.data.loginUrl || 'index';
+                    // window.location.href = response.data.loginUrl || 'index';
+                    // window.location.href = window.location.origin + window.location.pathname + '/login';
+                    window.location.reload();
                     return $q.reject(response);
                 }
                 return $q.reject(response);

+ 3 - 2
src/main/webapp/resources/tpl/error/index.html

@@ -6,8 +6,9 @@
 </head>
 <body>
 <script type="text/javascript">
-    //去除掉undefined
-    window.location.href=window.location.href.replace('/undefined', '#/index');
+    //返回上一页
+//    window.location.href="http://uas.ubtob.com/#/index";
+    window.history.go(-1);
 </script>
 </body>
 </html>