-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
330 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Form, Button, Row, Col } from 'antd'; | ||
import omit from 'omit.js'; | ||
import styles from './index.less'; | ||
import map from './map'; | ||
|
||
const FormItem = Form.Item; | ||
|
||
function generator({ defaultProps, defaultRules, type }) { | ||
return (WrappedComponent) => { | ||
return class BasicComponent extends Component { | ||
static contextTypes = { | ||
form: PropTypes.object, | ||
updateActive: PropTypes.func, | ||
}; | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
count: 0, | ||
}; | ||
} | ||
componentDidMount() { | ||
if (this.context.updateActive) { | ||
this.context.updateActive(this.props.itemKey); | ||
} | ||
} | ||
componentWillUnmount() { | ||
clearInterval(this.interval); | ||
} | ||
onGetCaptcha = () => { | ||
let count = 59; | ||
this.setState({ count }); | ||
if (this.props.onGetCaptcha) { | ||
this.props.onGetCaptcha(); | ||
} | ||
this.interval = setInterval(() => { | ||
count -= 1; | ||
this.setState({ count }); | ||
if (count === 0) { | ||
clearInterval(this.interval); | ||
} | ||
}, 1000); | ||
} | ||
render() { | ||
const { getFieldDecorator } = this.context.form; | ||
const options = {}; | ||
let otherProps = {}; | ||
const { onChange, defaultValue, rules, itemKey, ...restProps } = this.props; | ||
const { count } = this.state; | ||
options.rules = rules || defaultRules; | ||
if (onChange) { | ||
options.onChange = onChange; | ||
} | ||
if (defaultValue) { | ||
options.initialValue = defaultValue; | ||
} | ||
otherProps = restProps || otherProps; | ||
if (type === 'Captcha') { | ||
const inputProps = omit(otherProps, ['onGetCaptcha']); | ||
return ( | ||
<FormItem> | ||
<Row gutter={8}> | ||
<Col span={16}> | ||
{getFieldDecorator(itemKey, options)( | ||
<WrappedComponent {...defaultProps} {...inputProps} /> | ||
)} | ||
</Col> | ||
<Col span={8}> | ||
<Button | ||
disabled={count} | ||
className={styles.getCaptcha} | ||
size="large" | ||
onClick={this.onGetCaptcha} | ||
> | ||
{count ? `${count} s` : '获取验证码'} | ||
</Button> | ||
</Col> | ||
</Row> | ||
</FormItem> | ||
); | ||
} | ||
return ( | ||
<FormItem> | ||
{getFieldDecorator(itemKey, options)( | ||
<WrappedComponent {...defaultProps} {...otherProps} /> | ||
)} | ||
</FormItem> | ||
); | ||
} | ||
}; | ||
}; | ||
} | ||
|
||
const LoginItem = {}; | ||
Object.keys(map).forEach((item) => { | ||
LoginItem[item] = generator({ | ||
defaultProps: map[item].props, | ||
defaultRules: map[item].rules, | ||
type: item, | ||
})(map[item].component); | ||
}); | ||
|
||
export default LoginItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { Button, Form } from 'antd'; | ||
import styles from './index.less'; | ||
|
||
const FormItem = Form.Item; | ||
|
||
export default ({ className, ...rest }) => { | ||
const clsString = classNames(styles.submit, className); | ||
return ( | ||
<FormItem> | ||
<Button size="large" className={clsString} type="primary" htmlType="submit" {...rest} /> | ||
</FormItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Tabs } from 'antd'; | ||
|
||
const { TabPane } = Tabs; | ||
|
||
const generateId = (() => { | ||
let i = 0; | ||
return (prefix: string = '') => { | ||
i += 1; | ||
return `${prefix}${i}`; | ||
}; | ||
})(); | ||
|
||
export default class LoginTab extends Component { | ||
static contextTypes = { | ||
tabUtil: PropTypes.object, | ||
}; | ||
constructor(props) { | ||
super(props); | ||
this.uniqueId = generateId('login-tab-'); | ||
} | ||
componentWillMount() { | ||
if (this.context.tabUtil) { | ||
this.context.tabUtil.addTab(this.uniqueId); | ||
} | ||
} | ||
render() { | ||
const { tab, children, ...restProps } = this.props; | ||
return ( | ||
<TabPane tab={tab} {...restProps}>{ children }</TabPane> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.