From 99f5615144c5e99c7f734c00d5e5242b7bd4516b Mon Sep 17 00:00:00 2001 From: sunlei Date: Sun, 17 May 2026 13:56:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=99=BB=E5=BD=95=E5=9B=9E=E8=B7=B3=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 +- src/api/auth.ts | 20 +++++++++++++++++--- src/config.ts | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 50f727a..03b77a1 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ NODE_ENV=development VITE_APP_PLAY_GROUND=http://localhost:48090 VITE_APP_PROXY=http://localhost:48085/ -VITE_APP_ADMIN_LOGIN=http://localhost:5999/auth/login +VITE_APP_ADMIN_LOGIN=http://localhost:5999/#/auth/login VITE_APP_BASE_API=/api VITE_APP_OSS_DOMAIN=/chart-assets diff --git a/src/api/auth.ts b/src/api/auth.ts index d836819..bf751db 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -49,10 +49,24 @@ export const persistAuthData = ({ } }; -export const redirectToAdminLogin = () => { +const buildAdminLoginUrl = (redirect: string) => { const loginUrl = new URL(config.adminLogin); - loginUrl.searchParams.set("redirect", encodeURIComponent(window.location.href)); - window.location.href = loginUrl.toString(); + + if (loginUrl.hash) { + const [hashPath, hashSearch = ""] = loginUrl.hash.slice(1).split("?"); + const hashParams = new URLSearchParams(hashSearch); + hashParams.set("redirect", redirect); + // Admin 生产环境使用 hash 路由,redirect 必须放在 hash 内部才能被 Vue Router 读取。 + loginUrl.hash = `${hashPath}?${hashParams.toString()}`; + return loginUrl.toString(); + } + + loginUrl.searchParams.set("redirect", redirect); + return loginUrl.toString(); +}; + +export const redirectToAdminLogin = () => { + window.location.href = buildAdminLoginUrl(window.location.href); }; export const refreshPersistedAuth = async () => { diff --git a/src/config.ts b/src/config.ts index ba6c456..2a96c05 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,7 @@ import { os } from "@/utils/detect"; const config = (() => ({ - adminLogin: import.meta.env.VITE_APP_ADMIN_LOGIN || `${window.location.protocol}//${window.location.hostname}:5999/auth/login`, + adminLogin: import.meta.env.VITE_APP_ADMIN_LOGIN || `${window.location.protocol}//${window.location.hostname}:5999/#/auth/login`, isMobileApp: !os.desktop, axiosBase: "/api", playground: import.meta.env.VITE_APP_PLAY_GROUND,