Browse Source

Merge branch 'master' of http://git.ycjcjy.com/marketing/pc-admin into master

zlisen 3 years ago
parent
commit
5650818b8c

+ 1
- 0
package.json View File

@@ -58,6 +58,7 @@
58 58
     "path-to-regexp": "2.4.0",
59 59
     "qs": "^6.9.0",
60 60
     "react": "^16.8.6",
61
+    "react-amap": "^1.2.8",
61 62
     "react-copy-to-clipboard": "^5.0.1",
62 63
     "react-dom": "^16.8.6",
63 64
     "react-helmet": "^5.2.1",

+ 6
- 1
src/components/SelectButton/AreaSelect.jsx View File

@@ -42,12 +42,17 @@ const CitySelect = (props) => {
42 42
     }
43 43
   }
44 44
 
45
+  const style = {
46
+    width: '300px',
47
+    ...(props.style || {})
48
+  }
49
+
45 50
   return (
46 51
       <Select
47 52
       {...props}
48 53
       showSearch
49 54
       value={props.value}
50
-      style={{ width: '300px' }}
55
+      style={style}
51 56
       placeholder="请选择区域"
52 57
       onChange={props.onChange}
53 58
       filterOption={(input, option) =>

+ 6
- 1
src/components/SelectButton/CitySelect.jsx View File

@@ -41,9 +41,14 @@ const CitySelect = (props) => {
41 41
     }
42 42
   }
43 43
 
44
+  const style = {
45
+    width: '300px',
46
+    ...(props.style || {})
47
+  }
48
+
44 49
   return (
45 50
       <Select
46
-      style={{ width: '300px' }}
51
+      style={style}
47 52
       placeholder="请选择城市"
48 53
       showSearch
49 54
       {...props}

+ 143
- 25
src/pages/building/Edit/Basic.jsx View File

@@ -1,14 +1,29 @@
1 1
 import React from 'react'
2
-import { Form, Input, notification, Select } from 'antd'
2
+import { Row, Col, Form, Input, InputNumber, Radio, notification, Select } from 'antd'
3 3
 import FileUpload from '@/components/XForm/FileUpload';
4
+import ImageUpload from '@/components/XForm/ImageUpload';
5
+import ImageListUpload from '@/components/XForm/ImageListUpload';
6
+import SelectCity from '@/components/SelectButton/CitySelect'
7
+import AreaSelect from '@/components/SelectButton/AreaSelect'
4 8
 import BuildingType from './components/BuildingTypeSelect'
5
-import { formItemLayout } from './utils'
9
+import OpenTimePicker from './components/OpenTimePicker'
10
+import Amap from './components/Amap'
11
+import { formItemLayout, groupItemLayout } from './utils'
12
+
13
+const fullWidth= { width: '100%' }
6 14
 
7 15
 const Item = Form.Item
8 16
 
17
+const GroupItem = ({children}) => (
18
+  <Row gutter={24}>
19
+    <Col span={12}>{children[0]}</Col>
20
+    <Col span={11}>{children[1]}</Col>
21
+  </Row>
22
+)
23
+
9 24
 const BuildingBasic = (props) => {
10 25
   const { form } = props;
11
-  const { getFieldDecorator } = form;
26
+  const { getFieldDecorator, getFieldValue, setFieldsValue } = form;
12 27
 
13 28
   
14 29
   // 视频文件上传前 回调
@@ -24,16 +39,37 @@ const BuildingBasic = (props) => {
24 39
     })
25 40
   }
26 41
 
42
+  // 周边设施 回调
43
+  function handleMapScope(e) {
44
+    const coordinateValue = getFieldValue('coordinate')
45
+    if (!coordinateValue) {
46
+      notification.error({ message: '请先选择项目坐标位置' })
47
+      return
48
+    }
49
+
50
+    const lngLat = getFieldValue('coordinate').split(',')
51
+    const poiData = [].concat(POI_TYPES)
52
+    poiData.map(item => {
53
+      getAroundData({ types: item.key, location: lngLat, radius: e }).then(res => {
54
+        const { pois } = res
55
+        setFormMapScopeValue(item.key, pois)
56
+      }).catch(err => {
57
+        console.error(err)
58
+        notification.error({ message: '周边数据获取失败' })
59
+      })
60
+    })
61
+  }
62
+
27 63
   return (
28 64
     <Form {...formItemLayout}>
29 65
       <Item label="项目Id" style={{ display: 'none' }}>
30 66
         {getFieldDecorator('buildingId')(<Input disabled />)}
31 67
       </Item>
32
-      <Item label="楼盘编号" >
68
+      {/* <Item label="楼盘编号" >
33 69
         {getFieldDecorator('code', {
34 70
           rules: [{ required: true, message: '请输入楼盘编号' }],
35 71
         })(<Input />)}
36
-      </Item>
72
+      </Item> */}
37 73
       <Item label="楼盘名称" >
38 74
         {getFieldDecorator('buildingName', {
39 75
           rules: [{ required: true, message: '请输入楼盘名' }],
@@ -47,30 +83,34 @@ const BuildingBasic = (props) => {
47 83
       <Form.Item label="列表均价" help="项目列表展示价格,示例:约10000元/㎡、约1000万元/套起">
48 84
         {getFieldDecorator('price')(<Input />)}
49 85
       </Form.Item>
50
-      <Form.Item label="开盘时间" >
51
-        {getFieldDecorator('openingDate')(<Input placeholder="预计xxxx年xx月开盘" />)}
52
-      </Form.Item>
53
-      <Form.Item label="电话" >
54
-        {getFieldDecorator('tel', {
55
-          rules: [
56
-            {
57
-              pattern: new RegExp('^[0-9]*$'),
58
-              message: '请输入正确的电话号码',
59
-            },
60
-          ],
61
-        })(<Input placeholder="手机或者座机号码" />)}
62
-      </Form.Item>
86
+      <GroupItem>
87
+        <Form.Item label="开盘时间" {...groupItemLayout.a} >
88
+          {getFieldDecorator('openingDate')(
89
+            <OpenTimePicker placeholder="请选择开盘时间" style={fullWidth} />
90
+          )}
91
+        </Form.Item>
92
+        <Form.Item label="电话" {...groupItemLayout.b } >
93
+          {getFieldDecorator('tel', {
94
+            rules: [
95
+              {
96
+                pattern: new RegExp('^[0-9]*$'),
97
+                message: '请输入正确的电话号码',
98
+              },
99
+            ],
100
+          })(<Input placeholder="手机或者座机号码" />)}
101
+        </Form.Item>
102
+      </GroupItem>
63 103
       <Form.Item label="项目说明" >
64 104
         {getFieldDecorator('dynamic')(<Input placeholder="项目动态等,不超过30个字" maxLength={30}/>)}
65 105
       </Form.Item>
66
-      <Form.Item label="物业类型" >
106
+      {/* <Form.Item label="物业类型" >
67 107
         {getFieldDecorator('propertyType')(<Input />)}
68
-      </Form.Item>
108
+      </Form.Item> */}
69 109
       <Form.Item label="销售状态" >
70 110
         {getFieldDecorator('marketStatus', {
71 111
           rules: [{ required: true, message: '请选择销售状态' }],
72 112
         })(
73
-          <Select placeholder="销售状态" style={{ width: '100%' }}>
113
+          <Select placeholder="销售状态" style={fullWidth}>
74 114
             <Select.Option value="待售">待售</Select.Option>
75 115
             <Select.Option value="在售">在售</Select.Option>
76 116
             <Select.Option value="售罄">售罄</Select.Option>
@@ -80,14 +120,92 @@ const BuildingBasic = (props) => {
80 120
       </Form.Item>
81 121
       <Form.Item label="项目标签" >
82 122
         {getFieldDecorator('tag')(
83
-          <Select mode="tags" placeholder="输入后选中" style={{ width: '100%' }} />
123
+          <Select mode="tags" placeholder="输入后选中" style={fullWidth} />
84 124
         )}
85 125
       </Form.Item>
86
-      <Form.Item label="项目视频" help="视频仅支持mp4格式,建议尺寸:750*600,比例5:4,用于楼盘详情">
87
-        {getFieldDecorator('videoUrl')(
88
-          <FileUpload accept=".mp4" beforeUpload={fileUploadBeforeUpload} label="上传视频" size={1} />,
126
+
127
+      <GroupItem>
128
+        <Form.Item label="项目视频" help="视频仅支持mp4格式,建议尺寸:750*600,比例5:4,用于楼盘详情" {...groupItemLayout.a} >
129
+          {getFieldDecorator('videoUrl')(
130
+            <FileUpload accept=".mp4" beforeUpload={fileUploadBeforeUpload} label="上传视频" size={1} />,
131
+          )}
132
+        </Form.Item>
133
+        <Form.Item label="视频封面图" help="建议图片尺寸:750*600px,比例5:4,格式:jpg,用于视频封面" labelCol={{span: 8}} wrapperCol={{span:16}}>
134
+          {getFieldDecorator('videoImage', {
135
+            rules: [{ required: true, message: '请选择视频封面图' }],
136
+          })(
137
+            <ImageUpload />,
138
+          )}
139
+        </Form.Item>
140
+      </GroupItem>
141
+      <Form.Item label="楼盘主图" help="建议图片尺寸:750*600px,比例5:4,格式:jpg,用于楼盘详情">
142
+        {getFieldDecorator('avatarImage', {
143
+          rules: [{ required: true, message: '请选择项目主图' }],
144
+        })(
145
+          <ImageListUpload unlimited />,
89 146
         )}
90 147
       </Form.Item>
148
+      <Form.Item label="楼盘封面图" help="建议图片尺寸:750*420px,比例16:9,格式:jpg,用于楼盘列表">
149
+        {getFieldDecorator('listImage', {
150
+          rules: [{ required: true, message: '请选择列表图' }],
151
+        })(
152
+          <ImageUpload />,
153
+        )}
154
+      </Form.Item>
155
+      <GroupItem>
156
+        <Form.Item label="首页推荐" {...groupItemLayout.a} >
157
+          {getFieldDecorator('isMain', { initialValue: 1 })(
158
+            <Radio.Group>
159
+              <Radio value={1}>是</Radio>
160
+              <Radio value={2}>否</Radio>
161
+            </Radio.Group>,
162
+          )}
163
+        </Form.Item>
164
+        <Form.Item label="排序" help="数值越大,楼盘在小程序列表页中展示越靠前" {...groupItemLayout.b}>
165
+          {getFieldDecorator('orderNo')(<InputNumber min={0} style={fullWidth} />)}
166
+        </Form.Item>
167
+      </GroupItem>
168
+      <GroupItem>
169
+        <Form.Item label="所在城市" {...groupItemLayout.a } >
170
+          {getFieldDecorator('cityId', {
171
+            rules: [{ required: true, message: '请选择城市' }],
172
+          })(
173
+            <SelectCity style={fullWidth} />,
174
+          )}
175
+        </Form.Item>
176
+        <Form.Item label="楼盘区域" {...groupItemLayout.b } >
177
+          {getFieldDecorator('buildingArea', {
178
+            rules: [{ required: true, message: '请输入楼盘区域' }],
179
+          })(<AreaSelect style={fullWidth} />)}
180
+        </Form.Item>
181
+      </GroupItem>
182
+      <Form.Item label="项目地址" >
183
+        {getFieldDecorator('address', {
184
+          rules: [{ required: true, message: '请输入项目地址' }],
185
+        })(<Input />)}
186
+      </Form.Item>
187
+      <Form.Item label="地图位置" >
188
+        {getFieldDecorator('mapCoordinate')(<Amap onChange={e => setFieldsValue({ coordinate: e })}/>)}
189
+      </Form.Item>
190
+      <GroupItem>
191
+        <Form.Item label="项目坐标" {...groupItemLayout.a } >
192
+          {getFieldDecorator('coordinate', {
193
+            rules: [{ required: true, message: '请输入项目坐标' }],
194
+          })(<Input disabled />)}
195
+        </Form.Item>
196
+        <Form.Item label="周边范围" {...groupItemLayout.b } >
197
+          {getFieldDecorator('mapScope', {
198
+            rules: [{ required: true, message: '请选择周边设施搜索范围' }],
199
+          })(
200
+            <Select placeholder="周边设施搜索范围" style={fullWidth} onChange={e => getMapScope(e)}>
201
+              <Option value={1000}>1公里</Option>
202
+              <Option value={3000}>3公里</Option>
203
+              <Option value={5000}>5公里</Option>
204
+              <Option value={10000}>10公里</Option>
205
+            </Select>,
206
+          )}
207
+        </Form.Item>
208
+      </GroupItem>
91 209
 
92 210
     </Form>
93 211
   )

+ 126
- 0
src/pages/building/Edit/components/Amap.jsx View File

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

+ 80
- 0
src/pages/building/Edit/components/EditableArround.jsx View File

@@ -0,0 +1,80 @@
1
+import React, { useEffect, useRef, useState } from 'react'
2
+import { Typography, Tag, Input } from 'antd'
3
+
4
+export default React.forwardRef((props, ref) => {
5
+  const inputRef = useRef()
6
+  const valRef = useRef()
7
+  const [inputValue, setInputValue] = useState()
8
+  const [inputVisible, setInputVisible] = useState(false)
9
+  const [tags, setTags] = useState([])
10
+  // 地图周边 tag
11
+  const [mapTags, setMapTags] = useState([])
12
+
13
+  const handleClose = (tag) => {
14
+    if (mapTags.indexOf(tag) > -1) {
15
+      setMapTags(mapTags.filter((t) => t !== tag))
16
+    }
17
+
18
+    if (props.onChange) {
19
+      props.onChange(tags.filter((t) => t !== tag).join(','))
20
+    }
21
+  }
22
+
23
+  const handleInputConfirm = () => {
24
+    const exists = tags.indexOf(inputValue) > -1
25
+    if (!exists) {
26
+      props.onChange(tags.concat(inputValue).join(','))
27
+    }
28
+    setInputVisible(false)
29
+    setInputValue()
30
+  }
31
+
32
+  useEffect(() => {
33
+    setMapTags(props.mapPois || [])
34
+  }, [props.mapPois])
35
+
36
+  useEffect(() => {
37
+    const vals = (props.value||'').split(',')
38
+    const arr = vals.concat(mapTags)
39
+
40
+    // 去重
41
+    const nwTags = []
42
+    arr.forEach((it) => {
43
+      if (nwTags.indexOf(it) === -1) {
44
+        nwTags.push(it)
45
+      }
46
+    })
47
+
48
+    setTags(nwTags)
49
+  }, [props.value, mapTags])
50
+
51
+  return (
52
+    <div>
53
+      {
54
+        tags.map((tag) => (
55
+          <Tag key={tag} closable onClose={() => handleClose(tag)}>
56
+            <Typography.Text>{tag}</Typography.Text>
57
+          </Tag>
58
+        ))
59
+      }
60
+      {
61
+        inputVisible ? (
62
+          <Input
63
+            ref={inputRef}
64
+            type="text"
65
+            size="small"
66
+            style={{ width: 80, display: inputVisible ? 'block' : 'none' }}
67
+            value={inputValue}
68
+            onChange={e => setInputValue(e.target.value)}
69
+            onBlur={handleInputConfirm}
70
+            onPressEnter={handleInputConfirm}
71
+          />
72
+        ) : (
73
+          <Tag onClick={() => setInputVisible(true)} style={{ background: '#fff', borderStyle: 'dashed' }}>
74
+            <Icon type="plus" /> 新建
75
+          </Tag>
76
+        )
77
+      }
78
+    </div>
79
+  )
80
+})

+ 27
- 0
src/pages/building/Edit/components/OpenTimePicker.jsx View File

@@ -0,0 +1,27 @@
1
+
2
+import React, { useEffect, useState } from 'react';
3
+import moment from 'moment';
4
+import { DatePicker } from 'antd';
5
+
6
+/**
7
+ * 主要是做了一个日期的格式转换
8
+ */
9
+export default (props) => {
10
+  const { value, onChange, ...leftProps } = props;
11
+  const [val, setVal] = useState(value ? moment(value, 'YYYY-MM-DD HH:mm') : undefined);
12
+
13
+  const handelChange = (e) => {
14
+    if (onChange) {
15
+      onChange(e ? e.format('YYYY-MM-DD HH:mm') : undefined);
16
+    }
17
+  }
18
+
19
+  useEffect(() => {
20
+    setVal(value ? moment(value, 'YYYY-MM-DD HH:mm') : undefined);
21
+  }, [value])
22
+
23
+  return (
24
+    <DatePicker value={val} showTime={{ format: 'HH:mm' }} format="YYYY-MM-DD HH:mm"  {...leftProps} onChange={handelChange} />
25
+  )
26
+}
27
+

+ 53
- 0
src/pages/building/Edit/components/amap.less View File

@@ -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
+}

+ 11
- 0
src/pages/building/Edit/utils.js View File

@@ -9,3 +9,14 @@ export const formItemLayout = {
9 9
     sm: { span: 19 },
10 10
   },
11 11
 }
12
+
13
+export const groupItemLayout = {
14
+  a: {
15
+    labelCol:{ span: 6 },
16
+    wrapperCol:{ span:18 }
17
+  },
18
+  b: {
19
+    labelCol:{ span: 4 },
20
+    wrapperCol:{ span:18 }
21
+  }
22
+}

+ 90
- 0
src/utils/map/index.js View File

@@ -0,0 +1,90 @@
1
+import amapSDK from './sdk';
2
+
3
+const AMAP_KEY = '14f05ce59c26364fd0674014dc0d8b1b'
4
+
5
+const sdk = amapSDK(AMAP_KEY)
6
+
7
+export const POI_TYPES_KETY = {
8
+  Transport: 'Transport',
9
+  Mall: 'Mall',
10
+  Edu: 'Edu',
11
+  Hospital: 'Hospital',
12
+  Bank: 'Bank',
13
+  Restaurant: 'Restaurant',
14
+}
15
+
16
+// key 值会被拿到 building 表中 组合为字段名
17
+export const POI_TYPES = [
18
+  {
19
+    key: POI_TYPES_KETY.Transport,
20
+    label: '交通',
21
+    types: ['150100', '150200', '150300', '150400', '150500', '150600'],
22
+    data: [],
23
+  },
24
+  {
25
+    key: POI_TYPES_KETY.Mall,
26
+    label: '商业',
27
+    types: ['060100', '060200', '060300', '060400', '060500', '060600',
28
+            '060700', '060800', '060900', '061000', '061100', '061200',
29
+            '061300', '061400', '080100', '080200', '080300', '080400',
30
+            '080500', '080600'],
31
+    data: [],
32
+  },
33
+  {
34
+    key: POI_TYPES_KETY.Edu,
35
+    label: '学校',
36
+    types: ['141200'],
37
+    data: [],
38
+  },
39
+  {
40
+    key: POI_TYPES_KETY.Hospital,
41
+    label: '医院',
42
+    types: ['090100', '090200', '090300', '090400', '090500', '090600', '090700'],
43
+    data: [],
44
+  },
45
+  {
46
+    key: POI_TYPES_KETY.Bank,
47
+    label: '银行',
48
+    types: ['160100'],
49
+    data: [],
50
+  },
51
+  {
52
+    key: POI_TYPES_KETY.Restaurant,
53
+    label: '餐饮',
54
+    types: ['050100', '050200', '050300', '050400', '050500', '050600',
55
+            '050700', '050800', '050900'],
56
+    data: [],
57
+  },
58
+]
59
+
60
+/**
61
+ * 获取周边数据
62
+ * @param {查询参数} params 
63
+ */
64
+export function getAroundData (params) {
65
+  return new Promise((resolve, reject) => {
66
+      const { type, location } = params
67
+      if (!type) {
68
+          // console.err('未传输类型types值')
69
+          reject(new Error('未传输类型 type 值'))
70
+          return
71
+      }
72
+      if (!location) {
73
+          // console.err('未传输传输中心坐标location值')
74
+          reject(new Error('未传输传输中心坐标 location 值'))
75
+          return
76
+      }
77
+
78
+      const poiType = POI_TYPES.filter((it) => it.key === type)[0];
79
+      if (!poiType) {
80
+        reject(new Error('周边 type 类型不正确'))
81
+        return
82
+      }
83
+
84
+      sdk({
85
+        types: poiType.types.join('|'),
86
+        ...params,
87
+      }).then(resolve)
88
+      .catch(reject);
89
+  })
90
+}

+ 41
- 0
src/utils/map/sdk.js View File

@@ -0,0 +1,41 @@
1
+
2
+// 简易请求
3
+function request(url, params, options = {}) {
4
+  const queryString = Object.keys(params || {}).map((key) => {
5
+    const val = encodeURIComponent(params[key])
6
+    return `${key}=${val}`
7
+  }).join('&')
8
+
9
+  const api = queryString ? `${url}?${queryString}` : url
10
+
11
+  return new Promise((resolve, reject) => {
12
+    window.fetch(api, {
13
+      mode: 'cors',
14
+      referrerPolicy: 'no-referrer',
15
+      ...options
16
+    }).then(response => response.json())
17
+    .then((data) => {
18
+      const { status, info } = data
19
+      if (status === 1) {
20
+        resolve(data)
21
+      } else {
22
+        console.error(data)
23
+        const err = new Error(info)
24
+        reject(err)
25
+      }
26
+    }).catch(reject)
27
+  })
28
+}
29
+
30
+export function amapSDK(key) {
31
+  const prefix = 'https://restapi.amap.com'
32
+
33
+  function getPlaceAround(params = {}) {
34
+    const url = `${prefix}/v5/place/around`
35
+    return request(url, { key, ...params } )
36
+  }
37
+
38
+  return {
39
+    getPlaceAround,
40
+  }
41
+}

+ 3
- 0
src/utils/request.js View File

@@ -46,10 +46,13 @@ request.interceptors.request.use((url, options) => {
46 46
 
47 47
   return (
48 48
     {
49
+      // url: 'http://81.69.196.8:8567' + apiURL,
49 50
       url: apiURL,
50 51
       options: {
51 52
         ...opts,
52 53
         headers: {
54
+          Referrer: 'no-referrer',
55
+          'Referrer-Policy': 'no-referrer',
53 56
           ...authHeader,
54 57
           ...actionHeader,
55 58
           ...headers,