mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-20 14:33:49 +00:00
new App
This commit is contained in:
+2
-5
@@ -8,14 +8,13 @@ import {Router, Route, IndexRoute, hashHistory} from 'react-router';
|
||||
import './utils/index.js'; // 引入各种prototype辅助方法
|
||||
|
||||
// 开始引入各种自定义的组件
|
||||
import App from './components/App';
|
||||
// import App from './components/App';
|
||||
import App from './view/index';
|
||||
import Welcome from './components/Welcome';
|
||||
import Error from './components/Error';
|
||||
import Hello from './components/Hello';
|
||||
import DBTable from './components/DBTable';
|
||||
|
||||
// 路由表, 只要menu.js中所有的叶子节点配置了路由就可以了
|
||||
// 我本来想根据menu.js自动生成路由表, 但那样太不灵活了, 还是自己配置好些
|
||||
const routes = (
|
||||
<Router history={hashHistory}>
|
||||
<Route path="/" component={App}>
|
||||
@@ -48,9 +47,7 @@ const routes = (
|
||||
<Route path="666bb" component={Hello}/>
|
||||
</Route>
|
||||
</Route>
|
||||
|
||||
<Route path="*" component={Error}/>
|
||||
|
||||
</Route>
|
||||
</Router>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import config from 'config';
|
||||
import ajax from './ajax';
|
||||
import logger from './Logger';
|
||||
|
||||
module.exports = {ajax,config,logger};
|
||||
@@ -0,0 +1,75 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import Header from '../components/Header';
|
||||
import Footer from '../components/Footer';
|
||||
import Sidebar from '../components/Sidebar';
|
||||
import SignIn from './user/SignIn';
|
||||
// import SignIn from '../components/Login';
|
||||
import Breadcrumb from '../components/Breadcrumb';
|
||||
import {ajax,config,logger} from '../utils/lib.js'
|
||||
import {Spin, message} from 'antd'
|
||||
|
||||
const App = React.createClass({
|
||||
getInitialState: function () {
|
||||
return {
|
||||
loading: true,
|
||||
login: false,
|
||||
userName: '未登录',
|
||||
}
|
||||
},
|
||||
componentWillMount() {
|
||||
|
||||
},
|
||||
componentDidMount(){
|
||||
if (!this.state.login) {
|
||||
const hide = message.loading('正在获取用户信息...', 0)
|
||||
ajax.get(`${config.getAPIPath()}${config.login.getCurrentUser}`).end((err, res) => {
|
||||
if (ajax.isSuccess(res) && !config.debug) {
|
||||
hide()
|
||||
this.loginSuccess(res.body.data)
|
||||
} else {
|
||||
if (config.isSSO()) {
|
||||
hide()
|
||||
// logger.debug('not login, redirect to SSO login page')
|
||||
const redirect = encodeURIComponent(window.location.href)
|
||||
window.location.href = `${config.login.sso}${redirect}`
|
||||
} else {
|
||||
hide()
|
||||
message.error('获取用户信息失败, 请重新登录')
|
||||
// logger.debug('not login, redirect to Login component')
|
||||
this.setState({loading: false, login: false})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
render(){
|
||||
if (this.state.loading) {
|
||||
return <Spin spinning={this.state.loading} size="large"/>;
|
||||
}
|
||||
|
||||
if (!this.state.login) {
|
||||
return <SignIn loginSuccess={this.loginSuccess}/>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="ant-layout-aside">
|
||||
<Sidebar/>
|
||||
<div id="main-content-div" className="ant-layout-main">
|
||||
<Spin spinning={this.state.loading} size="large">
|
||||
<Header userName={this.state.userName}/>
|
||||
<Breadcrumb {...this.props} />
|
||||
<div className="ant-layout-container">
|
||||
<div className="ant-layout-content">
|
||||
{this.state.loading ? '' : this.props.children}
|
||||
</div>
|
||||
</div>
|
||||
<Footer/>
|
||||
</Spin>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = App
|
||||
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import {ajax,config,logger} from '../../utils/lib';
|
||||
import {message} from 'antd';
|
||||
import './signIn.less';
|
||||
|
||||
const SignIn = React.createClass({
|
||||
render(){
|
||||
return (
|
||||
<div className="ant-layout-logo">
|
||||
<div className="logo-text">
|
||||
66666
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = SignIn;
|
||||
Reference in New Issue
Block a user