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.ready(() => {
wx.updateAppMessageShareData(shareinfo); wx.updateAppMessageShareData(shareinfo);
wx.updateTimelineShareData(shareinfo); wx.updateTimelineShareData(shareinfo);
wx.getLocation({ // wx.getLocation({
type: 'gcj02', // type: 'gcj02',
success: (e) => { // success: (e) => {
localStorage.setItem('user_latitude', e.latitude) // localStorage.setItem('user_latitude', e.latitude)
localStorage.setItem('user_longitude', e.longitude) // localStorage.setItem('user_longitude', e.longitude)
} // }
}); // });
}); });
wx.error((e) => { wx.error((e) => {
}); });

View File

@ -85,51 +85,7 @@ export default {
} }
}, },
mounted() { mounted() {
if (wx && this.$isWechat()) { this.initLocation();
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.init(); this.init();
this.$nextTick(() => { this.$nextTick(() => {
this.checkScroll(); this.checkScroll();
@ -188,6 +144,55 @@ export default {
onSearchInput() { onSearchInput() {
this.searchparams.shopname = this.searchQuery; 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> </script>

View File

@ -74,7 +74,8 @@ export default {
} }
}, },
mounted() { mounted() {
this.init() this.init();
this.initLocation();
}, },
methods: { methods: {
init() { init() {
@ -93,6 +94,37 @@ export default {
this.$showImagePreview({ images: [imageUrl], startPosition: 0 }); 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() { openMap() {
if (this.shopInfo.shoplatitude && this.shopInfo.shoplongitude) { if (this.shopInfo.shoplatitude && this.shopInfo.shoplongitude) {
const lat = this.shopInfo.shoplatitude; const lat = this.shopInfo.shoplatitude;
@ -105,37 +137,22 @@ export default {
(this.shopInfo.shopaddress || '') (this.shopInfo.shopaddress || '')
); );
if (wx && this.$isWechat()) { if (wx && this.$isWechat()) {
this.$post('/v1/client/HWxinfoClient/share', JSON.stringify(location.href)).then(res => { wx.ready(() => {
const data = res.data || {}; wx.openLocation({
const jsApiList = data.jsApiList || ['openLocation']; latitude: Number(lat),
const openTagList = data.openTagList || ['wx-open-launch-weapp']; longitude: Number(lon),
jsApiList.push('wx-open-launch-weapp'); name: this.shopInfo.shopname || '',
wx.config({ address: fullAddress,
debug: false, scale: 15,
appId: data.appid, infoUrl: '',
timestamp: Number(data.timestamp) || 0, success: () => {
nonceStr: data.noncestr, console.log('wx.openLocation success');
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');
},
});
}); });
}); });
} 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');
} }
}, },
} }