2017-07-26 22:03:18 +08:00
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2017-08-11 11:26:49 +08:00
|
|
|
|
import { Route, BrowserRouter as Router } from 'react-router-dom';
|
2017-08-20 18:56:31 +08:00
|
|
|
|
import { Home, Group, Project, Follows, AddProject, Login } from './containers/index';
|
2017-08-28 17:13:05 +08:00
|
|
|
|
import {message} from 'antd'
|
2017-07-26 22:03:18 +08:00
|
|
|
|
import User from './containers/User/User.js';
|
|
|
|
|
import Header from './components/Header/Header';
|
|
|
|
|
import Footer from './components/Footer/Footer';
|
|
|
|
|
import Loading from './components/Loading/Loading';
|
2017-08-10 20:08:23 +08:00
|
|
|
|
import { checkLoginState } from './reducer/modules/user';
|
2017-07-24 11:35:31 +08:00
|
|
|
|
import { requireAuthentication } from './components/AuthenticatedComponent';
|
2017-07-20 19:59:49 +08:00
|
|
|
|
|
2017-07-19 16:24:37 +08:00
|
|
|
|
const LOADING_STATUS = 0;
|
|
|
|
|
|
2017-07-24 11:35:31 +08:00
|
|
|
|
@connect(
|
|
|
|
|
state => {
|
2017-07-26 22:03:18 +08:00
|
|
|
|
return {
|
2017-08-10 20:08:23 +08:00
|
|
|
|
loginState: state.user.loginState
|
2017-07-26 22:03:18 +08:00
|
|
|
|
};
|
2017-07-24 11:35:31 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
checkLoginState
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
export default class App extends Component {
|
2017-07-19 16:24:37 +08:00
|
|
|
|
constructor(props) {
|
2017-07-20 19:59:49 +08:00
|
|
|
|
super(props);
|
2017-07-19 16:24:37 +08:00
|
|
|
|
this.state = {
|
|
|
|
|
login: LOADING_STATUS
|
2017-07-26 22:03:18 +08:00
|
|
|
|
};
|
2017-07-19 16:24:37 +08:00
|
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
|
2017-07-20 19:59:49 +08:00
|
|
|
|
static propTypes = {
|
2017-07-26 22:03:18 +08:00
|
|
|
|
checkLoginState: PropTypes.func,
|
|
|
|
|
loginState: PropTypes.number
|
|
|
|
|
};
|
2017-07-24 11:35:31 +08:00
|
|
|
|
|
2017-08-10 20:08:23 +08:00
|
|
|
|
|
2017-07-24 11:35:31 +08:00
|
|
|
|
componentDidMount() {
|
2017-08-28 18:01:28 +08:00
|
|
|
|
message.warning('YApi平台正在公测,发布正式版会删除所有公测数据!', 10)
|
2017-07-24 11:35:31 +08:00
|
|
|
|
this.props.checkLoginState();
|
|
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
|
2017-07-19 16:24:37 +08:00
|
|
|
|
route = (status) => {
|
|
|
|
|
let r;
|
|
|
|
|
if (status === LOADING_STATUS) {
|
2017-07-26 22:03:18 +08:00
|
|
|
|
return <Loading visible />;
|
2017-07-19 16:24:37 +08:00
|
|
|
|
} else {
|
|
|
|
|
r = (
|
2017-08-21 15:13:52 +08:00
|
|
|
|
<Router >
|
|
|
|
|
<div className="g-main">
|
|
|
|
|
<div className="router-main">
|
|
|
|
|
{this.props.loginState !== 1 ? <Header /> : null}
|
|
|
|
|
<div className="router-container">
|
|
|
|
|
<Route exact path="/" component={Home} />
|
|
|
|
|
<Route path="/group" component={requireAuthentication(Group)} />
|
|
|
|
|
<Route path="/project/:id" component={requireAuthentication(Project)} />
|
|
|
|
|
<Route path="/user" component={requireAuthentication(User)} />
|
|
|
|
|
<Route path="/follow" component={requireAuthentication(Follows)} />
|
|
|
|
|
<Route path="/add-project" component={requireAuthentication(AddProject)} />
|
|
|
|
|
<Route path="/login" component={Login} />
|
|
|
|
|
</div>
|
2017-07-26 16:20:20 +08:00
|
|
|
|
</div>
|
2017-07-26 22:03:18 +08:00
|
|
|
|
<Footer />
|
2017-07-19 16:24:37 +08:00
|
|
|
|
</div>
|
2017-08-11 10:25:19 +08:00
|
|
|
|
</Router>
|
2017-09-05 17:04:59 +08:00
|
|
|
|
|
2017-07-19 16:24:37 +08:00
|
|
|
|
)
|
|
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
return r;
|
2017-07-19 16:24:37 +08:00
|
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
|
2017-07-10 19:50:11 +08:00
|
|
|
|
render() {
|
2017-07-24 11:35:31 +08:00
|
|
|
|
return this.route(this.props.loginState);
|
2017-07-10 19:50:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|