From 656c27fdb87fa3da9431fafbb86ac6ab0c15b9bf Mon Sep 17 00:00:00 2001 From: lifizer <913626195@qq.com> Date: Thu, 21 May 2026 16:37:02 +0800 Subject: [PATCH] =?UTF-8?q?Refactor(=E9=A6=96=E9=A1=B5):=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E5=AE=9A=E4=BD=8D=E6=88=90=E5=8A=9F=E5=92=8C?= =?UTF-8?q?=E4=B8=8A=E4=B8=80=E6=AC=A1=E7=9A=84=E5=AE=9A=E4=BD=8D=E5=9F=8E?= =?UTF-8?q?=E5=B8=82=E4=B8=8D=E5=90=8C=EF=BC=8C=E6=89=8D=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=9F=8E=E5=B8=82=E5=90=8D=E7=A7=B0=EF=BC=8C=E5=B9=B6=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E8=8E=B7=E5=8F=96=E9=A6=96=E9=A1=B5=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/index.vue | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 => {