u
This commit is contained in:
1 parent
f9eaacf02a
commit
69eda8b8ad
27 files changed
+2797
-616
No files matched your search
@@ -1,9 +1,8 @@
|
||||
<script lang="ts" setup>
|
||||
import type { UploadFile, UploadFileItem } from 'sard-uniapp'
|
||||
import { dialog, isImageUrl, isVideoUrl, toast } from 'sard-uniapp'
|
||||
import { aliyunpluploadApi, deleteAliyunFileApi, deleteFileApi, getUniqueIdApi, recognizeOcrBoxApi, saveObjectApi, uploadTempFileApi } from '@/request/api'
|
||||
import { getUniqueIdApi, recognizeOcrBoxApi, saveObjectApi, uploadContainerFileApi, uploadTempFileApi } from '@/request/api'
|
||||
import { downloadFile, getFileExtension, imageCompress, isImage } from '@/utils/file'
|
||||
import { uploadToOss } from '@/utils/oss'
|
||||
|
||||
const boxImage = ref(null)
|
||||
|
||||
@@ -14,8 +13,8 @@ const showResult = ref(false)
|
||||
|
||||
const form = ref({
|
||||
b_id: 0,
|
||||
containerNo: '',
|
||||
containerImageUrl: '',
|
||||
b_container_no: '',
|
||||
b_container_img: '',
|
||||
ocrScore: 0.00,
|
||||
ocrNo: '',
|
||||
})
|
||||
@@ -53,11 +52,14 @@ function handleChooseBox() {
|
||||
})
|
||||
|
||||
imageCompress(tempFile.path).then((compressRes) => {
|
||||
console.log(compressRes)
|
||||
uploadTempFileApi(compressRes.path, tempFile.name).then((res) => {
|
||||
form.value.b_container_img = compressRes.path
|
||||
|
||||
uploadTempFileApi(compressRes.path, {
|
||||
fileName: tempFile.name,
|
||||
}).then((res) => {
|
||||
if (res.success) {
|
||||
recognizeOcrBoxApi({
|
||||
fileUrl: res.data.tempUrl,
|
||||
fileUrl: res.data.url,
|
||||
}).then((ocrRes) => {
|
||||
if (ocrRes.success) {
|
||||
toast.success('识别成功,请检查箱号是否正确')
|
||||
@@ -65,7 +67,7 @@ function handleChooseBox() {
|
||||
const score = Number(ocrRes?.data?.score ?? 0)
|
||||
form.value.ocrScore = Math.floor(score * 100) / 100
|
||||
|
||||
form.value.containerNo = ocrRes.data.boxNumber
|
||||
form.value.b_container_no = ocrRes.data.boxNumber
|
||||
form.value.ocrNo = ocrRes.data.boxNumber
|
||||
|
||||
isError.value = false
|
||||
@@ -88,29 +90,17 @@ const computedOcrScore = computed(() => {
|
||||
|
||||
function resetForm() {
|
||||
boxImage.value = null
|
||||
form.value.containerImageUrl = ''
|
||||
form.value.containerNo = ''
|
||||
form.value.b_container_no = ''
|
||||
form.value.ocrNo = ''
|
||||
form.value.ocrScore = 0.00
|
||||
|
||||
showResult.value = false
|
||||
isError.value = false
|
||||
ocrFinish.value = false
|
||||
}
|
||||
|
||||
function handleDeleteBoxImage() {
|
||||
if (!form.value.containerImageUrl) {
|
||||
resetForm()
|
||||
return
|
||||
}
|
||||
|
||||
toast.loading('正在删除中 . . .', {
|
||||
overlay: true,
|
||||
transparent: false,
|
||||
})
|
||||
|
||||
deleteAliyunFileApi(form.value.containerImageUrl).then((res) => {
|
||||
if (res.success) {
|
||||
resetForm()
|
||||
toast.success('删除成功')
|
||||
}
|
||||
})
|
||||
resetForm()
|
||||
}
|
||||
|
||||
function onItemClick(fileItem: UploadFileItem) {
|
||||
@@ -136,9 +126,7 @@ function beforeRead(file: UploadFile): boolean | Promise<UploadFile> {
|
||||
})
|
||||
}
|
||||
|
||||
function beforeRemove(index: number, fileItem: UploadFileItem): boolean | Promise<void> {
|
||||
console.log(fileItem)
|
||||
|
||||
function beforeRemove(_index: number, _fileItem: UploadFileItem): boolean | Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
dialog.confirm({
|
||||
title: '提示',
|
||||
@@ -150,28 +138,18 @@ function beforeRemove(index: number, fileItem: UploadFileItem): boolean | Promis
|
||||
})
|
||||
}
|
||||
|
||||
function onRemove(index: number, item: UploadFileItem) {
|
||||
if (item.status === 'done') {
|
||||
deleteAliyunFileApi(item.url).then((res) => {
|
||||
if (res.success) {
|
||||
toast.success('删除成功')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function handleConfirm() {
|
||||
if (form.value.containerImageUrl === '') {
|
||||
if (form.value.b_container_img === '') {
|
||||
toast.fail('集装箱号图片不能为空')
|
||||
return
|
||||
}
|
||||
|
||||
if (form.value.containerNo === '') {
|
||||
if (form.value.b_container_no === '') {
|
||||
toast.fail('集装箱号不能为空')
|
||||
return
|
||||
}
|
||||
|
||||
if (!validateContainerNo(form.value.containerNo)) {
|
||||
if (!validateContainerNo(form.value.b_container_no)) {
|
||||
toast.fail('集装箱号不符合规则,请检查')
|
||||
return
|
||||
}
|
||||
@@ -181,82 +159,88 @@ async function handleConfirm() {
|
||||
transparent: false,
|
||||
})
|
||||
|
||||
//
|
||||
const mainTable = {
|
||||
b_id: form.value.b_id,
|
||||
b_container_no: form.value.b_container_no,
|
||||
b_container_img: form.value.b_container_img,
|
||||
b_ocr_no: form.value.ocrNo,
|
||||
b_ocr_score: form.value.ocrScore || 0.00,
|
||||
}
|
||||
const fileInserts = []
|
||||
// 主表
|
||||
await uploadContainerFileApi(boxImage.value.path, {
|
||||
jobId: form.value.b_id,
|
||||
containerNo: form.value.b_container_no,
|
||||
fileName: boxImage.value.name,
|
||||
}).then((res) => {
|
||||
if (res.success) {
|
||||
mainTable.b_container_img = res.data.path
|
||||
|
||||
// // 图片已经上传成功,保存主表即可
|
||||
// const mainTable = {
|
||||
// b_id: form.value.b_id,
|
||||
// b_container_no: form.value.containerNo,
|
||||
// b_container_img: form.value.containerImageUrl,
|
||||
// b_ocr_no: form.value.ocrNo,
|
||||
// b_ocr_score: form.value.ocrScore || 0.00,
|
||||
// }
|
||||
fileInserts.push({
|
||||
subid: res.data.uid,
|
||||
father: form.value.b_id,
|
||||
mx_xh: 0,
|
||||
mx_filename: res.data.fileName,
|
||||
mx_filesize: boxImage.value.size,
|
||||
mx_fileext: getFileExtension(boxImage.value.name),
|
||||
mx_mapfilename: res.data.path,
|
||||
mx_moduleid: 'b_container',
|
||||
mx_cate_id: '0',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// const fileInserts = []
|
||||
// 子表
|
||||
for (let index = 0; index < subFileList.value.length; index++) {
|
||||
const fileItem = subFileList.value[index]
|
||||
|
||||
// const containerNo = form.value.containerNo
|
||||
const res = await uploadContainerFileApi(fileItem.file.path, {
|
||||
jobId: form.value.b_id,
|
||||
containerNo: form.value.b_container_no,
|
||||
fileName: fileItem.name,
|
||||
})
|
||||
|
||||
// subFileList.value.forEach(async (fileItem, index) => {
|
||||
// const uniqueRes = await getUniqueIdApi()
|
||||
// const indexNumber = index + 2
|
||||
if (res.success) {
|
||||
const indexNumber = index + 2
|
||||
|
||||
// fileInserts.push({
|
||||
// subid: uniqueRes.data,
|
||||
// father: form.value.b_id,
|
||||
// mx_xh: indexNumber,
|
||||
// mx_filename: buildFileName(containerNo, indexNumber, fileItem.file.name),
|
||||
// mx_filesize: fileItem.file.size,
|
||||
// mx_fileext: getFileExtension(fileItem.file.name),
|
||||
// mx_mapfilename: fileItem.url,
|
||||
// mx_moduleid: 'b_container',
|
||||
// mx_cate_id: '1',
|
||||
// })
|
||||
// })
|
||||
fileInserts.push({
|
||||
subid: res.data.uid,
|
||||
father: form.value.b_id,
|
||||
mx_xh: indexNumber,
|
||||
mx_filename: res.data.fileName,
|
||||
mx_filesize: fileItem.file.size,
|
||||
mx_fileext: getFileExtension(fileItem.file.name),
|
||||
mx_mapfilename: res.data.path,
|
||||
mx_moduleid: 'b_container',
|
||||
mx_cate_id: '1',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// const uniqueRes = await getUniqueIdApi()
|
||||
const reqData = [
|
||||
{
|
||||
tableName: 'b_container',
|
||||
keyField: 'b_id',
|
||||
inserts: [mainTable],
|
||||
updates: [],
|
||||
deletes: [],
|
||||
},
|
||||
{
|
||||
tableName: 'bf_file',
|
||||
keyField: 'subid',
|
||||
inserts: fileInserts,
|
||||
updates: [],
|
||||
deletes: [],
|
||||
},
|
||||
]
|
||||
|
||||
// fileInserts.push({
|
||||
// subid: uniqueRes.data,
|
||||
// father: form.value.b_id,
|
||||
// mx_xh: 0,
|
||||
// mx_filename: buildFileName(containerNo, 1, boxImage.value.name),
|
||||
// mx_filesize: boxImage.value.size,
|
||||
// mx_fileext: getFileExtension(boxImage.value.name),
|
||||
// mx_mapfilename: form.value.containerImageUrl,
|
||||
// mx_moduleid: 'b_container',
|
||||
// mx_cate_id: '0',
|
||||
// })
|
||||
|
||||
// const reqData = [
|
||||
// {
|
||||
// tableName: 'b_container',
|
||||
// keyField: 'b_id',
|
||||
// inserts: [mainTable],
|
||||
// updates: [],
|
||||
// deletes: [],
|
||||
// },
|
||||
// {
|
||||
// tableName: 'bf_file',
|
||||
// keyField: 'subid',
|
||||
// inserts: fileInserts,
|
||||
// updates: [],
|
||||
// deletes: [],
|
||||
// },
|
||||
// ]
|
||||
|
||||
// saveObjectApi(reqData).then((res) => {
|
||||
// if (res.success) {
|
||||
// toast.success('保存成功')
|
||||
// tipContainerNo.value = form.value.containerNo
|
||||
// showResult.value = true
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
function buildFileName(containerNo, index, fileName) {
|
||||
const formattedIndex = String(index).padStart(2, '0')
|
||||
|
||||
return `${containerNo}_${formattedIndex}.${fileName.split('.').pop()}`
|
||||
saveObjectApi(reqData).then((res) => {
|
||||
if (res.success) {
|
||||
toast.success('保存成功')
|
||||
tipContainerNo.value = form.value.b_container_no
|
||||
showResult.value = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 集装箱号校验
|
||||
@@ -302,7 +286,7 @@ async function continueAdd() {
|
||||
<view style="display:flex;align-items: center;">
|
||||
<sar-icon family="iconfont" name="iconyuanbanben_OCR" size="38rpx" color="var(--sar-primary)" style="margin-right: 16rpx;" />
|
||||
<text>
|
||||
集装箱号(OCR识别)
|
||||
箱门照(OCR识别)
|
||||
</text>
|
||||
</view>
|
||||
</template>
|
||||
@@ -367,7 +351,7 @@ async function continueAdd() {
|
||||
</view>
|
||||
</view>
|
||||
<sar-input
|
||||
v-model="form.containerNo"
|
||||
v-model="form.b_container_no"
|
||||
placeholder="请输入箱号"
|
||||
/>
|
||||
</view>
|
||||
@@ -390,7 +374,6 @@ async function continueAdd() {
|
||||
:before-read="beforeRead"
|
||||
:before-remove="beforeRemove"
|
||||
@item-click="onItemClick"
|
||||
@remove="onRemove"
|
||||
/>
|
||||
</view>
|
||||
</wd-cell-group>
|
||||
|
||||
Reference in new issue
Block a user