Merge branch 'light_v2'
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Taro from "@tarojs/taro";
|
||||
import httpService, { ApiResponse } from "./httpService";
|
||||
import tokenManager from "../utils/tokenManager";
|
||||
import tokenManager from '../utils/tokenManager';
|
||||
import { useUser } from '@/store/userStore';
|
||||
|
||||
// 微信用户信息接口
|
||||
export interface WechatUserInfo {
|
||||
@@ -42,6 +43,13 @@ export interface UserStats {
|
||||
participated_games_count: number;
|
||||
}
|
||||
|
||||
// 手机号验证码登录接口参数
|
||||
export interface PhoneLoginParams {
|
||||
phone: string;
|
||||
verification_code: string;
|
||||
user_code: string
|
||||
}
|
||||
|
||||
export interface UserInfoType {
|
||||
subscribe_time: string;
|
||||
last_login_time: string;
|
||||
@@ -91,6 +99,13 @@ export const wechat_auth_login = async (
|
||||
});
|
||||
|
||||
if (auth_response.code === 0) {
|
||||
// 登录成功后,更新用户信息到 store
|
||||
try {
|
||||
await useUser.getState().fetchUserInfo();
|
||||
} catch (error) {
|
||||
console.error('更新用户信息到 store 失败:', error);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "微信登录成功",
|
||||
@@ -132,6 +147,13 @@ export const phone_auth_login = async (
|
||||
});
|
||||
|
||||
if (verify_response.code === 0) {
|
||||
// 登录成功后,更新用户信息到 store
|
||||
try {
|
||||
await useUser.getState().fetchUserInfo();
|
||||
} catch (error) {
|
||||
console.error('更新用户信息到 store 失败:', error);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "登录成功",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { UserInfo } from '@/components/UserInfo';
|
||||
import Taro from '@tarojs/taro';
|
||||
import { API_CONFIG } from '@/config/api';
|
||||
import httpService from './httpService';
|
||||
import httpService, { ApiResponse } from './httpService';
|
||||
import uploadFiles from './uploadFiles';
|
||||
import Taro from '@tarojs/taro';
|
||||
|
||||
|
||||
// 用户详情接口
|
||||
@@ -35,55 +35,28 @@ interface UserDetailData {
|
||||
};
|
||||
}
|
||||
|
||||
// 更新用户信息参数接口
|
||||
interface UpdateUserParams {
|
||||
nickname: string;
|
||||
avatar_url: string;
|
||||
gender: string;
|
||||
phone: string;
|
||||
latitude?: string;
|
||||
longitude?: string;
|
||||
city: string;
|
||||
province: string;
|
||||
country: string;
|
||||
|
||||
// 用户详细信息接口(从 loginService 移过来)
|
||||
export interface UserInfoType {
|
||||
id: number
|
||||
openid: string
|
||||
unionid: string
|
||||
session_key: string
|
||||
nickname: string
|
||||
avatar_url: string
|
||||
gender: string
|
||||
country: string
|
||||
province: string
|
||||
city: string
|
||||
district:string
|
||||
language: string
|
||||
phone: string
|
||||
is_subscribed: string
|
||||
latitude: number
|
||||
longitude: number
|
||||
subscribe_time: string
|
||||
last_login_time: string
|
||||
}
|
||||
|
||||
// 上传响应接口
|
||||
interface UploadResponseData {
|
||||
create_time: string;
|
||||
last_modify_time: string;
|
||||
duration: string;
|
||||
thumbnail_url: string;
|
||||
view_count: string;
|
||||
download_count: string;
|
||||
is_delete: number;
|
||||
id: number;
|
||||
user_id: number;
|
||||
resource_type: string;
|
||||
file_name: string;
|
||||
original_name: string;
|
||||
file_path: string;
|
||||
file_url: string;
|
||||
file_size: number;
|
||||
mime_type: string;
|
||||
description: string;
|
||||
tags: string;
|
||||
is_public: string;
|
||||
width: number;
|
||||
height: number;
|
||||
uploadInfo: {
|
||||
success: boolean;
|
||||
name: string;
|
||||
path: string;
|
||||
ossPath: string;
|
||||
fileType: string;
|
||||
fileSize: number;
|
||||
originalName: string;
|
||||
suffix: string;
|
||||
storagePath: string;
|
||||
};
|
||||
}
|
||||
|
||||
// 后端球局数据接口
|
||||
interface BackendGameData {
|
||||
@@ -284,7 +257,7 @@ export class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
// 更新用户信息(简化版本,具体逻辑在 userStore 中处理)
|
||||
static async update_user_info(update_data: Partial<UserInfo>): Promise<void> {
|
||||
try {
|
||||
// 过滤掉空字段
|
||||
@@ -490,4 +463,55 @@ export class UserService {
|
||||
return require('../static/userInfo/default_avatar.svg');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 从 loginService 移过来的用户相关方法
|
||||
|
||||
// 获取用户详细信息
|
||||
export const fetchUserProfile = async (): Promise<ApiResponse<UserInfoType>> => {
|
||||
try {
|
||||
const response = await httpService.post('user/detail');
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// 更新用户信息
|
||||
export const updateUserProfile = async (payload: Partial<UserInfoType>) => {
|
||||
try {
|
||||
const response = await httpService.post('/user/update', payload);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('更新用户信息失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// 更新用户坐标位置
|
||||
export const updateUserLocation = async (latitude: number, longitude: number) => {
|
||||
try {
|
||||
const response = await httpService.post('/user/update_location', {
|
||||
latitude,
|
||||
longitude,
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('更新用户坐标位置失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// 获取用户信息(从本地存储)
|
||||
export const get_user_info = (): any | null => {
|
||||
try {
|
||||
let userinfo = Taro.getStorageSync('user_info')
|
||||
if (userinfo) {
|
||||
return JSON.parse(userinfo)
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user