feat: upload cover not over yet
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user