合并代码

This commit is contained in:
筱野
2025-08-30 22:28:02 +08:00
143 changed files with 6369 additions and 2072 deletions

View File

@@ -0,0 +1,41 @@
import httpService from './httpService'
import type { ApiResponse } from './httpService'
// 用户接口
export interface GameDetail {
id: number,
title: string,
venue_id: number,
creator_id: number,
game_date: string,
start_time: string,
end_time: string,
max_participants: number,
current_participants: number,
ntrp_level: string,
play_style: string,
description: string,
status: string,
created_at: string,
updated_at: string,
}
// 响应接口
export interface Response {
code: string
message: string
data: GameDetail
}
// 发布球局类
class GameDetailService {
// 用户登录
async getDetail(id: number): Promise<ApiResponse<Response>> {
return httpService.post('/games/detail', { id }, {
showLoading: true,
})
}
}
// 导出认证服务实例
export default new GameDetailService()

View File

@@ -15,6 +15,7 @@ export interface RequestConfig {
needAuth?: boolean // 是否需要token认证
showLoading?: boolean // 是否显示加载提示
loadingText?: string // 加载提示文本
showToast?: boolean // 是否显示toast
}
// 响应数据接口
@@ -58,7 +59,7 @@ class HttpService {
// 构建完整URL
private buildUrl(url: string, params?: Record<string, any>): string {
const fullUrl = url.startsWith('http') ? url : `${this.baseURL}${url}`
if (params) {
const searchParams = new URLSearchParams()
Object.entries(params).forEach(([key, value]) => {
@@ -69,7 +70,7 @@ class HttpService {
const queryString = searchParams.toString()
return queryString ? `${fullUrl}?${queryString}` : fullUrl
}
return fullUrl
}
@@ -95,7 +96,7 @@ class HttpService {
const logMethod = console[level] || console.log
const timestamp = new Date().toLocaleTimeString()
if (data) {
logMethod(`[${timestamp}] HTTP ${level.toUpperCase()}: ${message}`, data)
} else {
@@ -165,9 +166,9 @@ class HttpService {
// 处理业务错误
private handleBusinessError(data: any): void {
const message = data.message || '操作失败'
this.log('error', `业务错误: ${message}`, data)
Taro.showToast({
title: message,
icon: 'none',
@@ -187,7 +188,7 @@ class HttpService {
} = config
const fullUrl = this.buildUrl(url, method === 'GET' ? params : undefined)
this.log('info', `发起请求: ${method} ${fullUrl}`, {
data: method !== 'GET' ? data : undefined,
params: method === 'GET' ? params : undefined
@@ -223,18 +224,18 @@ class HttpService {
return this.handleResponse<T>(response)
} catch (error) {
this.log('error', '请求失败', error)
// 在模拟模式下返回模拟数据
if (envConfig.enableMock && isDevelopment()) {
this.log('info', '使用模拟数据')
return this.getMockResponse<T>(url, method)
}
Taro.showToast({
title: '网络连接失败',
icon: 'none'
})
throw error
} finally {
// 隐藏加载提示
@@ -247,7 +248,7 @@ class HttpService {
// 获取模拟数据
private getMockResponse<T>(url: string, method: string): ApiResponse<T> {
this.log('info', `返回模拟数据: ${method} ${url}`)
return {
code: 200,
success: true,
@@ -323,4 +324,4 @@ class HttpService {
}
// 导出HTTP服务实例
export default new HttpService()
export default new HttpService()

View File

@@ -1,93 +1,67 @@
import { TennisMatch } from '../store/listStore'
import { TennisMatch } from "../store/listStore";
import httpService from "./httpService";
// 模拟网络延迟
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
// 模拟API响应格式
interface ApiResponse<T> {
code: number
message: string
data: T
timestamp: number
code: number;
message: string;
data: T;
timestamp: number;
}
// 模拟网球比赛数据
const mockTennisMatches: TennisMatch[] = [
{
id: '1',
title: '周一晚场浦东新区单打约球',
dateTime: '明天(周五)下午5点 2小时',
location: '仁恒河滨花园网球场・室外',
distance: '3.5km',
id: "1",
title: "周一晚场浦东新区单打约球",
dateTime: "明天(周五)下午5点 2小时",
location: "仁恒河滨花园网球场",
distance: "3.5km",
shinei: "室内",
registeredCount: 3,
maxCount: 4,
skillLevel: '2.0 至 2.5',
matchType: '双打',
skillLevel: "2.0 至 2.5",
matchType: "双打",
images: [
'https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center',
'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=200&h=200&fit=crop&crop=center',
'https://images.unsplash.com/photo-1551698618-1dfe5d97d256?w=200&h=200&fit=crop&crop=center'
]
"https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center",
"https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=200&h=200&fit=crop&crop=center",
"https://images.unsplash.com/photo-1551698618-1dfe5d97d256?w=200&h=200&fit=crop&crop=center",
],
},
{
id: '2',
title: '浦东新区单打约球',
dateTime: '明天(周五)下午5点 2小时',
location: '仁恒河滨花园网球场・室外',
distance: '3.5km',
id: "2",
title: "浦东新区单打约球",
dateTime: "明天(周五)下午5点 2小时",
location: "仁恒河滨花园网球场",
distance: "3.5km",
shinei: "室外",
registeredCount: 2,
maxCount: 4,
skillLevel: '2.0 至 2.5',
matchType: '双打',
skillLevel: "2.0 至 2.5",
matchType: "双打",
images: [
'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=200&h=200&fit=crop&crop=center',
'https://images.unsplash.com/photo-1551698618-1dfe5d97d256?w=200&h=200&fit=crop&crop=center'
]
"https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=200&h=200&fit=crop&crop=center",
"https://images.unsplash.com/photo-1551698618-1dfe5d97d256?w=200&h=200&fit=crop&crop=center",
],
},
{
id: '3',
title: '黄浦区双打约球',
dateTime: '7月20日(周日)下午6点 2小时',
location: '仁恒河滨花园网球场・室外',
distance: '3.5km',
id: "3",
title: "黄浦区双打约球",
dateTime: "7月20日(周日)下午6点 2小时",
location: "仁恒河滨花园网球场",
distance: "3.5km",
registeredCount: 3,
maxCount: 4,
skillLevel: '2.0 至 2.5',
matchType: '双打',
skillLevel: "2.0 至 2.5",
matchType: "双打",
images: [
'https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center'
]
}
]
// 模拟数据变化
const generateDynamicData = (): TennisMatch[] => {
return mockTennisMatches.map(match => ({
...match,
// 随机更新注册人数
registeredCount: Math.min(
match.maxCount,
Math.max(0, match.registeredCount + Math.floor(Math.random() * 3) - 1)
),
// 随机更新距离
distance: `${(Math.random() * 5 + 1).toFixed(1)}km`,
// 随机更新时间
dateTime: Math.random() > 0.5 ? match.dateTime : '今天下午3点 2小时'
}))
}
// 模拟网络错误
const simulateNetworkError = (): boolean => {
// 10% 概率模拟网络错误
return Math.random() < 0.1
}
// 模拟网络超时
const simulateTimeout = (): boolean => {
// 5% 概率模拟超时
return Math.random() < 0.05
}
"https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center",
],
},
];
/**
* 获取网球比赛列表
@@ -95,59 +69,18 @@ const simulateTimeout = (): boolean => {
* @returns Promise<TennisMatch[]>
*/
export const getTennisMatches = async (params?: {
page?: number
pageSize?: number
location?: string
skillLevel?: string
}): Promise<TennisMatch[]> => {
page?: number;
pageSize?: number;
location?: string;
skillLevel?: string;
}) => {
try {
console.log('API调用: getTennisMatches', params)
// 模拟网络延迟 (800-1500ms)
const delayTime = 800 + Math.random() * 700
await delay(delayTime)
// 模拟网络错误
if (simulateNetworkError()) {
throw new Error('网络连接失败,请检查网络设置')
}
// 模拟超时
if (simulateTimeout()) {
throw new Error('请求超时,请稍后重试')
}
// 生成动态数据
const matches = generateDynamicData()
// 模拟分页
if (params?.page && params?.pageSize) {
const start = (params.page - 1) * params.pageSize
const end = start + params.pageSize
return matches.slice(start, end)
}
// 模拟筛选
if (params?.location) {
return matches.filter(match =>
match.location.includes(params.location!)
)
}
if (params?.skillLevel) {
return matches.filter(match =>
match.skillLevel.includes(params.skillLevel!)
)
}
console.log('API响应成功:', matches.length, '条数据')
return matches
return httpService.post('/venues/list', params, { showLoading: false })
} catch (error) {
console.error('API调用失败:', error)
throw error
console.error("列表数据获取失败:", error);
throw error;
}
}
};
/**
* 刷新网球比赛数据
@@ -155,69 +88,12 @@ export const getTennisMatches = async (params?: {
*/
export const refreshTennisMatches = async (): Promise<TennisMatch[]> => {
try {
console.log('API调用: refreshTennisMatches')
// 模拟刷新延迟 (500-1000ms)
const delayTime = 500 + Math.random() * 500
await delay(delayTime)
// 模拟网络错误
if (simulateNetworkError()) {
throw new Error('刷新失败,请稍后重试')
}
// 生成新的动态数据
const matches = generateDynamicData()
console.log('API刷新成功:', matches.length, '条数据')
return matches
const matches = generateDynamicData();
return matches;
} catch (error) {
console.error('API刷新失败:', error)
throw error
console.error("API刷新失败:", error);
throw error;
}
}
};
/**
* 获取比赛详情
* @param id 比赛ID
* @returns Promise<TennisMatch | null>
*/
export const getTennisMatchDetail = async (id: string): Promise<TennisMatch | null> => {
try {
console.log('API调用: getTennisMatchDetail', id)
// 模拟网络延迟
await delay(600 + Math.random() * 400)
// 模拟网络错误
if (simulateNetworkError()) {
throw new Error('获取详情失败,请稍后重试')
}
const match = mockTennisMatches.find(m => m.id === id)
if (!match) {
throw new Error('比赛不存在')
}
console.log('API获取详情成功:', match.title)
return match
} catch (error) {
console.error('API获取详情失败:', error)
throw error
}
}
/**
* 模拟API统计信息
*/
export const getApiStats = () => {
return {
totalCalls: 0,
successRate: 0.95,
averageResponseTime: 800,
lastCallTime: new Date().toISOString()
}
}

View File

@@ -36,7 +36,7 @@ export interface VerifyCodeResponse {
}
// 微信授权登录
export const wechat_auth_login = async (): Promise<LoginResponse> => {
export const wechat_auth_login = async (phone_code?: string): Promise<LoginResponse> => {
try {
// 先进行微信登录获取code
const login_result = await Taro.login();
@@ -48,15 +48,12 @@ export const wechat_auth_login = async (): Promise<LoginResponse> => {
};
}
// 使用 httpService 调用微信授权接口
const auth_response = await httpService.post('/user/wx_auth', {
code: login_result.code
// 使用 httpService 调用微信授权接口传递手机号code
const auth_response = await httpService.post('user/wx_auth', {
code: login_result.code,
phone_code: phone_code // 传递手机号加密code
});
if (auth_response.code === 0) {
return {
success: true,
@@ -89,7 +86,7 @@ export interface PhoneLoginParams {
export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginResponse> => {
try {
// 使用 httpService 调用验证验证码接口
const verify_response = await httpService.post('/user/sms/verify', {
const verify_response = await httpService.post('user/sms/verify', {
phone: params.phone,
code: params.verification_code
});
@@ -127,7 +124,7 @@ export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginR
// 发送短信验证码
export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
try {
const response = await httpService.post('/user/sms/send', {
const response = await httpService.post('user/sms/send', {
phone: phone
});
@@ -155,7 +152,7 @@ export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
// 验证短信验证码
export const verify_sms_code = async (phone: string, code: string): Promise<VerifyCodeResponse> => {
try {
const response = await httpService.post('/user/sms/verify', {
const response = await httpService.post('user/sms/verify', {
phone: phone,
code: code
});

View File

@@ -30,6 +30,12 @@ export interface PublishBallData {
wechat_contact?: string // 微信联系
}
export interface createGameData extends PublishBallData {
status: string,
created_at: string,
updated_at: string,
}
// 响应接口
export interface Response {
code: string
@@ -37,7 +43,6 @@ export interface Response {
data: any
}
// 响应接口
export interface StadiumListResponse {
rows: Stadium[]
}
@@ -51,10 +56,61 @@ export interface Stadium {
latitude?: number
}
// export type SourceType = 'history' | 'preset'
export interface getPicturesReq {
pageOption: {
page: number,
pageSize: number,
},
seachOption: {
tag: string,
resource_type: string,
dateRange: string[],
},
}
export interface getPicturesRes {
code: number,
message: string,
data: {
rows: [
{
user_id: string,
resource_type: string,
file_name: string,
original_name: string,
file_path: string,
file_url: string,
file_size: number,
mime_type: string,
width: number,
height: number,
duration: number,
thumbnail_url: string,
is_public: string,
tags: string[],
description: string,
view_count: number,
download_count: number,
status: string,
last_modify_time: string,
}
],
count: number,
page: number,
pageSize: number,
totalPages: number,
}
}
function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms))
}
// 发布球局类
class PublishService {
// 发布
async createPersonal(data: PublishBallData): Promise<ApiResponse<Response>> {
// 用户登录
async createPersonal(data: PublishBallData): Promise<ApiResponse<createGameData>> {
return httpService.post('/games/create', data, {
showLoading: true,
loadingText: '发布中...'
@@ -66,14 +122,21 @@ class PublishService {
return httpService.post('/venues/list', data, {
showLoading: false })
}
<<<<<<< HEAD
// 畅打发布
async create_play_pmoothly(data: PublishBallData): Promise<ApiResponse<Response>> {
return httpService.post('/games/create_play_pmoothly', data, {
showLoading: true,
loadingText: '发布中...'
=======
async getPictures(req: getPicturesReq): Promise<ApiResponse<getPicturesRes>> {
return httpService.post('/gallery/sys_img_list', req, {
showLoading: false,
showToast: false,
>>>>>>> d92419f3c5648a67d1b6857d66d6c92a4bece034
})
}
}
// 导出认证服务实例
export default new PublishService()
export default new PublishService()

View File

@@ -0,0 +1,75 @@
import httpService from './httpService'
import type { ApiResponse } from './httpService'
import Taro from '@tarojs/taro'
import envConfig from '@/config/env'
// 用户接口
export interface UploadFilesData {
id: string,
filePath: string,
description?: string,
tags?: string,
is_public?: 0 | 1,
}
// {"code":0,"message":"请求成功!","data":{"tags":["test"],"create_time":"2025-08-24 22:51:03","last_modify_time":"2025-08-24 22:51:03","duration":"0","thumbnail_url":"","view_count":"0","download_count":"0","id":16,"user_id":1,"resource_type":"image","file_name":"front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","original_name":"QyoUvEsLG6ci57c7e25cca0845dafed3ee1fde07876d.png","file_path":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","file_url":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","file_size":17756,"mime_type":"image/png","description":"test","is_public":"1","status":"active","width":0,"height":0,"uploadInfo":{"success":true,"name":"front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","path":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","ossPath":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","fileType":"image/png","fileSize":17756,"originalName":"QyoUvEsLG6ci57c7e25cca0845dafed3ee1fde07876d.png","suffix":"png","storagePath":"front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png"}}}
export interface uploadFileResponse {
code: number,
message: string,
data: uploadFileResponseData,
}
export interface uploadFileResponseData {
id: number,
user_id: number,
file_name: string,
original_name: string,
file_path: string,
file_url: string,
file_size: number,
resource_type: string,
mime_type: string,
description: string,
tags: string[],
is_public: string,
view_count: number,
download_count: number,
created_at: string,
updated_at: string,
}
function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms))
}
// 发布球局类
class UploadApi {
async upload(req: UploadFilesData): Promise<{ id: string, data: uploadFileResponseData }> {
// return httpService.post('/files/upload', req, {
// showLoading: true,
// })
const { id, ...rest } = req
return Taro.uploadFile({
url: `${envConfig.apiBaseURL}/api/gallery/upload`,
filePath: rest.filePath,
name: 'file',
formData: {
description: rest.description,
tags: rest.tags,
is_public: rest.is_public,
}
}).then(res => {
return {
id,
data: JSON.parse(res.data).data,
}
})
}
async batchUpload(req: UploadFilesData[]): Promise<{ id: string, data: uploadFileResponseData }[]> {
return Promise.all(req.map(item => this.upload(item)))
}
}
// 导出认证服务实例
export default new UploadApi()