2017-07-10 19:50:11 +08:00
|
|
|
import React, { Component } from 'react'
|
2017-07-19 16:24:37 +08:00
|
|
|
import axios from 'axios';
|
|
|
|
import { Route, HashRouter, Redirect } from 'react-router-dom'
|
2017-07-20 15:38:25 +08:00
|
|
|
import { Header, Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
|
2017-07-19 16:24:37 +08:00
|
|
|
import User from './containers/User/User.js'
|
|
|
|
|
|
|
|
const LOADING_STATUS = 0;
|
|
|
|
const GUEST_STATUS = 1;
|
|
|
|
const MEMBER_STATUS = 2;
|
2017-07-10 19:50:11 +08:00
|
|
|
|
|
|
|
class App extends Component {
|
2017-07-19 16:24:37 +08:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
login: LOADING_STATUS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
route = (status) => {
|
|
|
|
let r;
|
|
|
|
if (status === LOADING_STATUS) {
|
|
|
|
return <span>loading...</span>
|
|
|
|
} else if (status === GUEST_STATUS) {
|
|
|
|
r = (
|
|
|
|
<HashRouter>
|
|
|
|
|
|
|
|
<div className="router-main">
|
|
|
|
<Header />
|
|
|
|
<Route path="/" component={Home} exact />
|
|
|
|
<Redirect to="/" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</HashRouter>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
r = (
|
|
|
|
<HashRouter>
|
|
|
|
<div className="router-main">
|
|
|
|
<Header />
|
|
|
|
<Route path="/" component={ProjectGroups} exact />
|
|
|
|
<Route path="/ProjectGroups" component={ProjectGroups} />
|
|
|
|
<Route path="/Interface" component={Interface} />
|
|
|
|
<Route path="/user" component={User} />
|
|
|
|
<Route path="/News" component={News} />
|
2017-07-20 15:38:25 +08:00
|
|
|
<Route path="/AddInterface" component={ AddInterface } />
|
2017-07-19 16:24:37 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</HashRouter>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
console.log('app.js init')
|
|
|
|
axios.get('/user/status').then((res) => {
|
|
|
|
if (res.data.errcode === 0 && res.data.data._id > 0) {
|
|
|
|
this.setState({
|
|
|
|
login: MEMBER_STATUS
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
login: GUEST_STATUS
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}, (err) => {
|
|
|
|
this.setState({
|
|
|
|
login: GUEST_STATUS
|
|
|
|
})
|
|
|
|
console.log(err.message)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-10 19:50:11 +08:00
|
|
|
render() {
|
2017-07-19 16:24:37 +08:00
|
|
|
console.log(MEMBER_STATUS)
|
|
|
|
console.log(this.route(this.state.login))
|
|
|
|
return this.route(this.state.login)
|
|
|
|
|
|
|
|
|
2017-07-10 19:50:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App
|