| | |
| | | import React from 'react'; |
| | | import { Input, Button, Space, Select, DatePicker } from 'antd'; |
| | | import moment from 'moment'; |
| | | import Http from '@/utils/http'; |
| | | |
| | | const NONE_OPTION = -9999; |
| | | |
| | |
| | | ); |
| | | } |
| | | |
| | | const LinkFilter = (props) => { |
| | | const [currentOption, setCurrentOption] = React.useState(); |
| | | const [options, setOptions] = React.useState([]); |
| | | |
| | | export { TextFilter, SelectFilter, DatetimeRangeFilter }; |
| | | const handleSearch = async (value) => { |
| | | if (value) { |
| | | const resp = await Http.doPostForm(`api/${props.name}/query`, { condition: value }); |
| | | setOptions(resp.data); |
| | | } else { |
| | | setOptions([]); |
| | | } |
| | | } |
| | | |
| | | return ( |
| | | <div style={{ padding: 8 }}> |
| | | <div> |
| | | <Select |
| | | 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] : []); |
| | | }} |
| | | onSearch={handleSearch} |
| | | showSearch={true} |
| | | debounceTime={300} |
| | | > |
| | | {options.map(item => ( |
| | | <Select.Option key={item.value} value={item.value}> |
| | | {item.label} |
| | | </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]: currentOption |
| | | })); |
| | | } |
| | | props.actionRef.current?.reload(); |
| | | }} |
| | | size="small" |
| | | style={{ width: 90 }} |
| | | > |
| | | 确定 |
| | | </Button> |
| | | <Button |
| | | onClick={() => { |
| | | setCurrentOption(NONE_OPTION) |
| | | props.setSelectedKeys([]); |
| | | props.clearFilters(); |
| | | }} |
| | | size="small" |
| | | style={{ width: 90 }} |
| | | > |
| | | 重置 |
| | | </Button> |
| | | </Space> |
| | | </div> |
| | | ); |
| | | } |
| | | |
| | | |
| | | export { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter }; |