| | |
| | | import React from 'react'; |
| | | import { Input, Button, Space, Select } from 'antd'; |
| | | |
| | | const NONE_OPTION = -9999; |
| | | |
| | | const TextFilter = (props) => { |
| | | return ( |
| | | <div style={{ padding: 8 }}> |
| | | <Input |
| | | style={{ width: 188, marginBottom: 8, display: 'block' }} |
| | | placeholder="请输入" |
| | | value={props.selectedKeys[0]} |
| | | onChange={e => { |
| | | props.setSelectedKeys(e.target.value ? [e.target.value] : []) |
| | |
| | | } |
| | | |
| | | const SelectFilter = (props) => { |
| | | const NONE_OPTION = -9999; |
| | | const [currentOption, setCurrentOption] = React.useState(); |
| | | |
| | | return ( |
| | | <div style={{ padding: 8 }}> |
| | | <div> |
| | | <Select |
| | | style={{ width: 188, marginBottom: 8 }} |
| | | placeholder="选择一个选项" |
| | | value={props.selectedKeys[0]} |
| | | onChange={value => props.setSelectedKeys(value ? [value] : [])} |
| | | style={{ width: 188, marginBottom: 8, display: 'block' }} |
| | | placeholder="请选择" |
| | | value={currentOption === NONE_OPTION ? undefined : currentOption} |
| | | onChange={value => { |
| | | setCurrentOption(value) |
| | | props.setSelectedKeys(value !== undefined && value !== null ? [value] : []); |
| | | }} |
| | | > |
| | | {props.data.map(item => ( |
| | | <Select.Option key={item.value} value={item.value}> |
| | |
| | | </Select.Option> |
| | | ))} |
| | | </Select> |
| | | </div> |
| | | <Space> |
| | | <Button |
| | | type="primary" |
| | | onClick={() => { |
| | | props.confirm(); |
| | | if (currentOption === NONE_OPTION) { |
| | | props.setSearchParam(prevState => { |
| | | const state = { ...prevState }; |
| | | delete state[props.name]; |
| | | return state; |
| | | }) |
| | | } else { |
| | | props.setSearchParam(prevState => ({ |
| | | ...prevState, |
| | | [props.name]: props.selectedKeys[0] |
| | | [props.name]: currentOption |
| | | })); |
| | | } |
| | | props.actionRef.current?.reload(); |
| | | }} |
| | | size="small" |
| | |
| | | </Button> |
| | | <Button |
| | | onClick={() => { |
| | | setSelectedKeys([]); |
| | | clearFilters(); |
| | | setCurrentOption(NONE_OPTION) |
| | | props.setSelectedKeys([]); |
| | | props.clearFilters(); |
| | | }} |
| | | size="small" |
| | | style={{ width: 90 }} |