diff --git a/a.less b/a.less deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index 26bacc9..dbf9484 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "prod": "NODE_ENV=production webpack --progress --colors --config webpack.config.prod.js -p --display-error-details", "clean": "rm dist/bundle*", "dev": "webpack-dev-server --devtool eval --progress --colors --content-base dist --hot --inline --display-error-details", - "eslint": "eslint --ext .js,.jsx src", + "eslint": "eslint --ext .js,.jsx src/view", "stylelint": "stylelint \"src/**/*.css\"", "lesshint": "lesshint src/" } diff --git a/src/view/index.js b/src/view/index.js index 90c3b8a..0e1ae4e 100644 --- a/src/view/index.js +++ b/src/view/index.js @@ -4,13 +4,12 @@ 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' +import { ajax, config, logger } from '../utils/lib.js' +import { Spin, message } from 'antd' const App = React.createClass({ - getInitialState: function () { + getInitialState() { return { // loading: true, // login: false, @@ -19,10 +18,7 @@ const App = React.createClass({ userName: '未登录', } }, - componentWillMount() { - - }, - componentDidMount(){ + componentDidMount() { if (!this.state.login) { const hide = message.loading('正在获取用户信息...', 0) ajax.get(`${config.getAPIPath()}${config.login.getCurrentUser}`).end((err, res) => { @@ -39,43 +35,52 @@ const App = React.createClass({ hide() message.error('获取用户信息失败, 请重新登录') logger.debug('not login, redirect to Login component') - this.setState({loading: false, login: false}) + this.setState({ + loading: false, + login: false, + }) } } }) } }, - loginSuccess (name, showMsg){ + loginSuccess(name, showMsg) { logger.debug('callback logingSuccess, name = %s', name) - if (showMsg) + if (showMsg) { message.success('登录成功') - this.setState({loading: false, login: true, userName: name}) - }, - render(){ - if (this.state.loading) { - return - } else if (!this.state.login) { - return } - + this.setState({ + loading: false, + login: true, + userName: name, + }) + }, + render() { + if (this.state.loading) { + return ( + + ) + } else 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 index cf5c81e..169ab3a 100644 --- a/src/view/user/signIn.js +++ b/src/view/user/signIn.js @@ -1,77 +1,78 @@ import React from 'react' import ReactDOM from 'react-dom' import { ajax, config, logger } from '../../utils/lib' -import { Icon, message, Button, Row, Col, Form, Input, Select} from 'antd' +import { Icon, message, Button, Row, Col, Form, Input, Select } from 'antd' import './signIn.less' const FormItem = Form.Item let SignIn = React.createClass({ - getInitialState(){ + getInitialState() { return { - loading: false + loading: false, } }, - handleSubmit(e){ - var _this = this + handleSubmit(e) { + const _this = this e.preventDefault() this.props.form.validateFieldsAndScroll((errors, values) => { if (!!errors) { return } - ajax.post(`${config.getAPIPath()}${config.login.validate}`).type('form').send(values).end((err, res) => { + ajax.post(`${config.getAPIPath()}${config.login.validate}`) + .type('form').send(values).end((err, res) => { if (ajax.isSuccess(res)) { - if (this.props.loginSuccess) + if (this.props.loginSuccess) { this.props.loginSuccess(res.body.data, true) - else + } else { message.info(`登录成功, 用户名: ${res.body.data}`) + } } else { - message.error(`登录失败: ${res.body.message}, 请联系管理员`) + message.error(`登录失败: ${res.body.message}, 请联系管理员`) } }) }) }, - render(){ + render() { const { getFieldProps } = this.props.form const username = getFieldProps('username', { rules: [ - {required: true, message: '不能为空'} - ] + { + required: true, + message: '不能为空', + }, + ], }) const password = getFieldProps('password', { rules: [ - {required: true, message: '不能为空'} - ] + { + required: true, + message: '不能为空', + }, + ], }) return ( - + Ant Design - - + + - - + + - 登录 + + 登录 + ) - } + }, }) SignIn = Form.create()(SignIn)