Browse Source

!70 【代码优化】门店自提:h5 位置信息相关逻辑
Merge pull request !70 from puhui999/master

芋道源码 8 months ago
parent
commit
2b5a06174f

+ 51 - 52
pages/user/goods_details_store/index.vue

@@ -32,7 +32,7 @@
             </view>
             <!-- #endif -->
           </view>
-          <view class="store-distance ss-flex ss-row-center" @tap="showMaoLocation(item)">
+          <view class="store-distance ss-flex ss-row-center" @tap.stop="showMaoLocation(item)">
             <text class="addressTxt" v-if="item.distance">距离{{ item.distance.toFixed(2) }}千米</text>
             <text class="addressTxt" v-else>查看地图</text>
             <view class="iconfont">
@@ -55,13 +55,11 @@
 
   const LONGITUDE = 'user_longitude';
   const LATITUDE = 'user_latitude';
-  const MAPKEY = 'mapKey';
   const state = reactive({
     loaded: false,
     loading: false,
     storeList: [],
     system_store: {},
-    // mapKey: cookie.get(MAPKEY),
     locationShow: false,
     user_latitude: 0,
     user_longitude: 0,
@@ -73,61 +71,62 @@
     });
   };
   const selfLocation = () => {
-    // TODO h5 地图
     // #ifdef H5
-    // if (state.$wechat.isWeixin()) {
-    //   state.$wechat.location().then(res => {
-    //     state.user_latitude = res.latitude;
-    //     state.user_longitude = res.longitude;
-    //     uni.setStorageSync(LATITUDE, res.latitude);
-    //     uni.setStorageSync(LONGITUDE, res.longitude);
-    //     getList();
-    //   });
-    // } else {
-    // #endif
-    uni.getLocation({
-      type: 'gcj02',
-      success: (res) => {
-        try {
-          state.user_latitude = res.latitude;
-          state.user_longitude = res.longitude;
-          uni.setStorageSync(LATITUDE, res.latitude);
-          uni.setStorageSync(LONGITUDE, res.longitude);
-        } catch {
-        }
-        getList();
-      },
-      complete: () => {
+    const jsWxSdk = sheep.$platform.useProvider('wechat').jsWxSdk;
+    if (jsWxSdk.isWechat()) {
+      jsWxSdk.getLocation((res) => {
+        console.log(res);
+        state.user_latitude = res.latitude;
+        state.user_longitude = res.longitude;
+        uni.setStorageSync(LATITUDE, res.latitude);
+        uni.setStorageSync(LONGITUDE, res.longitude);
         getList();
-      },
-    });
-    // #ifdef H5
-    // }
+      });
+    } else {
+      // #endif
+      uni.getLocation({
+        type: 'gcj02',
+        success: (res) => {
+          try {
+            state.user_latitude = res.latitude;
+            state.user_longitude = res.longitude;
+            uni.setStorageSync(LATITUDE, res.latitude);
+            uni.setStorageSync(LONGITUDE, res.longitude);
+          } catch {
+          }
+          getList();
+        },
+        complete: () => {
+          getList();
+        },
+      });
+      // #ifdef H5
+    }
     // #endif
   };
   const showMaoLocation = (e) => {
-    // TODO h5 地图
     // #ifdef H5
-    // if (state.$wechat.isWeixin()) {
-    //   state.$wechat.seeLocation({
-    //     latitude: Number(e.latitude),
-    //     longitude: Number(e.longitude),
-    //   }).then(res => {
-    //     console.log('success');
-    //   });
-    // } else {
-    // #endif
-    uni.openLocation({
-      latitude: Number(e.latitude),
-      longitude: Number(e.longitude),
-      name: e.name,
-      address: `${e.areaName}-${e.detailAddress}`,
-      success: function() {
-        console.log('success');
-      },
-    });
-    // #ifdef H5
-    // }
+    const jsWxSdk = sheep.$platform.useProvider('wechat').jsWxSdk;
+    if (jsWxSdk.isWechat()) {
+      jsWxSdk.openLocation({
+        latitude: Number(e.latitude),
+        longitude: Number(e.longitude),
+        name: e.name,
+        address: `${e.areaName}-${e.detailAddress}`
+      });
+    } else {
+      // #endif
+      uni.openLocation({
+        latitude: Number(e.latitude),
+        longitude: Number(e.longitude),
+        name: e.name,
+        address: `${e.areaName}-${e.detailAddress}`,
+        success: function() {
+          console.log('success');
+        },
+      });
+      // #ifdef H5
+    }
     // #endif
   };
 

+ 7 - 5
sheep/libs/sdk-h5-weixin.js

@@ -1,9 +1,10 @@
 /**
  * 本模块封装微信浏览器下的一些方法。
  * 更多微信网页开发sdk方法,详见:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
+ * 有 the permission value is offline verifying 报错请参考 @see https://segmentfault.com/a/1190000042289419 解决
  */
 
-import jweixin, { ready } from 'weixin-js-sdk';
+import jweixin from 'weixin-js-sdk';
 import $helper from '@/sheep/helper';
 import AuthUtil from '@/sheep/api/member/auth';
 
@@ -38,7 +39,7 @@ export default {
         timestamp: data.timestamp,
         nonceStr: data.nonceStr,
         signature: data.signature,
-        jsApiList: ['chooseWXPay'], // TODO 芋艿:后续可以设置更多权限;
+        jsApiList: ['chooseWXPay', 'openLocation', 'getLocation','updateTimelineShareData','scanQRCode'], // TODO 芋艿:后续可以设置更多权限;
         openTagList: data.openTagList
       });
     }
@@ -137,9 +138,10 @@ export default {
   openLocation(data, callback) {
     this.isReady(() => {
       jweixin.openLocation({
-        //根据传入的坐标打开地图
-        latitude: data.latitude,
-        longitude: data.longitude,
+        ...data,
+        success: function (res) {
+          console.log(res);
+        }
       });
     });
   },

+ 1 - 1
sheep/platform/provider/wechat/officialAccount.js

@@ -103,5 +103,5 @@ export default {
   unbind,
   getInfo,
   getOpenid,
-  jssdk: $wxsdk,
+  jsWxSdk: $wxsdk,
 };