feat: 进入详情页更新用户坐标信息
This commit is contained in:
@@ -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
|
||||
@@ -43,7 +43,7 @@ export const wechat_auth_login = async (phone_code?: string): Promise<LoginRespo
|
||||
try {
|
||||
// 先进行微信登录获取code
|
||||
const login_result = await Taro.login();
|
||||
|
||||
|
||||
if (!login_result.code) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -93,7 +93,7 @@ export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginR
|
||||
phone: params.phone,
|
||||
code: params.verification_code
|
||||
});
|
||||
|
||||
|
||||
if (verify_response.code===0) {
|
||||
return {
|
||||
success: true,
|
||||
@@ -130,7 +130,7 @@ export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
|
||||
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<Veri
|
||||
phone: phone,
|
||||
code: code
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
success: response.success,
|
||||
message: response.message || '验证失败',
|
||||
@@ -207,7 +207,7 @@ export const save_login_state = (token: string, user_info: WechatUserInfo) => {
|
||||
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<boolean> => {
|
||||
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;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// 更新用户信息
|
||||
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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user