fix: 大样图生成偶发失败加固(前端草图压缩1536px+后端超时5xx自动重试)

This commit is contained in:
HHY
2026-10-07 00:59:40 -07:00
parent acf1586ccc
commit 5795bf5352
4 changed files with 66 additions and 37 deletions
+13 -2
View File
@@ -308,8 +308,19 @@ function onSketchUpload(e: { file: unknown }) {
if (!(file instanceof File)) return
const reader = new FileReader()
reader.onload = () => {
sketchPhoto.value = String(reader.result)
ElMessage.success('草图已上传')
// 手机原图过大(5~10MB)会导致生图中转超时/拒绝, 统一压至 ≤1536px JPEG
const img = new Image()
img.onload = () => {
const scale = Math.min(1, 1536 / Math.max(img.naturalWidth, img.naturalHeight))
const cv = document.createElement('canvas')
cv.width = Math.max(1, Math.round(img.naturalWidth * scale))
cv.height = Math.max(1, Math.round(img.naturalHeight * scale))
cv.getContext('2d')!.drawImage(img, 0, 0, cv.width, cv.height)
sketchPhoto.value = cv.toDataURL('image/jpeg', 0.9)
ElMessage.success('草图已上传')
}
img.onerror = () => ElMessage.error('图片读取失败,请重试')
img.src = String(reader.result)
}
reader.readAsDataURL(file)
}