|
@@ -99,7 +99,22 @@ axios.interceptors.request.use(async (config) => {
|
|
|
const offline = isOfflineMode();
|
|
const offline = isOfflineMode();
|
|
|
if (!offline) {
|
|
if (!offline) {
|
|
|
if (!token && !~notLoginUrls.indexOf(config.url) && !shareBypassLogin) {
|
|
if (!token && !~notLoginUrls.indexOf(config.url) && !shareBypassLogin) {
|
|
|
- const redirect = window.location.href;
|
|
|
|
|
|
|
+ const buildRedirect = (): string => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const current = router.currentRoute?.value;
|
|
|
|
|
+ // 如果已经在登录页且已有 redirect 参数,避免递归叠加
|
|
|
|
|
+ const isLogin = current?.name === RouteName.login;
|
|
|
|
|
+ const existing = (current?.query?.redirect as string | undefined);
|
|
|
|
|
+ if (isLogin && existing) {
|
|
|
|
|
+ return existing;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {}
|
|
|
|
|
+ const { origin, pathname, search, hash } = window.location;
|
|
|
|
|
+ // 为了在 hash 路由中作为查询参数安全传递,双重编码 hash
|
|
|
|
|
+ const safeHash = hash ? encodeURIComponent(encodeURIComponent(hash)) : "";
|
|
|
|
|
+ return origin + pathname + (search || "") + safeHash;
|
|
|
|
|
+ };
|
|
|
|
|
+ const redirect = buildRedirect();
|
|
|
console.log(redirect, 'redirect')
|
|
console.log(redirect, 'redirect')
|
|
|
router.replace({ name: RouteName.login, query: { redirect } });
|
|
router.replace({ name: RouteName.login, query: { redirect } });
|
|
|
throw "用户未登录";
|
|
throw "用户未登录";
|
|
@@ -159,7 +174,20 @@ const responseInterceptor = (res: AxiosResponse<any, any>) => {
|
|
|
errMsg === "token已经失效,请重新登录"
|
|
errMsg === "token已经失效,请重新登录"
|
|
|
) {
|
|
) {
|
|
|
getAuth().clear();
|
|
getAuth().clear();
|
|
|
- const redirect = window.location.href;
|
|
|
|
|
|
|
+ const buildRedirect = (): string => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const current = router.currentRoute?.value;
|
|
|
|
|
+ const isLogin = current?.name === RouteName.login;
|
|
|
|
|
+ const existing = (current?.query?.redirect as string | undefined);
|
|
|
|
|
+ if (isLogin && existing) {
|
|
|
|
|
+ return existing;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {}
|
|
|
|
|
+ const { origin, pathname, search, hash } = window.location;
|
|
|
|
|
+ const safeHash = hash ? encodeURIComponent(encodeURIComponent(hash)) : "";
|
|
|
|
|
+ return origin + pathname + (search || "") + safeHash;
|
|
|
|
|
+ };
|
|
|
|
|
+ const redirect = buildRedirect();
|
|
|
router.replace({ name: RouteName.login, query: { redirect } });
|
|
router.replace({ name: RouteName.login, query: { redirect } });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|