登录改为表单

main
wuyize 2022-12-25 15:47:58 +08:00
parent e3c0fd2659
commit 420b6155ae
2 changed files with 11 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React, {FC, useEffect} from 'react';
import { Button } from 'antd';
import {useAppSelector} from "../models/hooks";
import {getToken, store} from "../models/store";
@ -8,8 +8,12 @@ function HomeView() {
const token = useAppSelector(getToken);
const navigate = useNavigate();
console.log( store.getState())
if(token.accessToken==='')
navigate('/login')
useEffect(() => {
if(token.accessToken===''){
console.log("redirect")
navigate("/login")
}
}, []);
return (
<div className="HomeView">
<p>{token.accessToken}</p>

View File

@ -15,7 +15,10 @@ function LoginView() {
const onFinish = (values: any) => {
console.log(values)
axios.post(baseUrl + 'login', values).then(function (response) {
const data = new FormData();
data.append('staffId', values.staffId);
data.append('staffPassword', values.staffPassword);
axios.post(baseUrl + 'login', data).then(function (response) {
console.log(response.data)
dispatch(setToken({
accessToken: response.data.accessToken,