wangfumin před 2 měsíci
rodič
revize
72e0bbfb46
2 změnil soubory, kde provedl 8 přidání a 76 odebrání
  1. 2 2
      src/request/index.ts
  2. 6 74
      src/view/system/login.vue

+ 2 - 2
src/request/index.ts

@@ -99,7 +99,7 @@ axios.interceptors.request.use(async (config) => {
     const offline = isOfflineMode();
     if (!offline) {
       if (!token && !~notLoginUrls.indexOf(config.url) && !shareBypassLogin) {
-        const redirect = encodeURIComponent(window.location.href);
+        const redirect = window.location.href;
         router.replace({ name: RouteName.login, query: { redirect } });
         throw "用户未登录";
       }
@@ -158,7 +158,7 @@ const responseInterceptor = (res: AxiosResponse<any, any>) => {
         errMsg === "token已经失效,请重新登录"
       ) {
         getAuth().clear();
-        const redirect = encodeURIComponent(window.location.href);
+        const redirect = window.location.href;
         router.replace({ name: RouteName.login, query: { redirect } });
       }
     }

+ 6 - 74
src/view/system/login.vue

@@ -139,82 +139,14 @@ const submitClick = async () => {
     }
 
     const params: any = router.currentRoute.value.query;
-    // console.log(params, 999);
     if ("redirect" in params && params.redirect) {
-      const rawRedirect = String(params.redirect);
-      let decoded = rawRedirect;
-      try {
-        decoded = decodeURIComponent(rawRedirect);
-      } catch {
-        try {
-          decoded = decodeURI(rawRedirect);
-        } catch {}
-      }
-      let url: URL;
-      try {
-        url = decoded.startsWith("http://") || decoded.startsWith("https://")
-          ? new URL(decoded)
-          : new URL(decoded, window.location.origin);
-      } catch (e) {
-        console.warn("Invalid redirect URL, fallback to dispatch:", decoded, e);
-        router.replace({ name: RouteName.dispatch });
-        return;
-      }
-      const isAbsolute = /^https?:\/\//.test(decoded);
-      const isInternal = !isAbsolute || url.origin === window.location.origin;
-
-      // remove token from appropriate place
-      window.localStorage.setItem('token', user.value.token);
-      if (isInternal) {
-        let targetPath = '';
-        if (url.hash) {
-          const hashStr = url.hash.slice(1); // remove leading '#'
-          const qIndex = hashStr.indexOf('?');
-          if (qIndex > -1) {
-            const basePath = hashStr.slice(0, qIndex);
-            const queryStr = hashStr.slice(qIndex + 1);
-            const usp = new URLSearchParams(queryStr);
-            usp.delete('token');
-            const qs = usp.toString();
-            targetPath = qs ? `${basePath}?${qs}` : basePath;
-          } else {
-            targetPath = hashStr;
-          }
-      } else {
-          // Fallback: when redirect contains '%23' in pathname (encoded '#'), treat as hash route
-          if (url.pathname.includes('%23')) {
-            const idx = url.pathname.indexOf('%23');
-            const after = url.pathname.slice(idx + 3); // content after '%23'
-            const qIndex = after.indexOf('?');
-            if (qIndex > -1) {
-              const basePath = after.slice(0, qIndex);
-              const queryStr = after.slice(qIndex + 1);
-              const usp = new URLSearchParams(queryStr);
-              usp.delete('token');
-              const qs = usp.toString();
-              targetPath = qs ? `${basePath}?${qs}` : basePath;
-            } else {
-              targetPath = after;
-            }
-          } else {
-            const usp = new URLSearchParams(url.search);
-            usp.delete('token');
-            const qs = usp.toString();
-            const pathName = url.pathname;
-            targetPath = qs ? `${pathName}?${qs}` : pathName;
-          }
-      }
-      if (!targetPath.startsWith('/')) targetPath = '/' + targetPath;
-      console.log('Internal redirect to', targetPath);
-      router.replace(targetPath);
-      } else {
-        url.searchParams.delete("token");
-        console.log('External redirect to', url.toString());
-        window.location.replace(url.toString());
-      }
+      const url = new URL(decodeURIComponent(params.redirect as string));
+      url.searchParams.delete("token");
+      // url.searchParams.append("token", user.value.token);
+      window.localStorage.setItem('token', user.value.token)
+      window.location.replace(url);
     } else {
-      // router.replace({ name: RouteName.scene });
-      router.replace({ name: RouteName.dispatch });
+      router.replace({ name: RouteName.example });
     }
   } catch (e) {
     console.error(e);