|
@@ -7,6 +7,8 @@ import { jsonp } from 'vue-jsonp';
|
|
|
const wx = Vue.prototype.wx;
|
|
const wx = Vue.prototype.wx;
|
|
|
// 腾讯位置服务 key
|
|
// 腾讯位置服务 key
|
|
|
const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6';
|
|
const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6';
|
|
|
|
|
+// 是否为移动端
|
|
|
|
|
+const isPC = localStorage.getItem('isPC');
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取当前定位 调用之前确保当前页面已经授权(getTicketFun)
|
|
* 获取当前定位 调用之前确保当前页面已经授权(getTicketFun)
|
|
@@ -14,8 +16,9 @@ const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6';
|
|
|
export function getPosition() {
|
|
export function getPosition() {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
toastLoading(0, '定位中...', true);
|
|
toastLoading(0, '定位中...', true);
|
|
|
- // 本地开发 test 环境时跳过获取定位功能 模拟定位
|
|
|
|
|
|
|
+ // PC端没有定位权限依然可以访问
|
|
|
if (process.env.NODE_ENV === 'test') {
|
|
if (process.env.NODE_ENV === 'test') {
|
|
|
|
|
+ // 本地开发 test 环境时跳过获取定位功能 模拟定位
|
|
|
let resData = {
|
|
let resData = {
|
|
|
latitude: 34.615684509277344,
|
|
latitude: 34.615684509277344,
|
|
|
longitude: 112.4474105834961,
|
|
longitude: 112.4474105834961,
|
|
@@ -25,7 +28,12 @@ export function getPosition() {
|
|
|
localStorage.setItem('lat', TXisBD.lat);
|
|
localStorage.setItem('lat', TXisBD.lat);
|
|
|
localStorage.setItem('lon', TXisBD.lon);
|
|
localStorage.setItem('lon', TXisBD.lon);
|
|
|
toastLoading().clear();
|
|
toastLoading().clear();
|
|
|
- resolve({ TXisBD, resData });
|
|
|
|
|
|
|
+ resolve({ TXisBD: TXisBD, resData: resData });
|
|
|
|
|
+ } else if (isPC) {
|
|
|
|
|
+ localStorage.setItem('lat', '');
|
|
|
|
|
+ localStorage.setItem('lon', '');
|
|
|
|
|
+ toastLoading().clear();
|
|
|
|
|
+ resolve({ TXisBD: { lat: '', lon: {} }, resData: { latitude: '', longitude: '' } });
|
|
|
} else {
|
|
} else {
|
|
|
wx.ready(() => {
|
|
wx.ready(() => {
|
|
|
wx.getLocation({
|
|
wx.getLocation({
|
|
@@ -33,22 +41,15 @@ export function getPosition() {
|
|
|
success: (resData) => {
|
|
success: (resData) => {
|
|
|
console.log('success');
|
|
console.log('success');
|
|
|
toastLoading().clear();
|
|
toastLoading().clear();
|
|
|
- // resData.errmsg == fail_no permission 没有权限依会走success
|
|
|
|
|
- if (resData.latitude) {
|
|
|
|
|
- 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 });
|
|
|
|
|
- } else {
|
|
|
|
|
- localStorage.setItem('lat', '');
|
|
|
|
|
- localStorage.setItem('lon', '');
|
|
|
|
|
- reject('定位失败,请开启企微定位权限');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 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: TXisBD, resData: resData });
|
|
|
},
|
|
},
|
|
|
fail: () => {
|
|
fail: () => {
|
|
|
console.log('fail');
|
|
console.log('fail');
|