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,