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.
78 lines
1.5 KiB
78 lines
1.5 KiB
import React from 'react';
|
|
import './App.css';
|
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
|
import {Login} from './account/Login';
|
|
import { withCookies } from 'react-cookie';
|
|
import {Main} from "./Main";
|
|
import {Register} from "./account/Register";
|
|
import {user_cookie} from "./account/PropCookie";
|
|
|
|
class App extends React.Component<any, any> {
|
|
|
|
|
|
constructor(props: Readonly<any>) {
|
|
super(props);
|
|
|
|
this.state={}
|
|
}
|
|
|
|
componentDidMount() {
|
|
const { cookies } = this.props
|
|
if((cookies.get(user_cookie)||"").length>0){
|
|
this.setState({
|
|
page:<Main user={cookies.get(user_cookie)} logout={()=>this.logout()}/>
|
|
})
|
|
}else{
|
|
this.toLogin()
|
|
}
|
|
}
|
|
|
|
|
|
//注销登录
|
|
logout(){
|
|
const { cookies } = this.props
|
|
cookies.remove(user_cookie)
|
|
this.toLogin()
|
|
}
|
|
|
|
/**
|
|
* 跳转注册
|
|
*/
|
|
toRegister(){
|
|
this.setState({
|
|
page:<Register toLogin={()=>this.toLogin()}/>
|
|
})
|
|
}
|
|
|
|
//登录
|
|
login(user:string,password:string){
|
|
|
|
const { cookies } = this.props
|
|
console.debug("user_cookie="+user)
|
|
cookies.set(user_cookie,user)
|
|
|
|
this.setState({
|
|
page:<Main user={user} logout={()=>this.logout()}/>
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 跳转登录
|
|
*/
|
|
toLogin(){
|
|
this.setState({
|
|
page:<Login toRegister={()=>this.toRegister()} login={(user:string,password:string)=>this.login(user,password)}/>
|
|
})
|
|
}
|
|
|
|
|
|
render() {
|
|
return (
|
|
<div className="App">
|
|
{this.state.page}
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default withCookies(App);
|
|
|