diff --git a/pages/home/index.vue b/pages/home/index.vue index 719fd1b..9bb2c98 100644 --- a/pages/home/index.vue +++ b/pages/home/index.vue @@ -713,6 +713,9 @@ export default { const { data } = res this.bannerList = data.banner || [] }) + console.timeEnd() + console.log('^^^^^^^^^^^^^^^^获取定位开始') + console.time() this.getLocationData() }, // 定位失败,重新唤起定位授权 @@ -723,16 +726,25 @@ export default { })) }, getLocationData() { + const cityName = uni.getStorageSync('locationCityName') + if (cityName) { + this.cityName = cityName + this.getPageData() + } this.isLocating = true getLocationPromise().then(mapData => { if (mapData.errMsg) { const { latitude, longitude } = mapData getCurAddress(latitude, longitude, address => { console.log(address) - this.cityName = address.city - uni.setStorageSync('locationCityName', this.cityName) + const resCityName = address.city || '' + // 如果当前定位成功和上一次的定位城市不同,才更新城市名称 + if (resCityName !== this.cityName) { + this.cityName = address.city + uni.setStorageSync('locationCityName', this.cityName) + this.getPageData() + } this.isLocating = false - this.getPageData() }) } else { this.isLocating = false @@ -743,6 +755,9 @@ export default { }) }, getPageData() { + console.timeEnd() + console.log('^^^^^^^^^^^^^^^^获取定位成功/失败开始获取首页数据') + console.time() const _this = this uni.showLoading({ title: '加载中' }) getHomeData({ cityName: this.cityName }).then(res => {