Skip to content

Commit

Permalink
fix: no result will cauth buzy
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Jul 10, 2021
1 parent 719fb82 commit d44277a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
}
23 changes: 17 additions & 6 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export default class ReactAntGeoInput extends Component {
* The change handler.
*/
onChange: PropTypes.func,
/**
* The handler when has error caught.
*/
onError: PropTypes.func,
/**
* If lat/lng should be editalbe.
*/
Expand All @@ -56,6 +60,7 @@ export default class ReactAntGeoInput extends Component {

static defaultProps = {
onChange: noop,
onError: noop,
readOnly: false,
appKey: '5Q5BZ-5EVWJ-SN5F3-K6QBZ-B3FAO-RVBWM',
secretKey: 'SWvT26ypwq5Nwb5RvS8cLi6NSoH8HlJX'
Expand Down Expand Up @@ -87,19 +92,25 @@ export default class ReactAntGeoInput extends Component {
}

handleSearch = (inValue) => {
const { appKey, secretKey, onChange } = this.props;
const { appKey, secretKey, onChange, onError } = this.props;
const path = `/ws/geocoder/v1?key=${appKey}&address=${inValue}`;
const sig = md5(path + secretKey);
const url = `/ws/geocoder/v1?key=${appKey}&address=${inValue}&sig=${sig}`;
this.setState({ busy: true });
fetch(url)
.then((res) => res.json())
.then((res) => {
const { location } = res.result;
this.setState({ ...location, busy: false });
onChange({
target: { value: { ...location, value: inValue } }
});
let location = { lat: 0, lng: 0 };
if (res.status !== 0) {
onError({ target: { value: 'nodata' } });
} else {
location = res.result.location;
}
this.setState(location);
onChange({ target: { value: { ...location, value: inValue } } });
})
.finally(() => {
this.setState({ busy: false });
});
};

Expand Down

0 comments on commit d44277a

Please sign in to comment.