|
@@ -91,6 +91,42 @@ const warehouse = store.warehouse
|
|
|
const uploadImages = ref([])
|
|
const uploadImages = ref([])
|
|
|
const uploading = ref(false)
|
|
const uploading = ref(false)
|
|
|
|
|
|
|
|
|
|
+// 自动上传图片
|
|
|
|
|
+const autoUploadImage = async (file) => {
|
|
|
|
|
+ if (!warehouse) {
|
|
|
|
|
+ showFailToast('未获取到仓库信息')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查图片大小是否超过2MB
|
|
|
|
|
+ if (file.size > 2 * 1024 * 1024) {
|
|
|
|
|
+ showFailToast('图片大小不能超过2MB')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ uploading.value = true
|
|
|
|
|
+ const toast = showLoadingToast('自动上传识别中...')
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await uploadOCRImage(file, warehouse)
|
|
|
|
|
+
|
|
|
|
|
+ closeToast()
|
|
|
|
|
+
|
|
|
|
|
+ if (response.code === 200) {
|
|
|
|
|
+ showNotify({ type: 'success', message: '面单上传成功' })
|
|
|
|
|
+ // 上传成功后重置表单
|
|
|
|
|
+ uploadImages.value = []
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showNotify({ type: 'danger', message: response.message || '上传失败' })
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ closeToast()
|
|
|
|
|
+ showNotify({ type: 'danger', message: '识别过程发生异常: ' + (err.message || '未知错误') })
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ uploading.value = false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 检查图片格式和大小
|
|
// 检查图片格式和大小
|
|
|
const beforeReadImage = (file) => {
|
|
const beforeReadImage = (file) => {
|
|
|
const files = Array.isArray(file) ? file : [file]
|
|
const files = Array.isArray(file) ? file : [file]
|
|
@@ -124,6 +160,8 @@ const afterReadImage = async (file) => {
|
|
|
const originalFile = fileItem.file
|
|
const originalFile = fileItem.file
|
|
|
|
|
|
|
|
if (originalFile) {
|
|
if (originalFile) {
|
|
|
|
|
+ let finalFile = originalFile
|
|
|
|
|
+
|
|
|
// 检查文件大小,如果大于1MB则进行压缩
|
|
// 检查文件大小,如果大于1MB则进行压缩
|
|
|
if (originalFile.size > 1 * 1024 * 1024) {
|
|
if (originalFile.size > 1 * 1024 * 1024) {
|
|
|
showNotify({
|
|
showNotify({
|
|
@@ -134,6 +172,7 @@ const afterReadImage = async (file) => {
|
|
|
try {
|
|
try {
|
|
|
// 压缩图片到1MB以内
|
|
// 压缩图片到1MB以内
|
|
|
const compressedFile = await compressImage(originalFile, 1 * 1024 * 1024)
|
|
const compressedFile = await compressImage(originalFile, 1 * 1024 * 1024)
|
|
|
|
|
+ finalFile = compressedFile
|
|
|
|
|
|
|
|
// 更新文件对象
|
|
// 更新文件对象
|
|
|
fileItem.file = compressedFile
|
|
fileItem.file = compressedFile
|
|
@@ -156,6 +195,9 @@ const afterReadImage = async (file) => {
|
|
|
} else {
|
|
} else {
|
|
|
console.log(`图片大小符合要求,无需压缩: ${(originalFile.size / 1024).toFixed(2)}KB`)
|
|
console.log(`图片大小符合要求,无需压缩: ${(originalFile.size / 1024).toFixed(2)}KB`)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 压缩完成后自动上传
|
|
|
|
|
+ await autoUploadImage(finalFile)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|