From 65aa2710988ce6d28d6470f9fff35c68a42478fd Mon Sep 17 00:00:00 2001 From: wangxiaowei <1121133807@qq.com> Date: Tue, 6 Jan 2026 16:26:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=9C=B0=E7=90=86=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useLocation.ts | 12 ++++++------ src/pages/index/index.vue | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/hooks/useLocation.ts b/src/hooks/useLocation.ts index 9e9188a..0ffd7c1 100644 --- a/src/hooks/useLocation.ts +++ b/src/hooks/useLocation.ts @@ -152,12 +152,12 @@ export function handleSetLocationCacheHooks(lat: number, lng: number) { // VERSION1: 初始化经纬度 export async function handleEnsureLocationAuthHooks() { - // 1. 检查缓存 - if (handleCheckLocationCacheHooks()) { - const lat = uni.getStorageSync(LOCATION_LAT_KEY) - const lng = uni.getStorageSync(LOCATION_LNG_KEY) - if (lat && lng) return { lat, lng } - } + // 1. 检查缓存-先把缓存去掉 + // if (handleCheckLocationCacheHooks()) { + // const lat = uni.getStorageSync(LOCATION_LAT_KEY) + // const lng = uni.getStorageSync(LOCATION_LNG_KEY) + // if (lat && lng) return { lat, lng } + // } // 2. 获取定位 return new Promise<{ lat: number, lng: number, }>((resolve) => { diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index e962d47..7c6cab2 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -182,9 +182,10 @@ onShow(async () => { // if (canLocation) { // const location = await handleGetLocationCity(latitude.value, longitude.value) - // Index.handleResetSearch() + // Index.handleResetSearch() // } // canLocation.value = true + // 检测用户授权地理位置的缓存LOCATION_DENY_TIME_KEY if (uni.getStorageSync(LOCATION_DENY_TIME_KEY)) { const location = await checkLocationAuthWithModal() if (location) { @@ -221,8 +222,9 @@ // 获取用户经纬度(带缓存和授权逻辑) const { lat, lng } = await handleEnsureLocationAuthHooks() latitude.value = lat - longitude.value = lng + longitude.value = lng + // 根据经纬度获取城市信息再重新赋值经纬度和城市 const location = await handleGetLocationCity(lat, lng) city.value = location.city latitude.value = location.latitude