退料附件拍照

This commit is contained in:
hongchao 2025-07-29 13:50:19 +08:00
parent b345f8be54
commit 94b0972f9d
2 changed files with 124 additions and 142 deletions

View File

@ -493,72 +493,103 @@ const submitCode = () => {
// //
const uploadImg = () => { const uploadImg = () => {
uni.chooseImage({ const count = 3 - imgList.value.length
count: 3 - imgList.value.length, // 3 if (count <= 0) {
sizeType: ['original', 'compressed'], uni.showToast({ title: '最多上传3张图片', icon: 'none' })
sourceType: ['album', 'camera'], return
success: async (res) => { }else{
const tempFiles = res.tempFiles uni.showActionSheet({
if (imgList.value.length + tempFiles.length > 3) { itemList: ['拍照', '从相册选择'],
uni.showToast({ title: '最多只能上传3张图片', icon: 'none' }) success: (res) => {
return if (res.tapIndex === 0) {
} getCameraFj()
} else if (res.tapIndex === 1) {
// //
for (let i = 0; i < tempFiles.length; i++) { getPhotoFj()
imgList.value.push({ }
url: tempFiles[i].path,
uploading: true,
})
}
//
const uploadPromises = tempFiles.map((file) => {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: '/file/upload',
filePath: file.path,
name: 'file',
success: (uploadRes) => {
const resData = JSON.parse(uploadRes.data)
if (resData.code === 200) {
resolve({
name: resData.data.name,
url: resData.data.url,
taskType: '10',
})
} else {
reject(new Error('上传失败'))
}
},
fail: (err) => {
reject(err)
},
})
})
})
try {
const results = await Promise.all(uploadPromises)
bmFileInfos.value = [...bmFileInfos.value, ...results]
uni.showToast({ title: '上传成功', icon: 'none' })
//
imgList.value = imgList.value.map((img) => {
return {
...img,
uploading: false,
}
})
} catch (error) {
uni.showToast({ title: '部分图片上传失败', icon: 'none' })
//
imgList.value = imgList.value.filter((img) => !img.uploading)
}
}, },
}) fail: (err) => {
console.error('操作菜单选择失败:', err)
},
})
}
} }
//
const getCameraFj = () => {
navigator.camera.getPicture(onCameraSuccessFj, onCameraErrorFj, {
quality: 50,
destinationType: window.Camera.DestinationType.DATA_URL,
sourceType: window.Camera.PictureSourceType.CAMERA,
})
}
//
const getPhotoFj = () => {
navigator.camera.getPicture(onCameraSuccessFj, onCameraErrorFj, {
quality: 50,
destinationType: window.Camera.DestinationType.DATA_URL,
sourceType: window.Camera.PictureSourceType.SAVEDPHOTOALBUM,
})
}
const onCameraErrorFj = (message) => {
console.log(message)
}
const onCameraSuccessFj = (file) => {
uploadSignUrlFj(file)
}
const generateRandomString = (length) => {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
const uploadSignUrlFj = (file) => {
const base64Data = file
uni.request({
url: '/file/uploadBase64',
method: 'POST',
data: {
base64File:base64Data,
fileName: `${generateRandomString(10)}_${Date.now()}.png`,
fileType: 'image/png'
},
success: (uploadRes) => {
if(!uploadRes.data.code){
uploadRes = JSON.parse(decryptWithSM4(uploadRes.data))
}else{
uploadRes = JSON.parse(uploadRes.data)
}
if (uploadRes.code && uploadRes.code == 200) {
imgList.value.push({
url: uploadRes.data.url, // Show local path first
serverUrl: uploadRes.data.url // Store server URL
})
bmFileInfos.value.push({
name: uploadRes.data.name,
url: uploadRes.data.url,
taskType: '10'
})
uni.showToast({ title: '上传成功', icon: 'none' })
} else {
uni.showToast({ title: '上传失败', icon: 'none' })
}
},
fail: (err) => {
console.error('上传失败', err)
uni.showToast({ title: '上传失败', icon: 'none' })
}
})
}
// //
const deleteImage = (index) => { const deleteImage = (index) => {
imgList.value.splice(index, 1) imgList.value.splice(index, 1)

File diff suppressed because one or more lines are too long