fix(http): 移除默认的Content-Type请求头

refactor(hooks): 改进上传钩子的响应解析逻辑

移除http拦截器中硬编码的Content-Type头,让请求更灵活
修改useUpload钩子以适配不同平台的返回格式,增强容错性
This commit is contained in:
feige996
2025-09-30 17:59:27 +08:00
parent fe7d81ff62
commit 6b899c712e
2 changed files with 14 additions and 4 deletions

View File

@@ -55,10 +55,21 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
tempFilePath,
formData,
onSuccess: (res) => {
const { data: _data } = JSON.parse(res)
data.value = _data
// 修改这里的解析逻辑,适应不同平台的返回格式
let parsedData = res
try {
// 尝试解析为JSON
const jsonData = JSON.parse(res)
// 检查是否包含data字段
parsedData = jsonData.data || jsonData
}
catch (e) {
// 如果解析失败,使用原始数据
console.log('Response is not JSON, using raw data:', res)
}
data.value = parsedData
// console.log('上传成功', res)
success?.(_data)
success?.(parsedData)
},
onError: (err) => {
error.value = err

View File

@@ -47,7 +47,6 @@ const httpInterceptor = {
// 2. (可选)添加小程序端请求头标识
options.header = {
...options.header,
'Content-Type': 'application/json; charset=utf-8',
}
// 3. 添加 token 请求头标识
const tokenStore = useTokenStore()