修改首页获取定位

This commit is contained in:
lcc
2025-10-16 11:00:28 +08:00
parent 4b51d24d21
commit fecde0f3c1
+28 -2
View File
@@ -2,12 +2,12 @@
<div class="scroll-y city-choose-list" style="height: 100%;">
<div class="fn-flex fn-flex-center font-24 inner30 bg-fa">
<template v-if="city_info.cityName">
<div class="fn-flex-item fn-flex fn-flex-center">
<div class="fn-flex-item fn-flex fn-flex-center" @click="reloadHome">
<van-icon name="guide-o" />
<span>当前城市</span>
<span>{{city_info.cityName}}</span>
</div>
<div class="fn-flex fn-flex-center" @click="refreshLocaiton">
<div class="fn-flex fn-flex-center" @click="resetCityName">
<van-icon name="replay" />
<span>定位</span>
</div>
@@ -113,6 +113,32 @@ export default {
})
}
},
async reloadHome(){
console.log('城市信息:', this.city_info);
if(this.city_info){
this.$emit('cityItem',{
cityName: this.city_info.cityName,
cityId: this.city_info.cityId
})
}
},
async resetCityName() {
const location = await WechatLocation.getLocation('gcj02');
const result = await api.wechatAPI.getLocationCity(location.latitude, location.longitude);
console.log('刷新定位:', result);
console.log('刷新定位location:', location);
if (result.code === 200 && result.data) {
const userStore = useUserStore();
// this.list = result.data;
this.city_info = {
cityName: result.data.cityName,
cityId: result.data.cityId
};
// localStorage.setItem('cityInfo', JSON.stringify(result.data));
// localStorage.setItem('userLocation', JSON.stringify({ ...location, time: new Date().getTime() }));
userStore.setCity(result.data);
}
},
handleClickItem(item){
this.city_info = {
cityName: item.city_name,