From 19795b9b11fb32d9eccd1fa5e1febb5776d4218b Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Wed, 10 Jun 2020 20:32:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85className?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AssociatedCheckboxes.tsx | 2 +- src/components/BaiduMapPicker.tsx | 194 +++++++++++++++--------- src/components/ImageGallery.tsx | 10 +- src/components/LocationPicker.tsx | 2 +- src/components/ResultBox.tsx | 2 +- src/components/ResultList.tsx | 7 +- src/components/Transfer.tsx | 2 +- src/renderers/Form/Combo.tsx | 2 +- src/renderers/List.tsx | 2 +- src/renderers/Status.tsx | 5 +- 10 files changed, 140 insertions(+), 88 deletions(-) diff --git a/src/components/AssociatedCheckboxes.tsx b/src/components/AssociatedCheckboxes.tsx index 2616c71e..58386582 100644 --- a/src/components/AssociatedCheckboxes.tsx +++ b/src/components/AssociatedCheckboxes.tsx @@ -153,7 +153,7 @@ export class AssociatedCheckboxes extends BaseCheckboxes< : this.handleRetry.bind(this, selectdOption) } > - + {selectdOption.loading ? ( diff --git a/src/components/BaiduMapPicker.tsx b/src/components/BaiduMapPicker.tsx index 0f29e454..41f5ce16 100644 --- a/src/components/BaiduMapPicker.tsx +++ b/src/components/BaiduMapPicker.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {ClassNamesFn, themeable} from '../theme'; import {Icon} from '..'; import {loadScript, autobind, uuid} from '../utils/helper'; -import { threadId } from 'worker_threads'; +import {threadId} from 'worker_threads'; import debounce from 'lodash/debounce'; declare const BMap: any; @@ -43,7 +43,7 @@ export class BaiduMapPicker extends React.Component< inputValue: '', locs: [], locIndex: -1, - sugs: [], + sugs: [] }; id = uuid(); @@ -51,27 +51,29 @@ export class BaiduMapPicker extends React.Component< placeholderInput: HTMLInputElement; map: any; ac: any; - search = debounce(() => { - if (this.state.inputValue) { - this.ac?.search(this.state.inputValue); - } else { - this.setState({ - sugs: [] - }) + search = debounce( + () => { + if (this.state.inputValue) { + this.ac?.search(this.state.inputValue); + } else { + this.setState({ + sugs: [] + }); + } + }, + 250, + { + trailing: true, + leading: false } - }, 250, { - trailing: true, - leading: false - }); + ); componentDidMount() { if ((window as any).BMap) { this.initMap(); } else { loadScript( - `http://api.map.baidu.com/api?v=2.0&ak=${ - this.props.ak - }&callback={{callback}}` + `http://api.map.baidu.com/api?v=2.0&ak=${this.props.ak}&callback={{callback}}` ).then(this.initMap); } } @@ -91,7 +93,9 @@ export class BaiduMapPicker extends React.Component< this.map = map; const value = this.props.value; - let point = value ? new BMap.Point(value.lng, value.lat) : new BMap.Point(116.404, 39.915); + let point = value + ? new BMap.Point(value.lng, value.lat) + : new BMap.Point(116.404, 39.915); map.centerAndZoom(point, 15); const geolocationControl = new BMap.GeolocationControl(); @@ -112,16 +116,26 @@ export class BaiduMapPicker extends React.Component< this.ac = new BMap.Autocomplete({ input, location: map, - onSearchComplete: (e:any) => { + onSearchComplete: (e: any) => { // 说明已经销毁了。 if (!this.map) { return; } - - const sugs:Array = []; + + const sugs: Array = []; if (Array.isArray(e.Ir)) { - e.Ir.forEach((item:any) => { - sugs.push([item.province, item.city, item.district, item.street, item.business].filter(item => item).join(' ')) + e.Ir.forEach((item: any) => { + sugs.push( + [ + item.province, + item.city, + item.district, + item.street, + item.business + ] + .filter(item => item) + .join(' ') + ); }); this.setState({ @@ -172,53 +186,62 @@ export class BaiduMapPicker extends React.Component< }); } - this.setState({ - locIndex: index, - locs - }, () => { - if (!select) { - return; - } + this.setState( + { + locIndex: index, + locs + }, + () => { + if (!select) { + return; + } - this.props?.onChange({ - address: locs[0].address, - lat: locs[0].lat, - lng: locs[0].lng, - city: locs[0].city - }) - }); + this.props?.onChange({ + address: locs[0].address, + lat: locs[0].lat, + lng: locs[0].lng, + city: locs[0].city + }); + } + ); }); } @autobind handleChange(e: React.ChangeEvent) { - this.setState({ - inputValue: e.currentTarget.value - }, this.search); + this.setState( + { + inputValue: e.currentTarget.value + }, + this.search + ); } @autobind handleSelect(e: React.MouseEvent) { - const index= parseInt(e.currentTarget.getAttribute('data-index')!, 10); + const index = parseInt(e.currentTarget.getAttribute('data-index')!, 10); const loc = this.state.locs[index]; - this.setState({ - locIndex: index - }, () => { - const point = new BMap.Point(loc.lng, loc.lat); - - this.map.clearOverlays(); - const mk = new BMap.Marker(point); - this.map.addOverlay(mk); - this.map.panTo(point); + this.setState( + { + locIndex: index + }, + () => { + const point = new BMap.Point(loc.lng, loc.lat); - this.props?.onChange({ - address: loc.address.trim() || loc.title, - lat: loc.lat, - lng: loc.lng, - city: loc.city - }) - }) + this.map.clearOverlays(); + const mk = new BMap.Marker(point); + this.map.addOverlay(mk); + this.map.panTo(point); + + this.props?.onChange({ + address: loc.address.trim() || loc.title, + lat: loc.lat, + lng: loc.lng, + city: loc.city + }); + } + ); } @autobind @@ -228,18 +251,19 @@ export class BaiduMapPicker extends React.Component< inputValue: value }); - var local = new BMap.LocalSearch(this.map, { //智能搜索 - onSearchComplete: () => { + var local = new BMap.LocalSearch(this.map, { + //智能搜索 + onSearchComplete: () => { const results = local.getResults(); const poi = results.getPoi(0); this.setState({ inputValue: poi.title, sugs: [] }); - this.getLocations(poi.point, true) + this.getLocations(poi.point, true); } - }); - local.search(value); + }); + local.search(value); } render() { @@ -251,34 +275,56 @@ export class BaiduMapPicker extends React.Component<
- + - +
-
+
-
+
{locs.map((item, index) => ( -
+
{item.title}
{item.address}
- {locIndex === index ? : null} + {locIndex === index ? ( + + ) : null}
))}
{hasSug ? (
- {sugs.map(item => -
{item}
- )} + {sugs.map(item => ( +
+ {item} +
+ ))}
) : null}
diff --git a/src/components/ImageGallery.tsx b/src/components/ImageGallery.tsx index e824f22b..7959c59a 100644 --- a/src/components/ImageGallery.tsx +++ b/src/components/ImageGallery.tsx @@ -108,7 +108,7 @@ export class ImageGallery extends React.Component< className={cx('ImageGallery-close')} onClick={this.close} > - + {~index && items[index] ? ( <> @@ -127,7 +127,7 @@ export class ImageGallery extends React.Component< )} onClick={this.prev} > - + - + ) : null} @@ -146,7 +146,7 @@ export class ImageGallery extends React.Component< {items.length > 1 ? (
- +
@@ -166,7 +166,7 @@ export class ImageGallery extends React.Component<
- +
) : null} diff --git a/src/components/LocationPicker.tsx b/src/components/LocationPicker.tsx index 0ebef28f..4f2a2f87 100644 --- a/src/components/LocationPicker.tsx +++ b/src/components/LocationPicker.tsx @@ -172,7 +172,7 @@ export class LocationPicker extends React.Component< ) : null} - + { {itemRender(item)} - +
)) diff --git a/src/components/ResultList.tsx b/src/components/ResultList.tsx index 7e371987..67c7686a 100644 --- a/src/components/ResultList.tsx +++ b/src/components/ResultList.tsx @@ -144,7 +144,10 @@ export class ResultList extends React.Component { key={index} > {sortable && !disabled && value.length > 1 ? ( - + ) : null} @@ -155,7 +158,7 @@ export class ResultList extends React.Component { data-index={index} onClick={this.handleRemove} > - + ) : null}
diff --git a/src/components/Transfer.tsx b/src/components/Transfer.tsx index e1961f79..dd0fe7bb 100644 --- a/src/components/Transfer.tsx +++ b/src/components/Transfer.tsx @@ -418,7 +418,7 @@ export class Transfer extends React.Component {
{showArrow /*todo 需要改成确认模式,即:点了按钮才到右边 */ ? (
- +
) : null}
diff --git a/src/renderers/Form/Combo.tsx b/src/renderers/Form/Combo.tsx index 60b9ab2c..9236c6f2 100644 --- a/src/renderers/Form/Combo.tsx +++ b/src/renderers/Form/Combo.tsx @@ -1054,7 +1054,7 @@ export default class ComboControl extends React.Component { {dragIcon ? ( ) : ( - + )}
diff --git a/src/renderers/List.tsx b/src/renderers/List.tsx index e1178bca..1760b439 100644 --- a/src/renderers/List.tsx +++ b/src/renderers/List.tsx @@ -894,7 +894,7 @@ export class ListItem extends React.Component { if (dragging) { return (
- +
); } else if (selectable && !hideCheckToggler) { diff --git a/src/renderers/Status.tsx b/src/renderers/Status.tsx index 4f9a09f6..fc2e63ec 100644 --- a/src/renderers/Status.tsx +++ b/src/renderers/Status.tsx @@ -69,7 +69,10 @@ export class StatusField extends React.Component { if (svgIcon) { viewValue = ( - + ); } else if (itemClassName) { viewValue = (