Commit f4f0f30f by 李伟康

fix(usedCar): 优化图片上传错误处理逻辑

将图片上传大小限制的错误提示方式从抛出异常改为使用 uni.showToast 提示用户。同时,
增加上传失败时的错误处理回调函数,确保在上传失败时能够正确隐藏加载提示并给出相
应的错误提示。此外,在 catch 语句中添加了对错误的打印,便于调试和问题追踪。
1 parent 1d5be6a7
...@@ -119,7 +119,10 @@ export default { ...@@ -119,7 +119,10 @@ export default {
async success (res) { async success (res) {
for (const file of res.tempFiles) { for (const file of res.tempFiles) {
if (file.size > MAX_IMAGE_SIZE) { if (file.size > MAX_IMAGE_SIZE) {
throw '图片上传最大10MB' return uni.showToast({
title: '图片上传最大10MB',
icon: 'none'
})
} }
} }
uni.showLoading({ title: '上传中...', mask: true }) uni.showLoading({ title: '上传中...', mask: true })
...@@ -128,9 +131,18 @@ export default { ...@@ -128,9 +131,18 @@ export default {
_this.imgList.push(url) _this.imgList.push(url)
} }
if (_this.imgList.length >= res.tempFilePaths.length) uni.hideLoading() if (_this.imgList.length >= res.tempFilePaths.length) uni.hideLoading()
} },
fail (err) {
console.log(err)
uni.hideLoading()
return uni.showToast({
title: '图片上传失败',
icon: 'none'
})
},
}) })
} catch (error) { } catch (error) {
console.log(error)
uni.hideLoading() uni.hideLoading()
return uni.showToast({ return uni.showToast({
title: error, title: error,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!