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

@@ -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;
}
};