|
|
@ -3,13 +3,43 @@ import { Button, Input } from 'antd'; |
|
|
|
|
|
|
|
|
import styles from './index.less'; |
|
|
import styles from './index.less'; |
|
|
|
|
|
|
|
|
export default ({ onSearch = () => ({}), text = '搜索', ...reset }) => ( |
|
|
export default class SearchInput extends React.Component { |
|
|
<div className={styles.search}> |
|
|
state = { |
|
|
<Input |
|
|
value: this.props.defaultValue, |
|
|
placeholder="请输入" |
|
|
} |
|
|
size="large" |
|
|
|
|
|
{...reset} |
|
|
handleOnChange = (e) => { |
|
|
addonAfter={<Button onClick={onSearch} type="primary">{text}</Button>} |
|
|
this.setState({ |
|
|
/> |
|
|
value: e.target.value, |
|
|
</div> |
|
|
}); |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleOnSearch = () => { |
|
|
|
|
|
if (this.props.onSearch) { |
|
|
|
|
|
this.props.onSearch(this.state.value); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleOnKey = (e) => { |
|
|
|
|
|
if (e.keyCode === 13) { |
|
|
|
|
|
this.handleOnSearch(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
|
const { text = '搜索', reset } = this.props; |
|
|
|
|
|
return ( |
|
|
|
|
|
<div className={styles.search}> |
|
|
|
|
|
<Input |
|
|
|
|
|
onKeyDown={this.handleOnKey} |
|
|
|
|
|
placeholder="请输入" |
|
|
|
|
|
size="large" |
|
|
|
|
|
{...reset} |
|
|
|
|
|
value={this.state.value} |
|
|
|
|
|
onChange={this.handleOnChange} |
|
|
|
|
|
addonAfter={<Button onClick={this.handleOnSearch} type="primary">{text}</Button>} |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|