添加收藏茶室接口和完善茶室详情

This commit is contained in:
wangxiaowei
2025-11-12 17:40:35 +08:00
parent 29bf4dae74
commit 0cad65c295
32 changed files with 1522 additions and 505 deletions

View File

@ -1,13 +1,12 @@
import { router } from '@/utils/tools'
const LOCATION_EXPIRE_MS = 30 * 24 * 60 * 60 * 1000 // 定位缓存30天
const LOCATION_DENY_INTERVAL = 60 * 60 * 1000 // 未授权定位弹窗间隔1小时
const LOCATION_EXPIRE_KEY = import.meta.env.VITE_DEFAULT_LOCATION_EXPIRE_KEY // 定位缓存KEY
const LOCATION_EXPIRE_MS = import.meta.env.VITE_DEFAULT_LOCATION_EXPIRE_MS // 30天
const LOCATION_DEFAULT_CITY = import.meta.env.VITE_DEFAULT_ADDRESS // 默认城市
const LOCATION_DEFAULT_LAT = import.meta.env.VITE_DEFAULT_LATITUDE // 上海经度
const LOCATION_DEFAULT_LNG = import.meta.env.VITE_DEFAULT_LONGITUDE // 上海纬度
const LOCATION_DENY_TIME_KEY = import.meta.env.VITE_DEFAULT_LOCATION_DENY_TIME_KEY
const LOCATION_DENY_INTERVAL = import.meta.env.VITE_DEFAULT_LOCATION_DENY_INTERVAL
export const LOCATION_EXPIRE_KEY = 'location_expire_time' // 定位缓存KEY
export const LOCATION_DEFAULT_CITY = '上海市' // 默认城市
export const LOCATION_DEFAULT_LAT = 34.757975 // 上海经度
export const LOCATION_DEFAULT_LNG = 113.665412 // 上海纬度
export const LOCATION_DENY_TIME_KEY = 'location_deny_time' // 未授权定位重新授权时间KEY
export const LOCATION_CITY_KEY = 'city' // 城市缓存KEY
// 检查过期时间
export function handleCheckLocationCacheHooks() {
@ -50,6 +49,7 @@ export async function handleEnsureLocationAuthHooks() {
},
fail() {
// 定位失败,返回默认上海
handleSetLocationCacheHooks(LOCATION_DEFAULT_LAT, LOCATION_DEFAULT_LNG)
resolve({ lat: LOCATION_DEFAULT_LAT, lng: LOCATION_DEFAULT_LNG })
}
})
@ -69,12 +69,88 @@ export async function handleEnsureLocationAuthHooks() {
})
}
// 返回默认上海
handleSetLocationCacheHooks(LOCATION_DEFAULT_LAT, LOCATION_DEFAULT_LNG)
resolve({ lat: LOCATION_DEFAULT_LAT, lng: LOCATION_DEFAULT_LNG })
}
})
})
}
/**
* 检查并弹窗授权地理位置(每小时弹一次,授权后自动获取定位)
* 返回 Promise<boolean>true 表示已授权false 表示未授权
*/
export function checkLocationAuthWithModal(): Promise<{ lat: number, lng: number } | false> {
return new Promise((resolve) => {
uni.getSetting({
success(settingRes) {
const hasAuth = settingRes.authSetting && settingRes.authSetting['scope.userLocation']
if (hasAuth) {
// 已授权,自动获取并返回经纬度
uni.getLocation({
type: 'gcj02',
success(res) {
handleSetLocationCacheHooks(res.latitude, res.longitude)
resolve({ lat: res.latitude, lng: res.longitude })
},
fail() {
resolve(false)
}
})
} else {
// 未授权,判断是否需要弹窗
const lastDeny = uni.getStorageSync(LOCATION_DENY_TIME_KEY)
if (!lastDeny || (Date.now() - lastDeny > LOCATION_DENY_INTERVAL)) {
uni.setStorageSync(LOCATION_DENY_TIME_KEY, Date.now())
uni.showModal({
title: '提示',
content: '需要获取您的地理位置,请授权定位服务',
showCancel: false,
success: () => {
uni.openSetting({
success(openRes) {
const nowAuth = openRes.authSetting && openRes.authSetting['scope.userLocation']
if (nowAuth) {
// 用户授权后,自动获取并返回经纬度
uni.getLocation({
type: 'gcj02',
success(res) {
handleSetLocationCacheHooks(res.latitude, res.longitude)
resolve({ lat: res.latitude, lng: res.longitude })
},
fail() {
resolve(false)
}
})
} else {
resolve(false)
}
}
})
}
})
} else {
resolve(false)
}
}
},
fail() {
resolve(false)
}
})
})
}
/**
* 设置城市
*/
export function setLocationCity(city: string) {
uni.setStorageSync(LOCATION_CITY_KEY, city)
}
// 检查是否需要弹授权框
function shouldShowAuthModal() {
const lastDeny = uni.getStorageSync(LOCATION_DENY_TIME_KEY)