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' import Taro, { useRouter, useShareAppMessage, useShareTimeline, useDidShow } from '@tarojs/taro'
// 导入API服务 // 导入API服务
import DetailService from '../../services/detailService' import DetailService from '../../services/detailService'
import { updateUserProfile } from '../../services/loginService'
import { getCurrentLocation } from '../../utils/locationUtils'
import { import {
useUserStats, useUserStats,
useUserActions useUserActions
@@ -114,8 +116,19 @@ function Index() {
useDidShow(() => { useDidShow(() => {
fetchDetail() fetchDetail()
calcBgMainColors() 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 fetchDetail = async () => {
const res = await DetailService.getDetail(Number(id)) const res = await DetailService.getDetail(Number(id))
if (res.code === 0) { if (res.code === 0) {
@@ -552,7 +565,7 @@ function Index() {
</View> </View>
</View> </View>
{/* share popup */} {/* share popup */}
<SharePopup ref={sharePopupRef} id={id} from={from} /> <SharePopup ref={sharePopupRef} id={id as string} from={from as string} />
</View> </View>
</View> </View>
) )

View File

@@ -331,3 +331,14 @@ export const refresh_login_status = async (): Promise<boolean> => {
return false; return false;
} }
}; };
// 更新用户信息
export const updateUserProfile = async (payload: Partial<WechatUserInfo> & { latitude?: number; longitude?: number; }) => {
try {
const response = await httpService.post('user/update', payload);
return response;
} catch (error) {
console.error('更新用户信息失败:', error);
throw error;
}
};