Skip to content

Commit bdbdc1a

Browse files
committed
接入百度地图经纬度查询接口
1 parent bbfa186 commit bdbdc1a

5 files changed

Lines changed: 79 additions & 27 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
"dependencies": {
2424
"axios": "^0.16.1",
2525
"iview": "^2.4.0",
26+
"jsonp": "^0.2.1",
2627
"left-pad": "1.1.3",
2728
"less": "^2.7.2",
2829
"less-loader": "^4.0.5",
2930
"lodash": "^4.17.4",
3031
"particles.js": "^2.0.0",
32+
"qs": "^6.5.1",
3133
"store": "^2.0.12",
3234
"vue": "^2.3.3",
3335
"vue-echarts": "^2.4.1",

src/renderer/components/Ui/AddPointModal.vue

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
<span>添加地点</span>
1212
</p>
1313
<div style="text-align:center">
14-
<Input class="addPointModal-input" v-model="model[0]" placeholder="地点名称" style="width: 300px"></Input><br>
15-
<Input class="addPointModal-input" v-model="model[1]" placeholder="经度" style="width: 300px"></Input><br>
16-
<Input class="addPointModal-input" v-model="model[2]" placeholder="纬度" style="width: 300px"></Input><br>
14+
<Input class="addPointModal-input" v-model="model[0]" placeholder="地点名称" style="width: 300px" @on-blur="getLocation"></Input><br>
15+
<Input v-if="!hasGetLocation" class="addPointModal-input" v-model="model[1]" placeholder="经度" style="margin-top:18px;width: 300px"></Input><br>
16+
<Input v-if="hasGetLocation" class="addPointModal-input" :value="model[1]" style="width: 300px"></Input><br>
17+
<Input v-if="!hasGetLocation" class="addPointModal-input" v-model="model[2]" placeholder="纬度" style="width: 300px"></Input><br>
18+
<Input v-if="hasGetLocation" class="addPointModal-input" :value="model[2]" style="margin-bottom:18px;width: 300px"></Input><br>
1719
<DatePicker class="addPointModal-input" @on-change="getDate($event)" type="date" placeholder="选择日期" style="width: 300px"></DatePicker>
1820
</div>
1921
</Modal>
@@ -44,20 +46,43 @@ export default {
4446
'',
4547
''
4648
],
47-
showModal: false
49+
showModal: false,
50+
hasGetLocation: false
4851
}
4952
},
50-
computed: mapState({
51-
excelData: state => state.excel.excelData,
52-
countAlias: 'excelData',
53-
userId: state => state.userInfo.userInfo.objectId || storage.get('userId'),
54-
countAlias: 'userId'
55-
}),
53+
computed: {
54+
...mapState({
55+
excelData: state => state.excel.excelData,
56+
countAlias: 'excelData',
57+
userId: state => state.userInfo.userInfo.objectId || storage.get('userId'),
58+
countAlias: 'userId'
59+
}),
60+
},
5661
methods: {
5762
...mapActions({
5863
addExcelData: 'addExcelData',
5964
setExcelData: 'setExcelData'
6065
}),
66+
getLocation() {
67+
if(this.model[0] !== '') {
68+
this.$Spin.show()
69+
ajax.get({
70+
url: url.GETLOCATION_CHINA,
71+
data: {
72+
address: this.model[0],
73+
output: 'json',
74+
ak: 'O9WWqYCWQ0d0N1KI85Blg7X2fSBsxOAs',
75+
callback: 'showLocation'
76+
}
77+
}).then(data => {
78+
console.log(data)
79+
this.model[1] = data.result.location.lng
80+
this.model[2] = data.result.location.lat
81+
this.hasGetLocation = true
82+
this.$Spin.hide()
83+
})
84+
}
85+
},
6186
addPoint() {
6287
if(this.model[0] === '' || this.model[1] === '' || this.model[2] === '' || this.model[3] === '')
6388
this.$Message.error('输入不能为空')
@@ -74,6 +99,8 @@ export default {
7499
}
75100
else
76101
this.addExcelData(this.model)
102+
this.model = ['', '', '', '']
103+
this.hasGetLocation = false
77104
let updateMapDate = new Date(_.now()).toLocaleString()
78105
ajax.post({
79106
url: url.ASYNC_UPLOAD,
@@ -113,7 +140,7 @@ export default {
113140

114141
<style lang="less" scoped>
115142
@import '../../assets/my-theme/custom.less';
116-
.addPointModal-input {
117-
margin-bottom: 12px;
143+
.addPointModal-input_1 {
144+
margin-bottom: 18px;
118145
}
119146
</style>

src/renderer/server/ajax.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import axios from 'axios'
22
import { Message } from 'iview'
3+
import jsonp from 'jsonp'
4+
import qs from 'qs'
35
axios.defaults.timeout = 1000000; //响应时间
46
axios.defaults.headers.post['Content-Type'] = 'application/json' //通信格式
5-
// axios.defaults.baseURL = 'http://localhost:3000/' //配置接口地址
6-
axios.defaults.baseURL = 'https://imap.leanapp.cn' //配置接口地址
7+
axios.defaults.baseURL = 'http://localhost:3000/' //配置接口地址
8+
// axios.defaults.baseURL = 'https://imap.leanapp.cn' //配置接口地址
79

810
export default {
911
// POST请求
1012
post({...obj}) {
1113
return new Promise((resolve,reject) => {
12-
axios.post(obj.url, obj.data).then((data) => {
14+
axios.post(obj.url, obj.data).then(data => {
1315
if(data.data.code === 0){
1416
Message.success(data.data.msg)
1517
resolve(data.data)
@@ -23,8 +25,22 @@ export default {
2325
Message.error(data.data.msg)
2426
resolve(data.data)
2527
}
26-
}).catch((data) => {
27-
reject(data);
28+
}).catch(data => {
29+
reject(data)
30+
})
31+
})
32+
},
33+
// GET请求
34+
get({...obj}) {
35+
return new Promise((resolve, reject) => {
36+
jsonp(obj.url + '?' + qs.stringify(obj.data) , null, (err, data) => {
37+
if (err) {
38+
Message.error('请求错误')
39+
} else {
40+
if(data.status === 0) {
41+
resolve(data)
42+
}
43+
}
2844
})
2945
})
3046
}

src/renderer/server/url.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
export default {
2-
REGISTER : '/api/v1/auth/register',
3-
EMAILLOGIN : '/api/v1/auth/login',
4-
ASKCODE : '/api/v1/auth/login/askCode',
5-
PHONELOGIN : '/api/v1/auth/login/phone',
6-
FORGETPASSWORD : '/api/v1/auth/forgetPassword',
7-
RESOLVEEXCEL : '/api/v1/resolveExcel',
8-
ASYNC_UPLOAD : '/api/v1/async/upload',
9-
ASYNC_DOWNLOAD : '/api/v1/async/download',
10-
DELMAPDATA : '/api/v1/delMapData'
2+
REGISTER : '/api/v1/auth/register',
3+
EMAILLOGIN : '/api/v1/auth/login',
4+
ASKCODE : '/api/v1/auth/login/askCode',
5+
PHONELOGIN : '/api/v1/auth/login/phone',
6+
FORGETPASSWORD : '/api/v1/auth/forgetPassword',
7+
RESOLVEEXCEL : '/api/v1/resolveExcel',
8+
ASYNC_UPLOAD : '/api/v1/async/upload',
9+
ASYNC_DOWNLOAD : '/api/v1/async/download',
10+
DELMAPDATA : '/api/v1/delMapData',
11+
GETLOCATION_CHINA: 'https://api.map.baidu.com/geocoder/v2/'
1112
}

yarn.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,12 @@ jsonify@~0.0.0:
35043504
version "0.0.0"
35053505
resolved "http://registry.npm.taobao.org/jsonify/download/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
35063506

3507+
jsonp@^0.2.1:
3508+
version "0.2.1"
3509+
resolved "http://registry.npm.taobao.org/jsonp/download/jsonp-0.2.1.tgz#a65b4fa0f10bda719a05441ea7b94c55f3e15bae"
3510+
dependencies:
3511+
debug "^2.1.3"
3512+
35073513
jsprim@^1.2.2:
35083514
version "1.4.1"
35093515
resolved "http://registry.npm.taobao.org/jsprim/download/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
@@ -4864,7 +4870,7 @@ q@^1.1.2:
48644870
version "1.5.0"
48654871
resolved "http://registry.npm.taobao.org/q/download/q-1.5.0.tgz#dd01bac9d06d30e6f219aecb8253ee9ebdc308f1"
48664872

4867-
qs@6.5.1, qs@~6.5.1:
4873+
qs@6.5.1, qs@^6.5.1, qs@~6.5.1:
48684874
version "6.5.1"
48694875
resolved "http://registry.npm.taobao.org/qs/download/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
48704876

0 commit comments

Comments
 (0)