fix: 修复报告页
This commit is contained in:
parent
f855675f09
commit
dfee22f42f
@ -265,10 +265,15 @@ const friendlyUploadError = (rawMsg) => {
|
|||||||
if (msg.includes('request:fail')) return '网络异常,请重试'
|
if (msg.includes('request:fail')) return '网络异常,请重试'
|
||||||
if (msg.includes('timeout')) return '上传超时,请重试'
|
if (msg.includes('timeout')) return '上传超时,请重试'
|
||||||
if (msg.includes('只能上传图片或视频')) return '格式不支持'
|
if (msg.includes('只能上传图片或视频')) return '格式不支持'
|
||||||
if (msg.includes('413') || msg.includes('Too Large')) return '文件过大'
|
if (msg.includes('413') || msg.includes('Too Large') || msg.includes('HTTP 413')) return '文件过大'
|
||||||
|
if (msg.includes('HTTP 502') || msg.includes('HTTP 503') || msg.includes('HTTP 504')) return '服务暂不可用'
|
||||||
|
if (/HTTP\s(4|5)\d{2}/.test(msg)) return '上传失败,请重试'
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 大视频上传较慢,单独加长超时(毫秒) */
|
||||||
|
const UPLOAD_TIMEOUT_MS = 180000
|
||||||
|
|
||||||
const buildPendingItem = (localPath, mediaType) => ({
|
const buildPendingItem = (localPath, mediaType) => ({
|
||||||
url: localPath,
|
url: localPath,
|
||||||
localPath,
|
localPath,
|
||||||
@ -293,30 +298,55 @@ const setUploadFail = (item, reason) => {
|
|||||||
|
|
||||||
const uploadSingleFile = (filePath) =>
|
const uploadSingleFile = (filePath) =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
|
let settled = false
|
||||||
|
const done = (r) => {
|
||||||
|
if (settled) return
|
||||||
|
settled = true
|
||||||
|
resolve(r)
|
||||||
|
}
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
done({ ok: false, message: '上传超时,请重试' })
|
||||||
|
}, UPLOAD_TIMEOUT_MS)
|
||||||
|
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
url: `${BASE_URL}/upload/image`,
|
url: `${BASE_URL}/upload/image`,
|
||||||
filePath,
|
filePath,
|
||||||
name: 'file',
|
name: 'file',
|
||||||
|
timeout: UPLOAD_TIMEOUT_MS,
|
||||||
success: (uploadRes) => {
|
success: (uploadRes) => {
|
||||||
|
clearTimeout(timer)
|
||||||
|
const sc = uploadRes.statusCode
|
||||||
|
if (sc !== 200) {
|
||||||
|
done({ ok: false, message: friendlyUploadError(`HTTP ${sc}`) })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const raw = uploadRes.data || ''
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(uploadRes.data || '{}')
|
const data = typeof raw === 'string' ? JSON.parse(raw || '{}') : raw
|
||||||
if (data.code === 200 && data.data?.url) {
|
if (data.code === 200 && data.data?.url) {
|
||||||
resolve({ ok: true, url: data.data.url })
|
done({ ok: true, url: data.data.url })
|
||||||
} else {
|
} else {
|
||||||
resolve({ ok: false, message: friendlyUploadError(data.message) })
|
done({ ok: false, message: friendlyUploadError(data.message) })
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
resolve({ ok: false, message: '返回解析失败' })
|
done({
|
||||||
|
ok: false,
|
||||||
|
message: raw && String(raw).length < 80 ? friendlyUploadError(raw) : '服务返回异常,请重试'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => resolve({ ok: false, message: friendlyUploadError(err?.errMsg) })
|
fail: (err) => {
|
||||||
|
clearTimeout(timer)
|
||||||
|
done({ ok: false, message: friendlyUploadError(err?.errMsg) })
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const showBatchUploadFail = (count, firstReason) => {
|
const showBatchUploadFail = (count, firstReason) => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: `${count}个上传失败:${firstReason || '请重试'}`.slice(0, 20),
|
title: `${count}个上传失败:${firstReason || '请重试'}`.slice(0, 36),
|
||||||
icon: 'none'
|
icon: 'none',
|
||||||
|
duration: 2800
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +369,7 @@ const retryUpload = async (field, idx) => {
|
|||||||
uni.showToast({ title: '重试成功', icon: 'success' })
|
uni.showToast({ title: '重试成功', icon: 'success' })
|
||||||
} else {
|
} else {
|
||||||
setUploadFail(item, r.message)
|
setUploadFail(item, r.message)
|
||||||
uni.showToast({ title: `重试失败:${r.message}`.slice(0, 20), icon: 'none' })
|
uni.showToast({ title: `重试失败:${r.message}`.slice(0, 36), icon: 'none' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user