yinxia.yang пре 1 дан
родитељ
комит
a2de16921d
2 измењених фајлова са 28 додато и 4 уклоњено
  1. 20 4
      src/App.vue
  2. 8 0
      src/utils/auth.ts

+ 20 - 4
src/App.vue

@@ -1,13 +1,29 @@
 <script setup lang="ts">
-	import { useRoute, useRouter } from 'vue-router'
+	import { useRoute } from 'vue-router'
 	import { useWarehouse } from './store'
-	import { clearAuthInfo, clearOAuthTemp, getDisplayName } from './utils/auth'
+	import { clearAuthInfo, clearOAuthTemp, getDisplayName, getOAuthLogoutUrl, mockLogin } from './utils/auth'
 	import { House, Collection, Box, Download, Upload, Notebook, SwitchButton } from '@element-plus/icons-vue'
     const faviconUrl = '/favicon.ico'
-	const route = useRoute(); const router = useRouter()
+	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() { clearAuthInfo(); clearOAuthTemp(); sessionStorage.setItem('warehouse-auth-paused', '1'); router.push('/login') }
+	function logout() {
+		// 先清空本地所有缓存
+		sessionStorage.clear()
+		clearAuthInfo()
+		clearOAuthTemp()
+		// Mock 模式直接跳登录页;否则跳转到 OIDC 服务端登出,销毁 SSO 会话
+		if (mockLogin) {
+			location.hash = '#/login'
+		} else {
+			try {
+				location.replace(getOAuthLogoutUrl())
+			} catch {
+				// 配置异常时回退到 forward.html
+				location.replace('/forward.html')
+			}
+		}
+	}
 	const user = getDisplayName
 	const now = new Date()
 	const dateStr = new Intl.DateTimeFormat('zh-CN', { year: 'numeric', month: 'long', day: 'numeric' }).format(now)

+ 8 - 0
src/utils/auth.ts

@@ -149,4 +149,12 @@ export function consumeOAuthTransaction(state : string | null) {
 /** 清除 PKCE 临时会话,用于认证失败、退出登录或登录失效后的清理。 */
 export function clearOAuthTemp() {
 	useStore().CLEAR_OAUTH_TEMP()
+}
+
+/** 生成 OIDC 登出链接,跳转到认证服务器登出后再回到应用。 */
+export function getOAuthLogoutUrl() {
+	const config = getOAuthConfig()
+	const baseURL = config.authorizeURL.replace(/\/oauth2\/authorize$/, '')
+	const postLogoutRedirectUri = getOAuthRedirectUri()
+	return `${baseURL}/logout?post_logout_redirect_uri=${encodeURIComponent(postLogoutRedirectUri)}`
 }