andrew před 4 roky
rodič
revize
17bc13b2cb

binární
estateagents-admin-manager/src/assets/xiaochengxu.png Zobrazit soubor


binární
estateagents-admin-manager/src/assets/yinhao.png Zobrazit soubor


+ 128
- 0
estateagents-admin-manager/src/components/AMap/AMapSearch.jsx Zobrazit soubor

@@ -0,0 +1,128 @@
1
+import React from 'react';
2
+import ReactDOM from 'react-dom';
3
+import { Map, Marker } from 'react-amap'
4
+import debounce from 'lodash.debounce'
5
+import styles from './style.less'
6
+
7
+const getPosFromProps = props => {
8
+  if (props.value) {
9
+    const temp = props.value.split(',')
10
+    return { longitude: temp[0], latitude: temp[1] }
11
+  } else {
12
+    return null
13
+  }
14
+}
15
+
16
+class AMapSearch extends React.PureComponent {
17
+
18
+  constructor(props) {
19
+    super(props);
20
+    this.state = {
21
+      markerPosition: getPosFromProps(props),
22
+    }
23
+
24
+    // 高德地图 Marker 实例
25
+    this.markerInstance = undefined
26
+    // 高德地图 Map 实例
27
+    this.mapInstance = undefined
28
+
29
+    this.amapEvents = {
30
+      created: mapInstance => {
31
+        this.mapInstance = mapInstance
32
+        
33
+        AMap.plugin(['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.CitySearch'], () => {
34
+          // 实例化Autocomplete
35
+          const autoOptions = { input: 'amapInput' }
36
+          const autoComplete = new AMap.Autocomplete(autoOptions)
37
+          const placeSearch = new AMap.PlaceSearch({ map: mapInstance })
38
+
39
+          // 监听下拉框选中事件
40
+          AMap.event.addListener(autoComplete, 'select', e => {
41
+            // TODO 针对选中的poi实现自己的功能
42
+            placeSearch.setCity(e.poi.adcode)
43
+            placeSearch.search(e.poi.name)
44
+          })
45
+
46
+          const citySearch = new AMap.CitySearch()
47
+          citySearch.getLocalCity((status, result) => {
48
+            if (status === 'complete' && result.info === 'OK') {
49
+              // 查询成功,result即为当前所在城市信息
50
+              console.log('当前所在城市:', result)
51
+              if (result && result.city && result.bounds) {
52
+                // 当前城市位置信息
53
+                const citybounds = result.bounds;
54
+                // 地图显示当前城市
55
+                mapInstance.setBounds(citybounds);
56
+                // 需要在设置坐标成功后,重新设置 缩放级别
57
+                // mapInstance.setZoom(15)
58
+              }
59
+            }
60
+          })
61
+
62
+          // 搜索结果点击
63
+          placeSearch.on('markerClick', debounce(e => {
64
+            const { location: loc } = e.data
65
+            const lngLat = `${loc.lng},${loc.lat}`
66
+            this.props.onChange(lngLat, e)
67
+          }, 300, { leading: true }))
68
+        })
69
+
70
+        // 实例点击事件
71
+        mapInstance.on('click', debounce(e => {
72
+          const lngLat = `${e.lnglat.getLng()},${e.lnglat.getLat()}`
73
+          this.props.onChange(lngLat, e)
74
+        }, 300, { leading: true }));
75
+      },
76
+    };
77
+    
78
+    this.markerEvents = {
79
+      created: markerInstance => {
80
+        this.markerInstance = markerInstance
81
+        console.log('--->',markerInstance)
82
+      }
83
+    }
84
+    // this.markerPosition = { longitude: 120, latitude: 30 };
85
+  }
86
+
87
+  static getDerivedStateFromProps(props, state) {
88
+    if (props.value && !state.markerPosition) {
89
+      return { markerPosition: getPosFromProps(props) }
90
+    }
91
+
92
+    return null
93
+  }
94
+
95
+  componentDidUpdate(prevProps) {
96
+    if (this.props.value !== prevProps.value) {
97
+      if (this.props.value) {
98
+        this.setState({ markerPosition: getPosFromProps(this.props) }, () => {
99
+          if (this.mapInstance) {
100
+            // 需要在设置坐标成功后,重新设置 缩放级别
101
+            // this.mapInstance.setZoom(15)
102
+          }
103
+        })
104
+      }
105
+    }
106
+  }
107
+
108
+  render() {
109
+    return (
110
+      <>
111
+        <div style={{ width: '100%', height: '100%', minHeight: '400px', position: 'relative' }}>
112
+          {/* zoom={15} 设置后,无效,不知道什么原因,必须手动设置 */}
113
+          <Map plugins={['ToolBar']} events={this.amapEvents} amapkey={this.props.amapkey} center={this.state.markerPosition}>
114
+            <Marker position={this.state.markerPosition} events={this.markerEvents} clickable />
115
+          </Map>
116
+          {
117
+          <div className={styles.infoBox}>
118
+            <span className={styles.inputText}>请输入关键字</span>
119
+            <input id="amapInput" className={styles.input} type="text" />
120
+          </div>
121
+          }
122
+        </div>
123
+      </>
124
+    )
125
+  }
126
+}
127
+
128
+export default AMapSearch

