fix: 文件上传压缩功能修复。
This commit is contained in:
@@ -114,6 +114,7 @@
|
||||
<script setup>
|
||||
import { getDoctorRecord, addDoctorRecord, updateDoctorRecord, uploadFile } from '@/api/health/doctorRecord'
|
||||
import config from '@/config'
|
||||
import { compressImage } from '@/utils/imageCompress'
|
||||
import { listPerson } from '@/api/health/person'
|
||||
import { listHealthRecord } from '@/api/health/healthRecord'
|
||||
const { proxy } = getCurrentInstance()
|
||||
@@ -457,30 +458,32 @@ function chooseImage() {
|
||||
}
|
||||
|
||||
// 递归上传图片
|
||||
function uploadImages(paths, index) {
|
||||
async function uploadImages(paths, index) {
|
||||
if (index >= paths.length) {
|
||||
uploading.value = false
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
// H5 端 mask: true 会让页面无法点击,一旦上传出问题会导致用户被“锁住”
|
||||
// 这里改为 mask: false,允许用户取消(会提示正在上传)
|
||||
uni.showLoading({ title: `上传中 ${index + 1}/${paths.length}`, mask: false })
|
||||
uploadFile({
|
||||
filePath: paths[index],
|
||||
name: 'file'
|
||||
}).then(res => {
|
||||
uni.showLoading({ title: `处理中 ${index + 1}/${paths.length}`, mask: false })
|
||||
try {
|
||||
// 上传前先压缩(超过 500KB 才压,避免小图多走一道)
|
||||
const compressedPath = await compressImage(paths[index])
|
||||
uni.showLoading({ title: `上传中 ${index + 1}/${paths.length}`, mask: false })
|
||||
const res = await uploadFile({
|
||||
filePath: compressedPath,
|
||||
name: 'file'
|
||||
})
|
||||
const url = (res.data && res.data.url) || res.fileName || res.url
|
||||
if (url) {
|
||||
attachmentList.value.push(normalizeAttachmentUrl(url))
|
||||
}
|
||||
uni.hideLoading()
|
||||
uploadImages(paths, index + 1)
|
||||
}).catch(() => {
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
uploading.value = false
|
||||
proxy.$refs['uToast'].show({ message: `第 ${index + 1} 张上传失败`, type: 'error' })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 删除图片
|
||||
|
||||
Reference in New Issue
Block a user