|
|
@@ -1,31 +1,31 @@
|
|
|
-import Vue from 'vue'
|
|
|
-import { getTicket } from '@/api/index'
|
|
|
-import { toastLoading } from '@/utils/commonVant'
|
|
|
-import { CJ02BD, gcj02BD } from '@/utils/index'
|
|
|
-import { jsonp } from 'vue-jsonp'
|
|
|
+import Vue from 'vue';
|
|
|
+import { getTicket } from '@/api/index';
|
|
|
+import { toastLoading } from '@/utils/commonVant';
|
|
|
+import { CJ02BD, gcj02BD } from '@/utils/index';
|
|
|
+import { jsonp } from 'vue-jsonp';
|
|
|
// 微信JSSDK实例
|
|
|
-const wx = Vue.prototype.wx
|
|
|
+const wx = Vue.prototype.wx;
|
|
|
// 腾讯位置服务 key
|
|
|
-const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6'
|
|
|
+const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6';
|
|
|
|
|
|
/**
|
|
|
* 获取当前定位 调用之前确保当前页面已经授权(getTicketFun)
|
|
|
* */
|
|
|
export function getPosition() {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- toastLoading(0, '定位中...', true)
|
|
|
+ toastLoading(0, '定位中...', true);
|
|
|
// 本地开发 test 环境时跳过获取定位功能 模拟定位
|
|
|
if (process.env.NODE_ENV === 'test') {
|
|
|
let resData = {
|
|
|
latitude: 34.615684509277344,
|
|
|
longitude: 112.4474105834961,
|
|
|
- }
|
|
|
+ };
|
|
|
// 定位坐标转换 腾讯转百度
|
|
|
- let TXisBD = CJ02BD(resData.latitude, resData.longitude)
|
|
|
- localStorage.setItem('lat', TXisBD.lat)
|
|
|
- localStorage.setItem('lon', TXisBD.lon)
|
|
|
- toastLoading().clear()
|
|
|
- resolve({ TXisBD, resData })
|
|
|
+ let TXisBD = CJ02BD(resData.latitude, resData.longitude);
|
|
|
+ localStorage.setItem('lat', TXisBD.lat);
|
|
|
+ localStorage.setItem('lon', TXisBD.lon);
|
|
|
+ toastLoading().clear();
|
|
|
+ resolve({ TXisBD, resData });
|
|
|
} else {
|
|
|
// let url = window.location.href;
|
|
|
// // 获取签名
|
|
|
@@ -47,38 +47,38 @@ export function getPosition() {
|
|
|
wx.getLocation({
|
|
|
type: 'gcj02',
|
|
|
success: (resData) => {
|
|
|
- toastLoading().clear()
|
|
|
- console.log('处理前')
|
|
|
- console.log(resData.latitude, resData.longitude)
|
|
|
+ toastLoading().clear();
|
|
|
+ console.log('处理前');
|
|
|
+ console.log(resData.latitude, resData.longitude);
|
|
|
// 定位坐标转换 腾讯转百度
|
|
|
- let TXisBD = CJ02BD(resData.latitude, resData.longitude)
|
|
|
- console.log('处理后')
|
|
|
- console.log(TXisBD)
|
|
|
- localStorage.setItem('lat', TXisBD.lat)
|
|
|
- localStorage.setItem('lon', TXisBD.lon)
|
|
|
- resolve({ TXisBD, resData })
|
|
|
+ let TXisBD = CJ02BD(resData.latitude, resData.longitude);
|
|
|
+ console.log('处理后');
|
|
|
+ console.log(TXisBD);
|
|
|
+ localStorage.setItem('lat', TXisBD.lat);
|
|
|
+ localStorage.setItem('lon', TXisBD.lon);
|
|
|
+ resolve({ TXisBD, resData });
|
|
|
},
|
|
|
fail: () => {
|
|
|
- toastLoading().clear()
|
|
|
- reject('GPS未开启')
|
|
|
+ toastLoading().clear();
|
|
|
+ reject('GPS未开启');
|
|
|
},
|
|
|
complete: () => {
|
|
|
- toastLoading().clear()
|
|
|
+ toastLoading().clear();
|
|
|
},
|
|
|
- })
|
|
|
- })
|
|
|
+ });
|
|
|
+ });
|
|
|
wx.error((err) => {
|
|
|
- toastLoading().clear()
|
|
|
- console.log(err)
|
|
|
- reject('定位失败,请开启企微定位权限')
|
|
|
- })
|
|
|
+ toastLoading().clear();
|
|
|
+ console.log(err);
|
|
|
+ reject('定位失败,请开启企微定位权限');
|
|
|
+ });
|
|
|
// } else {
|
|
|
// toastLoading().clear();
|
|
|
// reject("获取签名失败");
|
|
|
// }
|
|
|
// });
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -89,13 +89,13 @@ export function getPosition() {
|
|
|
export function getTicketFun(jsApiList = ['getLocation']) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
// 当前页面
|
|
|
- let url = window.location.href
|
|
|
+ let url = window.location.href;
|
|
|
// 获取签名
|
|
|
getTicket({ url: url }).then((response) => {
|
|
|
- console.log(response)
|
|
|
- toastLoading().clear()
|
|
|
+ console.log(response);
|
|
|
+ toastLoading().clear();
|
|
|
if (response.code == 200) {
|
|
|
- let qiyeData = response.data
|
|
|
+ let qiyeData = response.data;
|
|
|
wx.config({
|
|
|
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
|
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
@@ -104,14 +104,14 @@ export function getTicketFun(jsApiList = ['getLocation']) {
|
|
|
nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
|
|
|
signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
|
|
|
jsApiList: ['ready', ...jsApiList], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
|
|
|
- })
|
|
|
- resolve('获取签名成功')
|
|
|
+ });
|
|
|
+ resolve('获取签名成功');
|
|
|
} else {
|
|
|
- console.log('获取签名失败')
|
|
|
- reject('获取签名失败')
|
|
|
+ console.log('获取签名失败');
|
|
|
+ reject('获取签名失败');
|
|
|
}
|
|
|
- })
|
|
|
- })
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
/**
|
|
|
* 地点搜索 获取500米范围poi点
|
|
|
@@ -123,19 +123,19 @@ export function getTicketFun(jsApiList = ['getLocation']) {
|
|
|
export function getMapPoi(location, radius = 500, auto_extend = 0) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
let api =
|
|
|
- 'https://apis.map.qq.com/ws/place/v1/search?page_size=10&page_index=1&orderby=_distance&output=jsonp'
|
|
|
- let boundary = `&boundary=nearby(${location.latitude},${location.longitude},${radius},${auto_extend})`
|
|
|
- let key = `&key=${TxMapKey}`
|
|
|
+ 'https://apis.map.qq.com/ws/place/v1/search?page_size=10&page_index=1&orderby=_distance&output=jsonp';
|
|
|
+ let boundary = `&boundary=nearby(${location.latitude},${location.longitude},${radius},${auto_extend})`;
|
|
|
+ let key = `&key=${TxMapKey}`;
|
|
|
jsonp(api + boundary + key)
|
|
|
.then((res) => {
|
|
|
- console.log(res)
|
|
|
- resolve(res)
|
|
|
+ console.log(res);
|
|
|
+ resolve(res);
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
- console.log(err)
|
|
|
- reject(err)
|
|
|
- })
|
|
|
- })
|
|
|
+ console.log(err);
|
|
|
+ reject(err);
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -146,21 +146,21 @@ export function getMapPoi(location, radius = 500, auto_extend = 0) {
|
|
|
*/
|
|
|
export function getkeywordPoi(location, keywordValue) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- let keyword = keywordValue ? '&keyword=' + encodeURI(keywordValue) : ''
|
|
|
+ let keyword = keywordValue ? '&keyword=' + encodeURI(keywordValue) : '';
|
|
|
// 关键词搜索
|
|
|
let api =
|
|
|
- 'https://apis.map.qq.com/ws/place/v1/suggestion?output=jsonp&page_size=10®ion_fix=1'
|
|
|
- let key = `&key=${TxMapKey}`
|
|
|
- let locationPos = `&location=${location.latitude},${location.longitude}`
|
|
|
+ 'https://apis.map.qq.com/ws/place/v1/suggestion?output=jsonp&page_size=10®ion_fix=1';
|
|
|
+ let key = `&key=${TxMapKey}`;
|
|
|
+ let locationPos = `&location=${location.latitude},${location.longitude}`;
|
|
|
jsonp(api + locationPos + keyword + key)
|
|
|
.then((res) => {
|
|
|
- console.log(keyword)
|
|
|
- console.log(res)
|
|
|
- resolve(res)
|
|
|
+ console.log(keyword);
|
|
|
+ console.log(res);
|
|
|
+ resolve(res);
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
- console.log(err)
|
|
|
- reject(err)
|
|
|
- })
|
|
|
- })
|
|
|
+ console.log(err);
|
|
|
+ reject(err);
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|