|
|
|
@ -91,7 +91,7 @@ class SearchInput extends React.Component {
|
|
|
|
|
// const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {});
|
|
|
|
|
const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: typeof map[v] === 'string' ? { key: map[v] } : (map[v] || []).map(vi => ({ key: vi})) }), {});
|
|
|
|
|
|
|
|
|
|
if (value || !isEmpty(param)) {
|
|
|
|
|
if ((value && this.state.data.length === 0) || !isEmpty(param)) {
|
|
|
|
|
curl({ value, url: this.props.url || '', map: mapKey, resultkey, param }, (data) =>
|
|
|
|
|
this.setState({ data }, () => (typeof this.props.onSearchAfter === 'function' ? this.props.onSearchAfter(data, this.state.value) : ''))
|
|
|
|
|
);
|
|
|
|
@ -104,6 +104,10 @@ class SearchInput extends React.Component {
|
|
|
|
|
this.setState({ value }, () => this.props.onChange(value, option));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleFilter = (value, option) => {
|
|
|
|
|
return String(option?.children || option?.label || option?.value || '').toLowerCase().includes(value.toLowerCase());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const options = this.state.data.map(d => <Option key={d.key} extradata={d.options}>{d.label}</Option>);
|
|
|
|
|
const { onSearchAfter, defaultOptions, autoGet, dependenciesFun, ...props } = this.props;
|
|
|
|
@ -117,7 +121,7 @@ class SearchInput extends React.Component {
|
|
|
|
|
placeholder={this.props.placeholder}
|
|
|
|
|
defaultActiveFirstOption={false}
|
|
|
|
|
showArrow={false}
|
|
|
|
|
filterOption={false}
|
|
|
|
|
filterOption={this.handleFilter}
|
|
|
|
|
onSearch={this.handleSearch}
|
|
|
|
|
onChange={this.handleChange}
|
|
|
|
|
onFocus={() => this.handleSearch('')}
|
|
|
|
|