yinxia.yang 1 月之前
父节点
当前提交
901fe9e31f
共有 2 个文件被更改,包括 12 次插入 和 7 次删除
  1. 9 4
      src/App.vue
  2. 3 3
      src/utils/auth.ts

+ 9 - 4
src/App.vue

@@ -1,19 +1,24 @@
 <script setup lang="ts">
 	import { useRoute } from 'vue-router'
 	import { useWarehouse } from './store'
-	import { clearAuthInfo, clearOAuthTemp, getDisplayName } from './utils/auth'
+	import { clearAuthInfo, clearOAuthTemp, getDisplayName, getOAuthLogoutUrl } from './utils/auth'
 	import { House, Collection, Box, Download, Upload, Notebook, SwitchButton } from '@element-plus/icons-vue'
     const faviconUrl = '/favicon.ico'
 	const route = useRoute()
 	const warehouse = useWarehouse()
 	const links = [{ path: '/dashboard', name: '工作台', icon: House }, { path: '/master', name: '基础资料管理', icon: Collection }, { path: '/sku', name: '商品 / SKU 管理', icon: Box }, { path: '/inbound', name: '入库管理', icon: Download }, { path: '/outbound', name: '出库管理', icon: Upload }, { path: '/ledger', name: '库存台账', icon: Notebook }]
 	function logout() {
-		// 清空本地所有缓存
+		// 先清空本地所有缓存
 		sessionStorage.clear()
 		clearAuthInfo()
 		clearOAuthTemp()
-		// 跳转到登录页
-		location.replace('/#/login')
+		// 跳转到 OIDC 服务端登出,销毁 SSO 会话,登出后回到 index.html
+		try {
+			location.replace(getOAuthLogoutUrl())
+		} catch {
+			// 配置异常时回退到登录页
+			location.replace('/#/login')
+		}
 	}
 	const user = getDisplayName
 	const now = new Date()

+ 3 - 3
src/utils/auth.ts

@@ -151,11 +151,11 @@ export function clearOAuthTemp() {
 	useStore().CLEAR_OAUTH_TEMP()
 }
 
-/** 生成 OIDC 登出链接,跳转到认证服务器登出后再回到登录页。 */
+/** 生成 OIDC 登出链接,跳转到认证服务器登出后再回到 index.html 页面。 */
 export function getOAuthLogoutUrl() {
 	const config = getOAuthConfig()
 	const baseURL = config.authorizeURL.replace(/\/oauth2\/authorize$/, '')
-	// 登出后回到应用根路径,由路由守卫自动跳转到登录页
-	const postLogoutRedirectUri = location.origin + '/'
+	// 登出后回到 index.html,由路由守卫自动跳转到登录页
+	const postLogoutRedirectUri = location.origin + '/index.html'
 	return `${baseURL}/logout?post_logout_redirect_uri=${encodeURIComponent(postLogoutRedirectUri)}`
 }