浏览代码

Update:更新readme

XieXing 3 月之前
父节点
当前提交
0131886a08
共有 2 个文件被更改,包括 24 次插入9 次删除
  1. 7 0
      shudao-vue-frontend/index.html
  2. 17 9
      shudao-vue-frontend/src/utils/ticketAuth.js

+ 7 - 0
shudao-vue-frontend/index.html

@@ -6,6 +6,13 @@
     <link rel="icon" href="/favicon.ico">
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
     <title>蜀道安全管理AI智能助手</title>
+    <!-- 在任何JS模块加载之前保存原始URL(用于票据认证) -->
+    <script>
+        window.__ORIGINAL_URL__ = window.location.href;
+        window.__ORIGINAL_SEARCH__ = window.location.search;
+        window.__ORIGINAL_HASH__ = window.location.hash;
+        console.log('🔒 [index.html] 已保存原始URL:', window.__ORIGINAL_URL__);
+    </script>
 </head>
 
 <body>

+ 17 - 9
shudao-vue-frontend/src/utils/ticketAuth.js

@@ -12,20 +12,28 @@ const useDefaultTicket = isLocal || isTest
 const TICKET_GET_API = `${AUTH_GATEWAY_URL}/ticket/get`
 const TICKET_PROCESS_API = `${AUTH_GATEWAY_URL}/ticket/process`
 
-// ===== 关键修复:在模块加载时立即保存原始 URL =====
-// 防止其他请求(如 axios 拦截器)在认证完成前跳转导致票据丢失
+// ===== 关键修复:优先使用 index.html 中保存的原始 URL =====
+// index.html 在任何 JS 模块加载之前就保存了 URL,确保票据不会丢失
 let originalUrl = null
 let originalSearch = null
 let originalHash = null
 
-// 立即保存原始 URL(在任何其他代码执行之前)
+// 优先使用 index.html 中保存的原始 URL
 try {
-  originalUrl = window.location.href
-  originalSearch = window.location.search
-  originalHash = window.location.hash
-  console.log('💾 已保存原始 URL:', originalUrl)
-  console.log('💾 已保存原始 Search:', originalSearch)
-  console.log('💾 已保存原始 Hash:', originalHash)
+  if (window.__ORIGINAL_URL__) {
+    originalUrl = window.__ORIGINAL_URL__
+    originalSearch = window.__ORIGINAL_SEARCH__ || ''
+    originalHash = window.__ORIGINAL_HASH__ || ''
+    console.log('💾 使用 index.html 保存的原始 URL:', originalUrl)
+  } else {
+    // 降级:使用当前 URL
+    originalUrl = window.location.href
+    originalSearch = window.location.search
+    originalHash = window.location.hash
+    console.log('💾 降级:使用当前 URL:', originalUrl)
+  }
+  console.log('💾 原始 Search:', originalSearch)
+  console.log('💾 原始 Hash:', originalHash)
 } catch (e) {
   console.warn('⚠️ 保存原始 URL 失败:', e)
 }