diff --git a/src/pages/detail/index.tsx b/src/pages/detail/index.tsx
index 5565e69..b8f1ae1 100644
--- a/src/pages/detail/index.tsx
+++ b/src/pages/detail/index.tsx
@@ -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() {
{/* share popup */}
-
+
)
}
-export default Index
+export default Index
\ No newline at end of file
diff --git a/src/services/loginService.ts b/src/services/loginService.ts
index d0807b3..3d1dc3f 100644
--- a/src/services/loginService.ts
+++ b/src/services/loginService.ts
@@ -43,7 +43,7 @@ export const wechat_auth_login = async (phone_code?: string): Promise => {
const response = await httpService.post('user/sms/send', {
phone: phone
});
-
+
// 修复响应检查逻辑:检查 code === 0 或 success === true
if (response.code === 0 || response.success === true) {
return {
@@ -159,7 +159,7 @@ export const verify_sms_code = async (phone: string, code: string): Promise {
accessToken: token,
expiresAt: expires_at
});
-
+
// 保存用户信息
Taro.setStorageSync('user_info', user_info);
Taro.setStorageSync('is_logged_in', true);
@@ -222,7 +222,7 @@ export const clear_login_state = () => {
try {
// 使用 tokenManager 清除令牌
tokenManager.clearTokens();
-
+
// 清除其他登录状态
Taro.removeStorageSync('user_info');
Taro.removeStorageSync('is_logged_in');
@@ -240,7 +240,7 @@ export const check_login_status = (): boolean => {
clear_login_state();
return false;
}
-
+
const is_logged_in = Taro.getStorageSync('is_logged_in');
return !!is_logged_in;
} catch (error) {
@@ -265,7 +265,7 @@ export const get_token_status = () => {
const is_valid = tokenManager.hasValidToken();
const remaining_time = tokenManager.getTokenRemainingTime();
const is_expired = tokenManager.isTokenExpired();
-
+
return {
is_valid,
remaining_time,
@@ -317,17 +317,28 @@ export const refresh_login_status = async (): Promise => {
try {
// 检查微信登录状态
const is_valid = await check_wechat_login();
-
+
if (!is_valid) {
// 微信登录已过期,需要重新登录
clear_login_state();
return false;
}
-
+
// 检查本地存储的登录状态
return check_login_status();
} catch (error) {
console.error('刷新登录状态失败:', error);
return false;
}
-};
\ No newline at end of file
+};
+
+// 更新用户信息
+export const updateUserProfile = async (payload: Partial & { latitude?: number; longitude?: number; }) => {
+ try {
+ const response = await httpService.post('user/update', payload);
+ return response;
+ } catch (error) {
+ console.error('更新用户信息失败:', error);
+ throw error;
+ }
+};
\ No newline at end of file