Browse Source

fix(auth):修复Electron环境中页面跳转问题- 在Token失效时正确处理Electron环境的页面跳转
- 添加对file协议的判断以使用正确的路由方式
- 实现在首页跳转时保持当前页面状态
- 修复因协议不匹配导致的跳转失败问题- 增强跳转逻辑的兼容性与稳定性

panqiuyao 1 month ago
parent
commit
ab8afee4e4
2 changed files with 14 additions and 3 deletions
  1. 7 2
      frontend/src/stores/modules/user.ts
  2. 7 1
      frontend/src/utils/http.ts

+ 7 - 2
frontend/src/stores/modules/user.ts

@@ -93,8 +93,13 @@ export const useUserInfo = defineStore('userInfo', () => {
 
       // 跳转到首页
       try {
-
-        window.location.href = '/'
+        // 在Electron环境中使用正确的协议
+        if (window.location.protocol === 'file:') {
+          window.location.href = window.location.href.split('#')[0] + '#/';
+          window.location.reload()
+        } else {
+          window.location.href = '/';
+        }
         console.log('已跳转到首页');
       } catch (error) {
         console.error('跳转到首页失败:', error);

+ 7 - 1
frontend/src/utils/http.ts

@@ -49,7 +49,13 @@ async function handleTokenExpiry() {
         // 跳转到首页(在会话存储中标记需要显示登录框)
         try {
             sessionStorage.setItem('NEED_LOGIN_MODAL', '1');
-            window.location.href = '/'
+            // 在Electron环境中使用正确的协议
+            if (window.location.protocol === 'file:') {
+                window.location.href = window.location.href.split('#')[0] + '#/';
+                window.location.reload()
+            } else {
+                window.location.href = '/';
+            }
             console.log('Token失效:已跳转到首页');
         } catch (error) {
             console.error('Token失效:跳转到首页失败:', error);