定损附件上传修改
This commit is contained in:
parent
aa72cbfd09
commit
fd2d047f04
|
|
@ -226,70 +226,160 @@ const imgList2 = ref([]) // 图片列表,用于回显
|
|||
const fileData = ref({fileList:[]})
|
||||
//上传
|
||||
const uploadImg2 = () => {
|
||||
uni.chooseImage({
|
||||
count: 3 - imgList2.value.length, // 最多选择3张,减去已选数量
|
||||
sizeType: ['original', 'compressed'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: async (res) => {
|
||||
const tempFiles = res.tempFiles
|
||||
if (imgList2.value.length + tempFiles.length > 3) {
|
||||
uni.showToast({ title: '最多只能上传3张图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 显示选择的图片
|
||||
for (let i = 0; i < tempFiles.length; i++) {
|
||||
imgList2.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
|
||||
})
|
||||
} else {
|
||||
reject(new Error('上传失败'))
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
uni.showActionSheet({
|
||||
itemList: ['拍照', '从相册选择'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
getCameraFj()
|
||||
} else if (res.tapIndex === 1) {
|
||||
// 从相册选择
|
||||
getPhotoFj()
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('操作菜单选择失败:', err)
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
const results = await Promise.all(uploadPromises)
|
||||
fileData.value.fileList = [...bmFileInfos.value, ...results]
|
||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||
// uni.chooseImage({
|
||||
// count: 3 - imgList2.value.length, // 最多选择3张,减去已选数量
|
||||
// sizeType: ['original', 'compressed'],
|
||||
// sourceType: ['album', 'camera'],
|
||||
// success: async (res) => {
|
||||
// const tempFiles = res.tempFiles
|
||||
// if (imgList2.value.length + tempFiles.length > 3) {
|
||||
// uni.showToast({ title: '最多只能上传3张图片', icon: 'none' })
|
||||
// return
|
||||
// }
|
||||
|
||||
// 更新图片状态
|
||||
imgList2.value = imgList2.value.map(img => {
|
||||
return {
|
||||
...img,
|
||||
uploading: false
|
||||
// // 显示选择的图片
|
||||
// for (let i = 0; i < tempFiles.length; i++) {
|
||||
// imgList2.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
|
||||
// })
|
||||
// } else {
|
||||
// reject(new Error('上传失败'))
|
||||
// }
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// reject(err)
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
// try {
|
||||
// const results = await Promise.all(uploadPromises)
|
||||
// fileData.value.fileList = [...bmFileInfos.value, ...results]
|
||||
// uni.showToast({ title: '上传成功', icon: 'none' })
|
||||
|
||||
// // 更新图片状态
|
||||
// imgList2.value = imgList2.value.map(img => {
|
||||
// return {
|
||||
// ...img,
|
||||
// uploading: false
|
||||
// }
|
||||
// })
|
||||
// } catch (error) {
|
||||
// uni.showToast({ title: '部分图片上传失败', icon: 'none' })
|
||||
// // 移除上传失败的图片
|
||||
// imgList2.value = imgList2.value.filter(img => !img.uploading)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
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 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 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 = uploadRes.data
|
||||
}
|
||||
if (uploadRes.code && uploadRes.code == 200) {
|
||||
imgList2.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' })
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '部分图片上传失败', icon: 'none' })
|
||||
// 移除上传失败的图片
|
||||
imgList2.value = imgList2.value.filter(img => !img.uploading)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//删除图片
|
||||
const deleteImage2 = (index) => {
|
||||
imgList2.value.splice(index, 1)
|
||||
|
|
|
|||
|
|
@ -328,70 +328,96 @@ const imgList2 = ref([]) // 图片列表,用于回显
|
|||
const fileData = ref({fileList:[]})
|
||||
//上传
|
||||
const uploadImg2 = () => {
|
||||
uni.chooseImage({
|
||||
count: 3 - imgList2.value.length, // 最多选择3张,减去已选数量
|
||||
sizeType: ['original', 'compressed'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: async (res) => {
|
||||
const tempFiles = res.tempFiles
|
||||
if (imgList2.value.length + tempFiles.length > 3) {
|
||||
uni.showToast({ title: '最多只能上传3张图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 显示选择的图片
|
||||
for (let i = 0; i < tempFiles.length; i++) {
|
||||
imgList2.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
|
||||
})
|
||||
} else {
|
||||
reject(new Error('上传失败'))
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
uni.showActionSheet({
|
||||
itemList: ['拍照', '从相册选择'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
getCameraFj()
|
||||
} else if (res.tapIndex === 1) {
|
||||
// 从相册选择
|
||||
getPhotoFj()
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('操作菜单选择失败:', err)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
const results = await Promise.all(uploadPromises)
|
||||
fileData.value.fileList = [...bmFileInfos.value, ...results]
|
||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||
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;
|
||||
}
|
||||
|
||||
// 更新图片状态
|
||||
imgList2.value = imgList2.value.map(img => {
|
||||
return {
|
||||
...img,
|
||||
uploading: false
|
||||
// 附件拍照
|
||||
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 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 = uploadRes.data
|
||||
}
|
||||
if (uploadRes.code && uploadRes.code == 200) {
|
||||
imgList2.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' })
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '部分图片上传失败', icon: 'none' })
|
||||
// 移除上传失败的图片
|
||||
imgList2.value = imgList2.value.filter(img => !img.uploading)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//删除图片
|
||||
const deleteImage2 = (index) => {
|
||||
imgList2.value.splice(index, 1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue