1
This commit is contained in:
parent
960d43ba01
commit
a197797f9b
14
src/App.vue
14
src/App.vue
@ -111,13 +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.getLocation({
|
||||
// type: 'gcj02',
|
||||
// success: (e) => {
|
||||
// localStorage.setItem('user_latitude', e.latitude)
|
||||
// localStorage.setItem('user_longitude', e.longitude)
|
||||
// }
|
||||
// });
|
||||
});
|
||||
wx.error((e) => {
|
||||
});
|
||||
|
||||
@ -85,51 +85,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (wx && this.$isWechat()) {
|
||||
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'];
|
||||
jsApiList.push('wx-open-launch-weapp');
|
||||
wx.config({
|
||||
debug: false,
|
||||
appId: data.appid,
|
||||
timestamp: Number(data.timestamp) || 0,
|
||||
nonceStr: data.noncestr,
|
||||
signature: data.signature,
|
||||
jsApiList: jsApiList,
|
||||
openTagList: openTagList
|
||||
});
|
||||
wx.ready(() => {
|
||||
wx.getLocation({
|
||||
type: 'gcj02',
|
||||
success: (e) => {
|
||||
this.searchparams.latitude = e.latitude;
|
||||
this.searchparams.longitude = e.longitude;
|
||||
}
|
||||
});
|
||||
});
|
||||
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 {
|
||||
this.$geo.getWebGeo().then(res => {
|
||||
this.searchparams.latitude = res.lat;
|
||||
this.searchparams.longitude = res.lon;
|
||||
});
|
||||
}
|
||||
this.initLocation();
|
||||
this.init();
|
||||
this.$nextTick(() => {
|
||||
this.checkScroll();
|
||||
@ -188,6 +144,55 @@ export default {
|
||||
onSearchInput() {
|
||||
this.searchparams.shopname = this.searchQuery;
|
||||
},
|
||||
initLocation() {
|
||||
if (wx && this.$isWechat()) {
|
||||
this.$post('/v1/client/HWxinfoClient/share', JSON.stringify(location.href)).then(res => {
|
||||
const data = res.data || {};
|
||||
const jsApiList = data.jsApiList || ['getLocation'];
|
||||
const openTagList = data.openTagList || ['wx-open-launch-weapp'];
|
||||
jsApiList.push('wx-open-launch-weapp');
|
||||
wx.config({
|
||||
debug: false,
|
||||
appId: data.appid,
|
||||
timestamp: Number(data.timestamp) || 0,
|
||||
nonceStr: data.noncestr,
|
||||
signature: data.signature,
|
||||
jsApiList: jsApiList,
|
||||
openTagList: openTagList
|
||||
});
|
||||
wx.ready(() => {
|
||||
wx.getLocation({
|
||||
type: 'gcj02',
|
||||
success: (e) => {
|
||||
this.searchparams.latitude = e.latitude;
|
||||
this.searchparams.longitude = e.longitude;
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('定位失败:', err)
|
||||
// this.$showToast('定位被拒绝,请重新进入页面获取定位')
|
||||
},
|
||||
});
|
||||
});
|
||||
wx.error((e) => {
|
||||
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 {
|
||||
this.$geo.getWebGeo().then(res => {
|
||||
this.searchparams.latitude = res.lat;
|
||||
this.searchparams.longitude = res.lon;
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@ -74,7 +74,8 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.init()
|
||||
this.init();
|
||||
this.initLocation();
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
@ -93,6 +94,37 @@ export default {
|
||||
this.$showImagePreview({ images: [imageUrl], startPosition: 0 });
|
||||
}
|
||||
},
|
||||
initLocation() {
|
||||
if (wx && this.$isWechat()) {
|
||||
this.$post('/v1/client/HWxinfoClient/share', JSON.stringify(location.href)).then(res => {
|
||||
const data = res.data || {};
|
||||
const jsApiList = data.jsApiList || ['getLocation', 'openLocation'];
|
||||
const openTagList = data.openTagList || ['wx-open-launch-weapp'];
|
||||
jsApiList.push('wx-open-launch-weapp');
|
||||
wx.config({
|
||||
debug: false,
|
||||
appId: data.appid,
|
||||
timestamp: Number(data.timestamp) || 0,
|
||||
nonceStr: data.noncestr,
|
||||
signature: data.signature,
|
||||
jsApiList: jsApiList,
|
||||
openTagList: openTagList
|
||||
});
|
||||
// 预获取定位权限,用户点击地图时可以直接打开
|
||||
// wx.ready(() => {
|
||||
// wx.getLocation({
|
||||
// type: 'gcj02',
|
||||
// success: () => {
|
||||
// console.log('定位权限获取成功');
|
||||
// },
|
||||
// fail: () => {
|
||||
// console.log('定位权限获取失败');
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
});
|
||||
}
|
||||
},
|
||||
openMap() {
|
||||
if (this.shopInfo.shoplatitude && this.shopInfo.shoplongitude) {
|
||||
const lat = this.shopInfo.shoplatitude;
|
||||
@ -105,37 +137,22 @@ export default {
|
||||
(this.shopInfo.shopaddress || '')
|
||||
);
|
||||
if (wx && this.$isWechat()) {
|
||||
this.$post('/v1/client/HWxinfoClient/share', JSON.stringify(location.href)).then(res => {
|
||||
const data = res.data || {};
|
||||
const jsApiList = data.jsApiList || ['openLocation'];
|
||||
const openTagList = data.openTagList || ['wx-open-launch-weapp'];
|
||||
jsApiList.push('wx-open-launch-weapp');
|
||||
wx.config({
|
||||
debug: false,
|
||||
appId: data.appid,
|
||||
timestamp: Number(data.timestamp) || 0,
|
||||
nonceStr: data.noncestr,
|
||||
signature: data.signature,
|
||||
jsApiList: jsApiList,
|
||||
openTagList: openTagList
|
||||
});
|
||||
wx.ready(() => {
|
||||
wx.openLocation({
|
||||
latitude: Number(lat),
|
||||
longitude: Number(lon),
|
||||
name: this.shopInfo.shopname || '',
|
||||
address: fullAddress,
|
||||
scale: 15,
|
||||
infoUrl: '',
|
||||
success: () => {
|
||||
console.log('wx.openLocation success');
|
||||
},
|
||||
});
|
||||
wx.ready(() => {
|
||||
wx.openLocation({
|
||||
latitude: Number(lat),
|
||||
longitude: Number(lon),
|
||||
name: this.shopInfo.shopname || '',
|
||||
address: fullAddress,
|
||||
scale: 15,
|
||||
infoUrl: '',
|
||||
success: () => {
|
||||
console.log('wx.openLocation success');
|
||||
},
|
||||
});
|
||||
});
|
||||
} else {
|
||||
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');
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user