From 3d1f33107a20d739f4e8f97c8a15bb8f9ad5076a Mon Sep 17 00:00:00 2001
From: wangxiaowei <1121133807@qq.com>
Date: Sun, 28 Dec 2025 18:33:42 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=88=97=E8=A1=A8=E7=9A=84?=
=?UTF-8?q?=E6=97=B6=E5=80=99=E9=87=8D=E6=96=B0=E8=8E=B7=E5=8F=96=E7=BB=8F?=
=?UTF-8?q?=E7=BA=AC=E5=BA=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/hooks/useLocation.ts | 28 ++++++++++++++++++++++++++++
src/pages/index/index.vue | 30 ++++++++++++++++++++++--------
2 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/src/hooks/useLocation.ts b/src/hooks/useLocation.ts
index 4b6a510..9e9188a 100644
--- a/src/hooks/useLocation.ts
+++ b/src/hooks/useLocation.ts
@@ -307,3 +307,31 @@ function shouldShowAuthModal() {
const lastDeny = uni.getStorageSync(LOCATION_DENY_TIME_KEY)
return !lastDeny || (Date.now() - lastDeny > LOCATION_DENY_INTERVAL)
}
+
+
+// 强制获取定位(不走缓存,每次都重新定位)
+export function handleForceGetLocation(): Promise<{ lat: number, lng: number }> {
+ return new Promise((resolve) => {
+ uni.authorize({
+ scope: 'scope.userLocation',
+ success() {
+ uni.getLocation({
+ type: 'gcj02',
+ success(res) {
+ console.log("🚀 ~ 开始请求定位授权:handleForceGetLocation ~ res:", res)
+ handleSetLocationCacheHooks(res.latitude, res.longitude)
+ resolve({ lat: res.latitude, lng: res.longitude })
+ },
+ fail() {
+ handleSetLocationCacheHooks(LOCATION_DEFAULT_LAT, LOCATION_DEFAULT_LNG)
+ resolve({ lat: LOCATION_DEFAULT_LAT, lng: LOCATION_DEFAULT_LNG })
+ }
+ })
+ },
+ fail() {
+ handleSetLocationCacheHooks(LOCATION_DEFAULT_LAT, LOCATION_DEFAULT_LNG)
+ resolve({ lat: LOCATION_DEFAULT_LAT, lng: LOCATION_DEFAULT_LNG })
+ }
+ })
+ })
+}
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index bb16380..3f12b4b 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -38,23 +38,23 @@
更多茶艺师点击预约
-
+
-
-
+
@@ -113,7 +113,7 @@
import { router } from '@/utils/tools'
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
import useMescroll from "@/uni_modules/mescroll-uni/hooks/useMescroll.js"
- import { LOCATION_DENY_TIME_KEY, handleEnsureLocationAuthHooks, LOCATION_DEFAULT_CITY, handleGetLocationCity, LOCATION_CITY_KEY } from '@/hooks/useLocation'
+ import { LOCATION_DENY_TIME_KEY, handleEnsureLocationAuthHooks, LOCATION_DEFAULT_CITY, handleGetLocationCity, LOCATION_CITY_KEY, handleForceGetLocation } from '@/hooks/useLocation'
import { getHomeBannerList } from '@/api/home'
import { getHomeTeaStoreList } from '@/api/tea-room'
import { useUserStore } from '@/store'
@@ -142,7 +142,13 @@
const city_id = ref(0)
let lastLocation = { lat: 0, lng: 0 }
+ const canLocation = ref(false)
onShow(async () => {
+ // if (canLocation) {
+ // const location = await handleGetLocationCity(latitude.value, longitude.value)
+ // Index.handleResetSearch()
+ // }
+ // canLocation.value = true
if (uni.getStorageSync(LOCATION_DENY_TIME_KEY)) {
const location = await checkLocationAuthWithModal()
if (location) {
@@ -186,10 +192,18 @@
* 茶室门店列表
* @param mescroll
*/
- upCallback: (mescroll) => {
+ upCallback: async (mescroll) => {
const userStore = useUserStore()
const userId = userStore.userInfo?.id || 0
+ if (canLocation.value ) {
+ console.log("🚀 ~ 重置定位:", canLocation)
+ const location = await handleEnsureLocationAuthHooks()
+ latitude.value = location.lat
+ longitude.value = location.lng
+ }
+ canLocation.value = true
+
const filter = {
page: mescroll.num,
size: mescroll.size,