feat: add LogoutPage and adjust LoginPage
This commit is contained in:
parent
2474012a1a
commit
d69f6a5b86
@ -1,10 +1,11 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { message } from "antd";
|
||||
import { LoginForm, ProFormText } from "@ant-design/pro-components";
|
||||
import { LockOutlined, UserOutlined } from "@ant-design/icons";
|
||||
|
||||
import { useAuth } from "../components/hook.ts";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
@ -13,7 +14,11 @@ export function LoginPage() {
|
||||
const [errMsg, setErrMsg] = useState("");
|
||||
|
||||
const onSuccess = async () => {
|
||||
await msg.success("登录成功");
|
||||
await msg.open({
|
||||
type: "success",
|
||||
content: "登录成功",
|
||||
duration: 1,
|
||||
});
|
||||
if (window.history?.length) navigate(-1);
|
||||
else navigate("/");
|
||||
};
|
||||
|
27
src/pages/logout.tsx
Normal file
27
src/pages/logout.tsx
Normal file
@ -0,0 +1,27 @@
|
||||
import { useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { Result } from "antd";
|
||||
import { SmileOutlined } from "@ant-design/icons";
|
||||
|
||||
import { useAuth } from "../components/hook.ts";
|
||||
|
||||
export function LogoutPage() {
|
||||
const navigate = useNavigate();
|
||||
const auth = useAuth();
|
||||
|
||||
const goHome = () => setTimeout(() => navigate("/"), 1500);
|
||||
useEffect(
|
||||
() => {
|
||||
auth.logout(goHome, goHome);
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Result icon={<SmileOutlined />} title={"See you next time!"} />
|
||||
</>
|
||||
);
|
||||
}
|
@ -7,3 +7,4 @@ export { SearchPage } from "./search";
|
||||
export { SubmitPage } from "./submit";
|
||||
|
||||
export { LoginPage } from "./login.tsx";
|
||||
export { LogoutPage } from "./logout.tsx";
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {
|
||||
HomePage,
|
||||
LoginPage,
|
||||
LogoutPage,
|
||||
ProblemPage,
|
||||
SearchPage,
|
||||
SubmitPage,
|
||||
@ -18,6 +19,10 @@ const RouteConfigs = [
|
||||
path: "login",
|
||||
element: <LoginPage />,
|
||||
},
|
||||
{
|
||||
path: "logout",
|
||||
element: <LogoutPage />,
|
||||
},
|
||||
{
|
||||
path: "search",
|
||||
element: <SearchPage />,
|
||||
|
Reference in New Issue
Block a user