Преглед изворни кода

登录后跳转到原来的页面

visuddhinanda пре 1 година
родитељ
комит
c098ace1e8
1 измењених фајлова са 13 додато и 2 уклоњено
  1. 13 2
      dashboard-v4/dashboard/src/components/nut/users/SignIn.tsx

+ 13 - 2
dashboard-v4/dashboard/src/components/nut/users/SignIn.tsx

@@ -1,7 +1,7 @@
 import { useIntl } from "react-intl";
 import { ProForm, ProFormText } from "@ant-design/pro-components";
 import { Alert, message } from "antd";
-import { useNavigate } from "react-router-dom";
+import { useNavigate, useParams, useSearchParams } from "react-router-dom";
 import { EyeInvisibleOutlined, EyeTwoTone } from "@ant-design/icons";
 
 import { useAppDispatch } from "../../../hooks";
@@ -32,6 +32,7 @@ const Widget = () => {
   const dispatch = useAppDispatch();
   const navigate = useNavigate();
   const [error, setError] = useState<string>();
+  const [searchParams] = useSearchParams();
 
   return (
     <>
@@ -52,7 +53,17 @@ const Widget = () => {
             get<IUserResponse>("/v2/auth/current").then((json) => {
               if (json.ok) {
                 dispatch(signIn([json.data, res.data]));
-                navigate(TO_HOME);
+                let url: string | null = null;
+                searchParams.forEach((value, key) => {
+                  if (key === "url") {
+                    url = value;
+                  }
+                });
+                if (url) {
+                  window.location.href = atob(url);
+                } else {
+                  navigate(TO_HOME);
+                }
               } else {
                 setError("用户名或密码错误");
                 console.error(json.message);