浏览代码

没有登记的话记住当前的页面路由,并且在登录时跳转过去

xiaochan 1 月之前
父节点
当前提交
7ededf278e
共有 2 个文件被更改,包括 14 次插入7 次删除
  1. 6 5
      src/utils/request.js
  2. 8 2
      src/views/system/login.vue

+ 6 - 5
src/utils/request.js

@@ -63,7 +63,7 @@ service.interceptors.response.use(
         duration: 3500,
         dangerouslyUseHTMLString: true,
         message: response.data.message,
-        showClose: true
+        showClose: true,
       });
       return response.data.data;
     }
@@ -91,7 +91,7 @@ service.interceptors.response.use(
         message: response.data.message,
         duration: 3500,
         grouping: true,
-        showClose: true
+        showClose: true,
       });
     } else if (response.data.code > 2000 && response.data.code < 3000) {
       if (response.data.code === 2003) {
@@ -111,6 +111,7 @@ service.interceptors.response.use(
     } else if (response.data.code > 3000 && response.data.code < 4000) {
       if (onceFun == null) {
         onceFun = true;
+        const url = XEUtils.parseUrl(window.location.href);
         CyMessageBox.alert({
           type: "error",
           message: response.data.message,
@@ -118,7 +119,7 @@ service.interceptors.response.use(
           showClose: false,
         })
           .then(() => {
-            router.push("/login").then(XEUtils.noop);
+            router.push(`/login?redirect=${url.path}`).then(XEUtils.noop);
           })
           .finally(() => {
             onceFun = null;
@@ -137,7 +138,7 @@ service.interceptors.response.use(
         type: "error",
         duration: 2500,
         grouping: true,
-        showClose: true
+        showClose: true,
       });
       return {
         error: true,
@@ -183,7 +184,7 @@ service.interceptors.response.use(
       type: "error",
       duration: 3500,
       grouping: true,
-      showClose: true
+      showClose: true,
     });
     useProgressBarStore().initialize({
       title: "",

+ 8 - 2
src/views/system/login.vue

@@ -78,6 +78,7 @@ import router from "@/router";
 import { useSystemStore } from "@/pinia/system-store";
 import { changeToken } from "@/utils/cy-use/useChangeToken";
 import { useDialog } from "@/components/cy/CyDialog/index.ts";
+import XEUtils from "xe-utils";
 
 const showPwd = ref(false);
 
@@ -104,7 +105,7 @@ const submit = () => {
     codeRs: form.codeRs,
     password: form.password,
   };
-  loginApi(params).then(res => {
+  loginApi(params).then(async res => {
     localStorage.clear();
     userStore.setUserInfo(res);
     systemConfig.setConfig(res.userConfigJson);
@@ -115,7 +116,12 @@ const submit = () => {
       });
     } else {
       changeToken();
-      router.push("/dashboard");
+      const url = XEUtils.parseUrl(window.location.href);
+      if (url.searchQuery?.redirect) {
+        location.href = url.search.replace("?redirect=", "");
+      } else {
+        router.push("/dashboard");
+      }
     }
   });
 };