diff --git a/pages/user/goods_details_store/index.vue b/pages/user/goods_details_store/index.vue index 20f3e084..07b68508 100644 --- a/pages/user/goods_details_store/index.vue +++ b/pages/user/goods_details_store/index.vue @@ -32,7 +32,7 @@ - + 距离{{ item.distance.toFixed(2) }}千米 查看地图 @@ -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 { - } + 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(); - }, - complete: () => { - 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 }; diff --git a/sheep/libs/sdk-h5-weixin.js b/sheep/libs/sdk-h5-weixin.js index a71b9513..1df26f94 100644 --- a/sheep/libs/sdk-h5-weixin.js +++ b/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); + } }); }); }, diff --git a/sheep/platform/provider/wechat/officialAccount.js b/sheep/platform/provider/wechat/officialAccount.js index 2d3e5dd0..404b8660 100644 --- a/sheep/platform/provider/wechat/officialAccount.js +++ b/sheep/platform/provider/wechat/officialAccount.js @@ -103,5 +103,5 @@ export default { unbind, getInfo, getOpenid, - jssdk: $wxsdk, + jsWxSdk: $wxsdk, };