mirror of
https://github.com/PlayEdu/frontend.git
synced 2025-06-29 20:42:50 +08:00
登录初步
This commit is contained in:
parent
4e03c1d82d
commit
4b965f26f5
14
src/App.tsx
14
src/App.tsx
@ -3,9 +3,23 @@ import routes from "./routes";
|
|||||||
import "./App.scss";
|
import "./App.scss";
|
||||||
import { Suspense } from "react";
|
import { Suspense } from "react";
|
||||||
import LoadingPage from "./pages/loading";
|
import LoadingPage from "./pages/loading";
|
||||||
|
import { user } from "./api/index";
|
||||||
|
import { getToken } from "./utils/index";
|
||||||
|
import { useDispatch } from "react-redux";
|
||||||
|
import { logoutAction } from "./store/user/loginUserSlice";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const Views = () => useRoutes(routes);
|
const Views = () => useRoutes(routes);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const getUser = () => {
|
||||||
|
user.detail().then((res: any) => {
|
||||||
|
const data = res.data;
|
||||||
|
dispatch(logoutAction(data.user));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (getToken()) {
|
||||||
|
getUser();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<LoadingPage />}>
|
<Suspense fallback={<LoadingPage />}>
|
||||||
|
@ -10,7 +10,7 @@ export function login(
|
|||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
captcha_key: captchaKey,
|
captcha_key: captchaKey,
|
||||||
captcha_value: captchaVal,
|
captcha_val: captchaVal,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ const LoginPage: React.FC = () => {
|
|||||||
const getUser = () => {
|
const getUser = () => {
|
||||||
user.detail().then((res: any) => {
|
user.detail().then((res: any) => {
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
dispatch(logoutAction(data.user));
|
dispatch(loginAction(data.user));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
navigate("/");
|
navigate("/");
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user