解决小程序上传时出现的问题。
This commit is contained in:
@@ -113,9 +113,20 @@ export function request(options = {}) {
|
||||
const fullUrl = url.startsWith('http') ? url : getApiUrl(url)
|
||||
const apiEnv = typeof getApiEnv === 'function' ? getApiEnv() : ''
|
||||
|
||||
// 详细的请求日志
|
||||
console.log('[Request] 开始处理请求:', {
|
||||
originalUrl: url,
|
||||
fullUrl: fullUrl,
|
||||
method: method.toUpperCase(),
|
||||
isLoginApi: isLoginApi(fullUrl),
|
||||
apiEnv: apiEnv,
|
||||
needTenantId,
|
||||
needToken
|
||||
})
|
||||
|
||||
// 每次请求打印完整 URL,格式示例:
|
||||
// H5环境(local)直接使用完整URL: http://localhost:8090/api/audioManagement/list
|
||||
console.log(`H5环境(${apiEnv})直接使用完整URL: ${fullUrl}`)
|
||||
console.log(`[Request] 完整请求URL: ${fullUrl}`)
|
||||
|
||||
// 构建请求头
|
||||
const requestHeader = {
|
||||
@@ -169,7 +180,16 @@ export function request(options = {}) {
|
||||
}
|
||||
|
||||
// 发起请求
|
||||
console.log('[Request] 准备发起 uni.request:', {
|
||||
url: fullUrl,
|
||||
method: method.toUpperCase(),
|
||||
hasData: !!requestData,
|
||||
hasHeaders: !!requestHeader,
|
||||
timeout: timeout
|
||||
})
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('[Request] 调用 uni.request 开始执行')
|
||||
uni.request({
|
||||
url: fullUrl,
|
||||
method: method.toUpperCase(),
|
||||
@@ -178,13 +198,30 @@ export function request(options = {}) {
|
||||
timeout,
|
||||
...restOptions,
|
||||
success: (res) => {
|
||||
console.log('[Request] 收到响应:', {
|
||||
url: fullUrl,
|
||||
method: method.toUpperCase(),
|
||||
statusCode: res.statusCode,
|
||||
hasData: !!res.data,
|
||||
dataType: typeof res.data
|
||||
})
|
||||
|
||||
// 检查HTTP状态码,如果是401(未授权),跳转到登录页面
|
||||
if (res.statusCode === 401) {
|
||||
console.warn('[Request] 收到401状态码,跳转到登录页面')
|
||||
redirectToLogin()
|
||||
reject(new Error('登录已过期,请重新登录'))
|
||||
return
|
||||
}
|
||||
resolve(res)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('[Request] 请求失败:', {
|
||||
url: fullUrl,
|
||||
method: method.toUpperCase(),
|
||||
error: err
|
||||
error: err,
|
||||
errorMessage: err.errMsg || '未知错误',
|
||||
errorCode: err.code || '无错误码'
|
||||
})
|
||||
reject(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user