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'
|
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,10 +565,10 @@ 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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Index
|
export default Index
|
||||||
@@ -43,7 +43,7 @@ export const wechat_auth_login = async (phone_code?: string): Promise<LoginRespo
|
|||||||
try {
|
try {
|
||||||
// 先进行微信登录获取code
|
// 先进行微信登录获取code
|
||||||
const login_result = await Taro.login();
|
const login_result = await Taro.login();
|
||||||
|
|
||||||
if (!login_result.code) {
|
if (!login_result.code) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -93,7 +93,7 @@ export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginR
|
|||||||
phone: params.phone,
|
phone: params.phone,
|
||||||
code: params.verification_code
|
code: params.verification_code
|
||||||
});
|
});
|
||||||
|
|
||||||
if (verify_response.code===0) {
|
if (verify_response.code===0) {
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -130,7 +130,7 @@ export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
|
|||||||
const response = await httpService.post('user/sms/send', {
|
const response = await httpService.post('user/sms/send', {
|
||||||
phone: phone
|
phone: phone
|
||||||
});
|
});
|
||||||
|
|
||||||
// 修复响应检查逻辑:检查 code === 0 或 success === true
|
// 修复响应检查逻辑:检查 code === 0 或 success === true
|
||||||
if (response.code === 0 || response.success === true) {
|
if (response.code === 0 || response.success === true) {
|
||||||
return {
|
return {
|
||||||
@@ -159,7 +159,7 @@ export const verify_sms_code = async (phone: string, code: string): Promise<Veri
|
|||||||
phone: phone,
|
phone: phone,
|
||||||
code: code
|
code: code
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: response.success,
|
success: response.success,
|
||||||
message: response.message || '验证失败',
|
message: response.message || '验证失败',
|
||||||
@@ -207,7 +207,7 @@ export const save_login_state = (token: string, user_info: WechatUserInfo) => {
|
|||||||
accessToken: token,
|
accessToken: token,
|
||||||
expiresAt: expires_at
|
expiresAt: expires_at
|
||||||
});
|
});
|
||||||
|
|
||||||
// 保存用户信息
|
// 保存用户信息
|
||||||
Taro.setStorageSync('user_info', user_info);
|
Taro.setStorageSync('user_info', user_info);
|
||||||
Taro.setStorageSync('is_logged_in', true);
|
Taro.setStorageSync('is_logged_in', true);
|
||||||
@@ -222,7 +222,7 @@ export const clear_login_state = () => {
|
|||||||
try {
|
try {
|
||||||
// 使用 tokenManager 清除令牌
|
// 使用 tokenManager 清除令牌
|
||||||
tokenManager.clearTokens();
|
tokenManager.clearTokens();
|
||||||
|
|
||||||
// 清除其他登录状态
|
// 清除其他登录状态
|
||||||
Taro.removeStorageSync('user_info');
|
Taro.removeStorageSync('user_info');
|
||||||
Taro.removeStorageSync('is_logged_in');
|
Taro.removeStorageSync('is_logged_in');
|
||||||
@@ -240,7 +240,7 @@ export const check_login_status = (): boolean => {
|
|||||||
clear_login_state();
|
clear_login_state();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const is_logged_in = Taro.getStorageSync('is_logged_in');
|
const is_logged_in = Taro.getStorageSync('is_logged_in');
|
||||||
return !!is_logged_in;
|
return !!is_logged_in;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -265,7 +265,7 @@ export const get_token_status = () => {
|
|||||||
const is_valid = tokenManager.hasValidToken();
|
const is_valid = tokenManager.hasValidToken();
|
||||||
const remaining_time = tokenManager.getTokenRemainingTime();
|
const remaining_time = tokenManager.getTokenRemainingTime();
|
||||||
const is_expired = tokenManager.isTokenExpired();
|
const is_expired = tokenManager.isTokenExpired();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
is_valid,
|
is_valid,
|
||||||
remaining_time,
|
remaining_time,
|
||||||
@@ -317,17 +317,28 @@ export const refresh_login_status = async (): Promise<boolean> => {
|
|||||||
try {
|
try {
|
||||||
// 检查微信登录状态
|
// 检查微信登录状态
|
||||||
const is_valid = await check_wechat_login();
|
const is_valid = await check_wechat_login();
|
||||||
|
|
||||||
if (!is_valid) {
|
if (!is_valid) {
|
||||||
// 微信登录已过期,需要重新登录
|
// 微信登录已过期,需要重新登录
|
||||||
clear_login_state();
|
clear_login_state();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查本地存储的登录状态
|
// 检查本地存储的登录状态
|
||||||
return check_login_status();
|
return check_login_status();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('刷新登录状态失败:', error);
|
console.error('刷新登录状态失败:', error);
|
||||||
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user