Refactor(首页):如果当前定位成功和上一次的定位城市不同,才更新城市名称,并重新获取首页的数据

This commit is contained in:
lifizer
2026-05-21 16:37:02 +08:00
parent 2cddb59530
commit 656c27fdb8
+18 -3
View File
@@ -713,6 +713,9 @@ export default {
const { data } = res const { data } = res
this.bannerList = data.banner || [] this.bannerList = data.banner || []
}) })
console.timeEnd()
console.log('^^^^^^^^^^^^^^^^获取定位开始')
console.time()
this.getLocationData() this.getLocationData()
}, },
// 定位失败,重新唤起定位授权 // 定位失败,重新唤起定位授权
@@ -723,16 +726,25 @@ export default {
})) }))
}, },
getLocationData() { getLocationData() {
const cityName = uni.getStorageSync('locationCityName')
if (cityName) {
this.cityName = cityName
this.getPageData()
}
this.isLocating = true this.isLocating = true
getLocationPromise().then(mapData => { getLocationPromise().then(mapData => {
if (mapData.errMsg) { if (mapData.errMsg) {
const { latitude, longitude } = mapData const { latitude, longitude } = mapData
getCurAddress(latitude, longitude, address => { getCurAddress(latitude, longitude, address => {
console.log(address) console.log(address)
this.cityName = address.city const resCityName = address.city || ''
uni.setStorageSync('locationCityName', this.cityName) // 如果当前定位成功和上一次的定位城市不同,才更新城市名称
if (resCityName !== this.cityName) {
this.cityName = address.city
uni.setStorageSync('locationCityName', this.cityName)
this.getPageData()
}
this.isLocating = false this.isLocating = false
this.getPageData()
}) })
} else { } else {
this.isLocating = false this.isLocating = false
@@ -743,6 +755,9 @@ export default {
}) })
}, },
getPageData() { getPageData() {
console.timeEnd()
console.log('^^^^^^^^^^^^^^^^获取定位成功/失败开始获取首页数据')
console.time()
const _this = this const _this = this
uni.showLoading({ title: '加载中' }) uni.showLoading({ title: '加载中' })
getHomeData({ cityName: this.cityName }).then(res => { getHomeData({ cityName: this.cityName }).then(res => {