feat: 进入详情页更新用户坐标信息

This commit is contained in:
2025-09-03 20:49:32 +08:00
parent 248acc1423
commit c54af2a4b3
2 changed files with 37 additions and 13 deletions

View File

@@ -4,6 +4,8 @@ import { Cell, Avatar, Progress, Popover } from '@nutui/nutui-react-taro'
import Taro, { useRouter, useShareAppMessage, useShareTimeline, useDidShow } from '@tarojs/taro'
// 导入API服务
import DetailService from '../../services/detailService'
import { updateUserProfile } from '../../services/loginService'
import { getCurrentLocation } from '../../utils/locationUtils'
import {
useUserStats,
useUserActions
@@ -114,8 +116,19 @@ function Index() {
useDidShow(() => {
fetchDetail()
calcBgMainColors()
updateLocation()
})
const updateLocation = async () => {
try {
const location = await getCurrentLocation()
await updateUserProfile({ latitude: location.latitude, longitude: location.longitude })
console.log('用户位置更新成功')
} catch (error) {
console.error('用户位置更新失败', error)
}
}
const fetchDetail = async () => {
const res = await DetailService.getDetail(Number(id))
if (res.code === 0) {
@@ -552,10 +565,10 @@ function Index() {
</View>
</View>
{/* share popup */}
<SharePopup ref={sharePopupRef} id={id} from={from} />
<SharePopup ref={sharePopupRef} id={id as string} from={from as string} />
</View>
</View>
)
}
export default Index
export default Index