diff --git a/src/App.vue b/src/App.vue index 5fad15f..f571f3c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -111,6 +111,13 @@ export default { wx.ready(() => { wx.updateAppMessageShareData(shareinfo); wx.updateTimelineShareData(shareinfo); + wx.getLocation({ + type: 'gcj02', + success: (e) => { + localStorage.setItem('user_latitude', e.latitude) + localStorage.setItem('user_longitude', e.longitude) + } + }); }); wx.error((e) => { }); diff --git a/src/router.js b/src/router.js index f9839ae..832bfd8 100644 --- a/src/router.js +++ b/src/router.js @@ -31,7 +31,7 @@ const routes = [ name: 'Social', parentName: 'Index', component: () => import('./views/Tabbars/Social.vue'), - meta: { title: '加盟店', cache: true } + meta: { title: '加盟店' } }, { path: '/My', diff --git a/src/views/Tabbars/Social.vue b/src/views/Tabbars/Social.vue index b4d8aca..e351c5a 100644 --- a/src/views/Tabbars/Social.vue +++ b/src/views/Tabbars/Social.vue @@ -84,11 +84,10 @@ export default { }, } }, - async mounted() { - this.init(); - + mounted() { if (wx && this.$isWechat()) { - this.$post('/v1/client/HWxinfoClient/share', JSON.stringify(location.href)).then(res => { + let url = 'https://m.taigurun.cn' + this.$post('/v1/client/HWxinfoClient/share', JSON.stringify(url)).then(res => { const data = res.data || {}; const jsApiList = data.jsApiList || ['onMenuShareTimeline', 'onMenuShareAppMessage', 'updateAppMessageShareData', 'updateTimelineShareData', 'openLocation', 'getLocation']; const openTagList = data.openTagList || ['wx-open-launch-weapp']; @@ -111,12 +110,27 @@ export default { } }); }); + wx.error((e) => { + // window.location.reload(); + if (localStorage.getItem('latitude') && localStorage.getItem('longitude')) { + this.searchparams.latitude = localStorage.getItem('latitude'); + this.searchparams.longitude = localStorage.getItem('longitude'); + return + } else { + // this.$geo.getWebGeo().then(res => { + // this.searchparams.latitude = res.lat; + // this.searchparams.longitude = res.lon; + // }); + } + }); }); } else { - const res = await this.$geo.getWebGeo(); - this.searchparams.latitude = res.lat; - this.searchparams.longitude = res.lon; + this.$geo.getWebGeo().then(res => { + this.searchparams.latitude = res.lat; + this.searchparams.longitude = res.lon; + }); } + this.init(); this.$nextTick(() => { this.checkScroll(); const ro = new ResizeObserver(() => this.checkScroll()); diff --git a/src/views/User/ShopInfo.vue b/src/views/User/ShopInfo.vue index 46df815..fc04602 100644 --- a/src/views/User/ShopInfo.vue +++ b/src/views/User/ShopInfo.vue @@ -107,7 +107,7 @@ export default { if (wx && this.$isWechat()) { this.$post('/v1/client/HWxinfoClient/share', JSON.stringify(location.href)).then(res => { const data = res.data || {}; - const jsApiList = data.jsApiList || ['onMenuShareTimeline', 'onMenuShareAppMessage', 'updateAppMessageShareData', 'updateTimelineShareData', 'openLocation', 'getLocation']; + const jsApiList = data.jsApiList || ['openLocation']; const openTagList = data.openTagList || ['wx-open-launch-weapp']; jsApiList.push('wx-open-launch-weapp'); wx.config({ @@ -120,13 +120,6 @@ export default { openTagList: openTagList }); wx.ready(() => { - wx.getLocation({ - type: 'gcj02', - success: (e) => { - this.searchparams.latitude = e.latitude; - this.searchparams.longitude = e.longitude; - } - }); wx.openLocation({ latitude: Number(lat), longitude: Number(lon), @@ -137,19 +130,8 @@ export default { success: () => { console.log('wx.openLocation success'); }, - fail: (err) => { - console.error('wx.openLocation fail', err); - // window.open(`https://uri.amap.com/navigation?to=${lon},${lat},${fullAddress}&mode=car&src=shop`, '_blank'); - } }); }); - wx.error((err) => { - console.error('wx.error', err); - }); - // wx.error((err) => { - // console.error('wx.openLocation error', err); - // window.open(`https://uri.amap.com/navigation?to=${lon},${lat},${fullAddress}&mode=car&src=shop`, '_blank'); - // }); }); } else { window.open(`https://uri.amap.com/navigation?to=${lon},${lat},${fullAddress}&mode=car&src=shop`, '_blank');