import React, { PureComponent as Component } from 'react'; import ReactDOM from 'react-dom'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { Route, BrowserRouter as Router } from 'react-router-dom'; import { Home, Group, Project, Follows, AddProject, Login } from './containers/index'; import { Alert } from 'antd'; 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'; import MyPopConfirm from './components/MyPopConfirm/MyPopConfirm'; // import statisticsPage from '../exts/yapi-plugin-statistics/statisticsClientPage/index'; import { checkLoginState } from './reducer/modules/user'; import { requireAuthentication } from './components/AuthenticatedComponent'; const plugin = require('client/plugin.js'); const LOADING_STATUS = 0; const alertContent = () => { const ua = window.navigator.userAgent, isChrome = ua.indexOf("Chrome") && window.chrome; if (!isChrome) { return } } let AppRoute = { home: { path: '/', component: Home }, group: { path: '/group', component: Group }, project: { path: '/project/:id', component: Project }, user: { path: '/user', component: User }, follow: { path: '/follow', component: Follows }, addProject: { path: '/add-project', component: AddProject }, login: { path: '/login', component: Login } }; // 增加路由钩子 plugin.emitHook('app_route', AppRoute); @connect( state => { return { loginState: state.user.loginState }; }, { checkLoginState } ) export default class App extends Component { constructor(props) { super(props); this.state = { login: LOADING_STATUS }; } static propTypes = { checkLoginState: PropTypes.func, loginState: PropTypes.number }; componentDidMount() { this.props.checkLoginState(); } route = (status) => { let r; if (status === LOADING_STATUS) { return ; } else { r = ( { // 自定义 window.confirm // http://reacttraining.cn/web/api/BrowserRouter/getUserConfirmation-func let container = document.createElement('div'); document.body.appendChild(container); ReactDOM.render(( ), container); }}> {alertContent()} {this.props.loginState !== 1 ? : null} {Object.keys(AppRoute).map(key => { let item = AppRoute[key]; return ( key === 'login' ? : key === 'home' ? : ) }) } {/* {/* */} {/* */} ) } return r; } render() { return this.route(this.props.loginState); } }