Merge remote-tracking branch 'origin' into feat/liujie

This commit is contained in:
2025-08-24 15:55:13 +08:00
98 changed files with 10184 additions and 83 deletions

View File

@@ -0,0 +1,92 @@
import Taro from '@tarojs/taro'
export interface LocationInfo {
latitude: number
longitude: number
address: string
name?: string
}
// 获取当前位置
export const getCurrentLocation = (): Promise<LocationInfo> => {
return new Promise((resolve, reject) => {
Taro.getLocation({
type: 'wgs84',
success: (res) => {
// 使用逆地理编码获取地址信息
reverseGeocode(res.latitude, res.longitude)
.then(address => {
resolve({
latitude: res.latitude,
longitude: res.longitude,
address
})
})
.catch(() => {
resolve({
latitude: res.latitude,
longitude: res.longitude,
address: `${res.latitude.toFixed(6)}, ${res.longitude.toFixed(6)}`
})
})
},
fail: (error) => {
reject(error)
}
})
})
}
// 选择地图位置
export const chooseLocation = (): Promise<LocationInfo> => {
return new Promise((resolve, reject) => {
Taro.chooseLocation({
success: (res) => {
resolve({
latitude: res.latitude,
longitude: res.longitude,
address: res.address,
name: res.name
})
},
fail: (error) => {
reject(error)
}
})
})
}
// 逆地理编码简化版本实际项目中应该调用真实的地图服务API
export const reverseGeocode = (latitude: number, longitude: number): Promise<string> => {
return new Promise((resolve) => {
// 这里应该调用真实的地图服务API比如腾讯地图、高德地图等
// 暂时返回坐标字符串
setTimeout(() => {
resolve(`纬度:${latitude.toFixed(6)}, 经度:${longitude.toFixed(6)}`)
}, 500)
})
}
// 计算两点间距离(单位:米)
export const calculateDistance = (
lat1: number,
lng1: number,
lat2: number,
lng2: number
): number => {
const radLat1 = lat1 * Math.PI / 180.0
const radLat2 = lat2 * Math.PI / 180.0
const a = radLat1 - radLat2
const b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0
let s = 2 * Math.asin(Math.sqrt(
Math.pow(Math.sin(a/2), 2) +
Math.cos(radLat1) * Math.cos(radLat2) *
Math.pow(Math.sin(b/2), 2)
))
s = s * 6378.137 // 地球半径
s = Math.round(s * 10000) / 10000
return s * 1000 // 转换为米
}

View File

@@ -85,6 +85,17 @@ class TokenManager {
return !!token && !this.isTokenExpired()
}
// 获取令牌剩余有效时间(毫秒)
getTokenRemainingTime(): number {
const expiresAt = this.getTokenExpires()
if (!expiresAt) {
return 0 // 如果没有过期时间返回0
}
const remaining = expiresAt - Date.now()
return remaining > 0 ? remaining : 0
}
// 获取Authorization头
getAuthHeader(): Record<string, string> {
const token = this.getAccessToken()
@@ -93,7 +104,7 @@ class TokenManager {
}
return {
'Authorization': `Bearer ${token}`
'applet-token': `${token}`
}
}
}