Przeglądaj źródła

pc端无定位依然支持访问

zhujindu 1 rok temu
rodzic
commit
2231e62a1c

+ 8 - 4
src/utils/TXApiFun.js

@@ -8,13 +8,12 @@ const wx = Vue.prototype.wx;
 // 腾讯位置服务 key
 const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6';
 // 当前设备
-// const isDevice = localStorage.getItem('isDevice');
-// console.log(isDevice);
+const isDevice = localStorage.getItem('isDevice');
 
 /**
  * 获取当前定位 调用之前确保当前页面已经授权(getTicketFun)
  * */
-export function getPosition(isDevice) {
+export function getPosition(isPermit = false) {
   return new Promise((resolve, reject) => {
     toastLoading(0, '定位中...', true);
     // PC端没有定位权限依然可以访问
@@ -31,10 +30,15 @@ export function getPosition(isDevice) {
       toastLoading().clear();
       resolve({ TXisBD: TXisBD, resData: resData });
     } else if (isDevice == 'PC') {
+      // PC状态 分允许通过和不允许通过 isPermit: tru允许,false不允许
       localStorage.setItem('lat', '');
       localStorage.setItem('lon', '');
       toastLoading().clear();
-      resolve({ TXisBD: { lat: '', lon: '' }, resData: { latitude: '', longitude: '' } });
+      if (isPermit) {
+        resolve({ TXisBD: { lat: '', lon: '' }, resData: { latitude: '', longitude: '' } });
+      } else {
+        reject('GPS未开启');
+      }
     } else {
       wx.ready(() => {
         wx.getLocation({

+ 1 - 2
src/views/deviceOutside/index.vue

@@ -1135,8 +1135,7 @@ export default {
       });
     },
     positionFn(val) {
-      const isDevice = localStorage.getItem('isDevice');
-      getPosition(isDevice)
+      getPosition(true)
         .then((res) => {
           let { TXisBD } = res;
           this.lat = TXisBD.lat;

+ 1 - 2
src/views/deviceWithin/index.vue

@@ -656,8 +656,7 @@ export default {
       this.endShow = false;
       this.toastLoading(0, '加载中...', true);
       localStorage.removeItem('visitId');
-      const isDevice = localStorage.getItem('isDevice');
-      getPosition(isDevice)
+      getPosition(true)
         .then((res) => {
           let { TXisBD } = res;
           this.getUserInPlanListFun(TXisBD);