提交 123a2bb8 作者: 龚洪江

修复:地图选点问题

上级 911f94e1
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<script type="module" src="/src/main.tsx"></script> <script type="module" src="/src/main.tsx"></script>
<script type="text/javascript" > <script type="text/javascript" >
window._AMapSecurityConfig = { window._AMapSecurityConfig = {
securityJsCode:'a9cd5c6e4eb563b65884efc14759d6a1', securityJsCode:'e3e2af73906d447a776b1d5b59e9a046',
} }
</script> </script>
</body> </body>
......
...@@ -43,6 +43,7 @@ service.interceptors.response.use( ...@@ -43,6 +43,7 @@ service.interceptors.response.use(
if (['605', '603', '602', '4004', '607', '2014', '2013', '5008'].includes(data.code)) { if (['605', '603', '602', '4004', '607', '2014', '2013', '5008'].includes(data.code)) {
message.error(data.message).then(); message.error(data.message).then();
Cookies.remove('SHAREFLY-TOKEN'); Cookies.remove('SHAREFLY-TOKEN');
localStorage.removeItem('roleId');
setTimeout(() => { setTimeout(() => {
window.location.reload(); window.location.reload();
}, 1000); }, 1000);
......
...@@ -15,6 +15,8 @@ const SelectMapModal: FC<propType> = (props) => { ...@@ -15,6 +15,8 @@ const SelectMapModal: FC<propType> = (props) => {
SelectMapModal.defaultProps = { SelectMapModal.defaultProps = {
title: '选择地点', title: '选择地点',
}; };
//筛选值
const [searchKey, setSearchKey] = useState<string>('');
// 参数 // 参数
const { title, open, closed, submit } = props; const { title, open, closed, submit } = props;
// 子组件事件 // 子组件事件
...@@ -31,7 +33,8 @@ const SelectMapModal: FC<propType> = (props) => { ...@@ -31,7 +33,8 @@ const SelectMapModal: FC<propType> = (props) => {
adCode: number; adCode: number;
}>(); }>();
// 搜索地点 // 搜索地点
const [addressList, setAddressList] = useState<{ label: string; value: number; data: any }[]>(); const [addressList, setAddressList] =
useState<{ label: string; value: number; data: any; searchKey: string }[]>();
// 取消事件 // 取消事件
const handleCancel = () => { const handleCancel = () => {
setPosition(undefined); setPosition(undefined);
...@@ -44,6 +47,7 @@ const SelectMapModal: FC<propType> = (props) => { ...@@ -44,6 +47,7 @@ const SelectMapModal: FC<propType> = (props) => {
}; };
// 搜索地点 // 搜索地点
const handleSearch = (e: string) => { const handleSearch = (e: string) => {
setSearchKey(e || '');
if (e) { if (e) {
childRef.current?.onSearch(e); childRef.current?.onSearch(e);
} else { } else {
...@@ -54,8 +58,7 @@ const SelectMapModal: FC<propType> = (props) => { ...@@ -54,8 +58,7 @@ const SelectMapModal: FC<propType> = (props) => {
const handleSearchDebounced = debounce(handleSearch, 500); const handleSearchDebounced = debounce(handleSearch, 500);
// 选择了地址 // 选择了地址
const handleSearchAddress = (e: number) => { const handleSearchAddress = (e: number) => {
if (e) { if (!isNaN(e)) {
console.log(addressList?.[e].data);
// eslint-disable-next-line no-unsafe-optional-chaining // eslint-disable-next-line no-unsafe-optional-chaining
const { lat, lng } = addressList?.[e].data.location; const { lat, lng } = addressList?.[e].data.location;
childRef.current?.addMarker({ lat, lng }); childRef.current?.addMarker({ lat, lng });
...@@ -96,7 +99,7 @@ const SelectMapModal: FC<propType> = (props) => { ...@@ -96,7 +99,7 @@ const SelectMapModal: FC<propType> = (props) => {
allowClear allowClear
onSearch={handleSearchDebounced} onSearch={handleSearchDebounced}
filterOption={(input, option) => filterOption={(input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()) (option?.searchKey ?? '').toLowerCase().includes(input.toLowerCase())
} }
options={addressList} options={addressList}
onChange={handleSearchAddress} onChange={handleSearchAddress}
...@@ -115,7 +118,8 @@ const SelectMapModal: FC<propType> = (props) => { ...@@ -115,7 +118,8 @@ const SelectMapModal: FC<propType> = (props) => {
}); });
}} }}
onSearchAddress={(e) => { onSearchAddress={(e) => {
setAddressList(e.map((i, j) => ({ label: i.name, value: j, data: i }))); console.log('筛选e--->', e);
setAddressList(e.map((i, j) => ({ label: i.name, value: j, data: i, searchKey })));
}} }}
></MapComponent> ></MapComponent>
<div <div
......
...@@ -45,7 +45,7 @@ class MapComponent extends Component<MapComponentProps> { ...@@ -45,7 +45,7 @@ class MapComponent extends Component<MapComponentProps> {
// dom渲染成功后进行map对象的创建 // dom渲染成功后进行map对象的创建
componentDidMount() { componentDidMount() {
AMapLoader.load({ AMapLoader.load({
key: '7a3a24e85672c06ab466d790fb5d38a3', // 申请好的Web端开发者Key,首次调用 load 时必填 key: '5d75700ddef48d1c3d2de349e3dd260c', // 申请好的Web端开发者Key,首次调用 load 时必填
version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15 version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等 plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
}) })
...@@ -93,7 +93,6 @@ class MapComponent extends Component<MapComponentProps> { ...@@ -93,7 +93,6 @@ class MapComponent extends Component<MapComponentProps> {
if (status === 'complete' && result.info === 'OK') { if (status === 'complete' && result.info === 'OK') {
// result为对应的地理位置详细信息 // result为对应的地理位置详细信息
const { formattedAddress, addressComponent } = result.regeocode; const { formattedAddress, addressComponent } = result.regeocode;
console.log('点击选择-->', status, result);
this.props.onSelectAddress({ this.props.onSelectAddress({
lat, lat,
lng, lng,
...@@ -115,6 +114,7 @@ class MapComponent extends Component<MapComponentProps> { ...@@ -115,6 +114,7 @@ class MapComponent extends Component<MapComponentProps> {
onSearch(keyword: string) { onSearch(keyword: string) {
// 根据关键字进行搜索 // 根据关键字进行搜索
this.autoComplete.search(keyword, (status, result) => { this.autoComplete.search(keyword, (status, result) => {
console.log('搜索结果-->', result);
// 搜索成功时,result即是对应的匹配数据 // 搜索成功时,result即是对应的匹配数据
if (status === 'complete' && result.info === 'OK') { if (status === 'complete' && result.info === 'OK') {
this.props.onSearchAddress(result.tips); this.props.onSearchAddress(result.tips);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论