You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
help_admin/src/App.tsx

83 lines
1.6 KiB

4 years ago
import React from 'react';
import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import {Login} from './account/Login';
4 years ago
import {Cookies, withCookies} from 'react-cookie';
import {Main} from "./Main";
import {Register} from "./account/Register";
import {manager_cookie} from "./account/PropCookie";
4 years ago
import {LoginRes} from "./result";
4 years ago
4 years ago
class App extends React.Component<
{
allCookies:any;
cookies:Cookies
},
{
page?:JSX.Element;
}
> {
constructor(props: Readonly<any>) {
super(props);
this.state={}
}
componentDidMount() {
const { cookies } = this.props
if((cookies.get(manager_cookie)||"").length>0){
this.setState({
4 years ago
page:<Main cookies={this.props.cookies} logout={()=>this.logout()}/>
})
}else{
this.toLogin()
}
}
4 years ago
//注销登录
logout(){
4 years ago
this.props.cookies.remove(manager_cookie)
this.toLogin()
}
/**
*
*/
toRegister(){
this.setState({
page:<Register toLogin={()=>this.toLogin()}/>
})
}
/**
*
*/
toLogin(){
this.setState({
4 years ago
page:<Login cookies={this.props.cookies} toRegister={()=>this.toRegister()} onLoginSuccess={(res:LoginRes)=>{
this.props.cookies.set(manager_cookie,res.managerId)
this.setState({
page:<Main logout={()=>this.logout()} cookies={this.props.cookies}/>
})
}
}/>
})
}
render() {
4 years ago
return (
<div className="App">
{this.state.page}
4 years ago
</div>
);
}
}
export default withCookies(App);