Merge branch 'feat/liujie'
This commit is contained in:
41
src/services/detailApi.ts
Normal file
41
src/services/detailApi.ts
Normal 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()
|
||||
@@ -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()
|
||||
@@ -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,7 +122,13 @@ class PublishService {
|
||||
return httpService.post('/venues/list', data, {
|
||||
showLoading: false })
|
||||
}
|
||||
async getPictures(req: getPicturesReq): Promise<ApiResponse<getPicturesRes>> {
|
||||
return httpService.post('/gallery/sys_img_list', req, {
|
||||
showLoading: true,
|
||||
showToast: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 导出认证服务实例
|
||||
export default new PublishService()
|
||||
export default new PublishService()
|
||||
75
src/services/uploadFiles.ts
Normal file
75
src/services/uploadFiles.ts
Normal 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()
|
||||
Reference in New Issue
Block a user