diff --git a/src/index.js b/src/index.js index 50e7fc0..cdbec6a 100644 --- a/src/index.js +++ b/src/index.js @@ -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 = ( @@ -48,9 +47,7 @@ const routes = ( - - ); diff --git a/src/utils/lib.js b/src/utils/lib.js new file mode 100644 index 0000000..f767aa9 --- /dev/null +++ b/src/utils/lib.js @@ -0,0 +1,5 @@ +import config from 'config'; +import ajax from './ajax'; +import logger from './Logger'; + +module.exports = {ajax,config,logger}; diff --git a/src/view/index.js b/src/view/index.js new file mode 100644 index 0000000..e99ffd6 --- /dev/null +++ b/src/view/index.js @@ -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 ; + } + + if (!this.state.login) { + return ; + } + + return ( +
+ +
+ +
+ +
+
+ {this.state.loading ? '' : this.props.children} +
+
+
+ +
+
+ ) + } +}) + +module.exports = App diff --git a/src/view/user/signIn.js b/src/view/user/signIn.js new file mode 100644 index 0000000..569e89b --- /dev/null +++ b/src/view/user/signIn.js @@ -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 ( +
+
+ 66666 +
+
+ ); + } +}) + +module.exports = SignIn; diff --git a/src/view/user/signIn.less b/src/view/user/signIn.less new file mode 100644 index 0000000..e69de29