mirror of
https://github.com/PlayEdu/backend
synced 2025-06-22 20:22:47 +08:00
登录页面初步
This commit is contained in:
parent
0dad3f206e
commit
31e30a5316
14
src/App.tsx
14
src/App.tsx
@ -1,10 +1,22 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styles from "./App.module.css";
|
import styles from "./App.module.css";
|
||||||
import { useRoutes } from "react-router-dom";
|
import { useLocation, useRoutes, useNavigate } from "react-router-dom";
|
||||||
import routes from "./router/routes";
|
import routes from "./router/routes";
|
||||||
|
import { getToken } from "./utils/index";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const Views = () => useRoutes(routes);
|
const Views = () => useRoutes(routes);
|
||||||
|
// const CheckLogin = () => {
|
||||||
|
// const navigate = useNavigate();
|
||||||
|
// const location = useLocation();
|
||||||
|
// if (location.pathname !== "/login") {
|
||||||
|
// navigate("/login");
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// const token = getToken();
|
||||||
|
// if (!token) {
|
||||||
|
// CheckLogin();
|
||||||
|
// }
|
||||||
return (
|
return (
|
||||||
<div className={styles.App}>
|
<div className={styles.App}>
|
||||||
<Views />
|
<Views />
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
import axios, { Axios, AxiosResponse } from "axios";
|
import axios, { Axios, AxiosResponse } from "axios";
|
||||||
import { message } from "antd";
|
import { message } from "antd";
|
||||||
import { getToken, clearToken } from "../../utils/index";
|
import { getToken, clearToken } from "../../utils/index";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
|
const GoLogin = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
navigate("/login");
|
||||||
|
};
|
||||||
|
|
||||||
export class HttpClient {
|
export class HttpClient {
|
||||||
axios: Axios;
|
axios: Axios;
|
||||||
@ -10,9 +16,9 @@ export class HttpClient {
|
|||||||
baseURL: url,
|
baseURL: url,
|
||||||
timeout: 15000,
|
timeout: 15000,
|
||||||
withCredentials: false,
|
withCredentials: false,
|
||||||
headers:{
|
headers: {
|
||||||
"Accept":"application/json"
|
Accept: "application/json",
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
//拦截器注册
|
//拦截器注册
|
||||||
@ -46,6 +52,7 @@ export class HttpClient {
|
|||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
clearToken();
|
clearToken();
|
||||||
// 跳转到登录界面
|
// 跳转到登录界面
|
||||||
|
GoLogin();
|
||||||
} else if (status === 404) {
|
} else if (status === 404) {
|
||||||
// 跳转到404页面
|
// 跳转到404页面
|
||||||
} else if (status === 403) {
|
} else if (status === 403) {
|
||||||
|
@ -64,7 +64,7 @@ const data: DataType[] = [
|
|||||||
|
|
||||||
export const VodListPage: React.FC = () => {
|
export const VodListPage: React.FC = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
login.login("1@qq.com", "123123", "1", "2");
|
|
||||||
}, []);
|
}, []);
|
||||||
const handleChange = (e: any) => {
|
const handleChange = (e: any) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
@ -3,16 +3,11 @@ import styles from "./HomePage.module.css";
|
|||||||
import { Outlet, useNavigate } from "react-router-dom";
|
import { Outlet, useNavigate } from "react-router-dom";
|
||||||
import { Header, LeftMenu, Footer } from "../../compenents";
|
import { Header, LeftMenu, Footer } from "../../compenents";
|
||||||
import { login } from "../../api/index";
|
import { login } from "../../api/index";
|
||||||
import { getToken, clearToken } from "../../utils/index";
|
|
||||||
|
|
||||||
export const HomePage: React.FC = () => {
|
export const HomePage: React.FC = () => {
|
||||||
// const token = getToken();
|
|
||||||
// const navigate = useNavigate();
|
|
||||||
// if (token === "") {
|
|
||||||
// navigate("/login");
|
|
||||||
// }
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
login.login("1@qq.com", "123123", "1", "2");
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -4,9 +4,9 @@ import { Typography, Spin, Input, Button, message } from "antd";
|
|||||||
import { login, system } from "../../api/index";
|
import { login, system } from "../../api/index";
|
||||||
import { setToken } from "../../utils/index";
|
import { setToken } from "../../utils/index";
|
||||||
|
|
||||||
export const Login: React.FC = (defaultState) => {
|
export const Login: React.FC = () => {
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
const [captchaList, setCourse] = useState<any>(null);
|
const [image, setImage] = useState<string>("");
|
||||||
const [email, setEmail] = useState<string>("");
|
const [email, setEmail] = useState<string>("");
|
||||||
const [password, setPassword] = useState<string>("");
|
const [password, setPassword] = useState<string>("");
|
||||||
const [captcha_val, setCaptcha_val] = useState<string>("");
|
const [captcha_val, setCaptcha_val] = useState<string>("");
|
||||||
@ -14,7 +14,7 @@ export const Login: React.FC = (defaultState) => {
|
|||||||
const fetchData = () => {
|
const fetchData = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
system.getImageCaptcha().then((res: any) => {
|
system.getImageCaptcha().then((res: any) => {
|
||||||
setCourse(res.data);
|
setImage(res.data.image);
|
||||||
setCaptcha_key(res.data.key);
|
setCaptcha_key(res.data.key);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
@ -105,7 +105,7 @@ export const Login: React.FC = (defaultState) => {
|
|||||||
<img
|
<img
|
||||||
className={styles["captcha"]}
|
className={styles["captcha"]}
|
||||||
onClick={fetchData}
|
onClick={fetchData}
|
||||||
src={captchaList.image}
|
src={image}
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user