This commit is contained in:
chenhao 2026-06-05 13:48:17 +08:00
parent 960d43ba01
commit a197797f9b
3 changed files with 103 additions and 81 deletions

View File

@ -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) => {
});

View File

@ -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>

View File

@ -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,20 +137,6 @@ 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),
@ -132,11 +150,10 @@ export default {
},
});
});
});
}
} else {
window.open(`https://uri.amap.com/navigation?to=${lon},${lat},${fullAddress}&mode=car&src=shop`, '_blank');
}
}
},
}
}