+ 7
- 0
estateagents-admin-manager/src/components/AMap/index.js Zobrazit soubor

@@ -0,0 +1,7 @@
1
+import AMapSearch from './AMapSearch'
2
+import { regeo as getRegeo } from './utils'
3
+
4
+export {
5
+  AMapSearch,
6
+  getRegeo
7
+}

+ 53
- 0
estateagents-admin-manager/src/components/AMap/style.less Zobrazit soubor

@@ -0,0 +1,53 @@
1
+
2
+.infoBox {
3
+  padding: 10px;
4
+  position: absolute;
5
+  top: 20px;
6
+  left: 20px;
7
+  background-color: white;
8
+  width: 290px;
9
+  box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
10
+  z-index: 100;
11
+  .inputText{
12
+    margin-right: 10px;
13
+  }
14
+  .input{
15
+    width: 150px;
16
+    height: 32px;
17
+    font-size: 16px;
18
+  }
19
+ 
20
+}
21
+
22
+
23
+/* types */
24
+
25
+.native-toast-error {
26
+  background-color: #d92727;
27
+  color: white;
28
+}
29
+
30
+.native-toast-success {
31
+  background-color: #62a465;
32
+  color: white;
33
+}
34
+
35
+.native-toast-warning {
36
+  background-color: #fdaf17;
37
+  color: white;
38
+}
39
+
40
+.native-toast-info {
41
+  background-color: #5060ba;
42
+  color: white;
43
+}
44
+
45
+[class^="native-toast-icon-"] {
46
+  vertical-align: middle;
47
+  margin-right: 8px
48
+}
49
+
50
+[class^="native-toast-icon-"] svg {
51
+  width: 16px;
52
+  height: 16px;
53
+}

+ 26
- 0
estateagents-admin-manager/src/components/AMap/utils.js Zobrazit soubor

@@ -0,0 +1,26 @@
1
+import { fetch, apis } from '@/utils/request'
2
+
3
+export function regeo(key, params) {
4
+  return new Promise((resolve, reject) => {
5
+    fetch(apis.amap.regeo)({
6
+      params: {
7
+        key,
8
+        output: 'json',
9
+        extensions: 'base',
10
+        batch: 'false',
11
+        roadlevel: 0,
12
+        ...params,
13
+      }
14
+    }).then(res => {
15
+      if (res.status === '1' && res.infocode === '10000') {
16
+        resolve(res.regeocode)
17
+      } else {
18
+        console.error(res)
19
+        resolve(res.info)
20
+      }
21
+    }).catch(err => {
22
+      console.error(err)
23
+      resolve(err.message)
24
+    })
25
+  })
26
+}

+ 42
- 0
estateagents-admin-manager/src/components/ActionList/index.jsx Zobrazit soubor

@@ -0,0 +1,42 @@
1
+import React from 'react';
2
+import { Menu, Dropdown, Icon } from 'antd';
3
+
4
+import './style.less';
5
+
6
+export default function withActions(actionsRender) {
7
+  return function ActionList(text, record) {
8
+    const actions = actionsRender(text, record);
9
+    const [Act1, Act2, ...leftActs] = (actions || []).filter(Boolean);
10
+    const showMore = leftActs && leftActs.length > 0;
11
+
12
+    const menus = (
13
+      <Menu className="actlist-menu">
14
+        {[Act2].concat(leftActs).filter(Boolean).map((Act, index) => (<Menu.Item key={`dm-${index}`}>{Act}</Menu.Item>))}
15
+      </Menu>
16
+    );
17
+    console.log('---------->', record, menus)
18
+
19
+    return (
20
+      <div className="action-list">
21
+        {
22
+          Act1 && <span>{Act1}</span>
23
+        }
24
+        {
25
+          !showMore && Act2 && <span>{Act2}</span>
26
+        }
27
+        {
28
+          showMore ?
29
+          (
30
+            <span>
31
+              <Dropdown overlay={menus} trigger={['click']}>
32
+                <a onClick={e => e.preventDefault()}>
33
+                  <span>更多</span> <Icon type="down" />
34
+                </a>
35
+              </Dropdown>
36
+            </span>
37
+          ) : null
38
+        }
39
+      </div>
40
+    );
41
+  }
42
+}

+ 29
- 0
estateagents-admin-manager/src/components/ActionList/style.less Zobrazit soubor

@@ -0,0 +1,29 @@
1
+
2
+:global{
3
+  .action-list {  
4
+    span {
5
+      display: inline-block;
6
+      & + span {
7
+        margin-left: 16px;
8
+      }
9
+  
10
+      a {
11
+        color: #666;
12
+  
13
+        span {
14
+          color: #FF4A4A;
15
+        }
16
+      }
17
+    }
18
+  }
19
+  
20
+  .actlist-menu {
21
+    .ant-dropdown-menu-item {
22
+      color: #666 !important;
23
+
24
+      &:hover {
25
+        background-color: rgba(0,0,0, .1);
26
+      }
27
+    }
28
+  }
29
+}