|
@@ -1,6 +1,6 @@
|
|
<template>
|
|
<template>
|
|
<el-dialog v-model="dialogVisible" :width="parameter.width" :top="parameter.top" :title="`${parameter.title}`" :destroy-on-close="true" draggable>
|
|
<el-dialog v-model="dialogVisible" :width="parameter.width" :top="parameter.top" :title="`${parameter.title}`" :destroy-on-close="true" draggable>
|
|
- <el-form class="drawer-multiColumn-form" label-width="100px">
|
|
|
|
|
|
+ <el-form class="drawer-multiColumn-form" label-width="100px" :model="formModel" :rules="rules" ref="formRef">
|
|
<el-form-item label="图片数据集压缩文件上传">
|
|
<el-form-item label="图片数据集压缩文件上传">
|
|
<el-upload
|
|
<el-upload
|
|
action="#"
|
|
action="#"
|
|
@@ -78,7 +78,7 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="ImportPicDataset">
|
|
<script setup lang="ts" name="ImportPicDataset">
|
|
-import { ref } from 'vue'
|
|
|
|
|
|
+import { ref, defineExpose, onMounted } from 'vue'
|
|
import { ElNotification, UploadRequestOptions, UploadRawFile } from 'element-plus'
|
|
import { ElNotification, UploadRequestOptions, UploadRawFile } from 'element-plus'
|
|
|
|
|
|
export interface ParameterProps {
|
|
export interface ParameterProps {
|
|
@@ -97,7 +97,6 @@ export interface ParameterProps {
|
|
|
|
|
|
const formModel = ref({
|
|
const formModel = ref({
|
|
batchNum: '',
|
|
batchNum: '',
|
|
- name: '',
|
|
|
|
objectType: '',
|
|
objectType: '',
|
|
objectSubtype: '',
|
|
objectSubtype: '',
|
|
scene: '',
|
|
scene: '',
|
|
@@ -107,11 +106,13 @@ const formModel = ref({
|
|
dataType: '',
|
|
dataType: '',
|
|
labeled: false
|
|
labeled: false
|
|
})
|
|
})
|
|
|
|
+
|
|
const dataTypes = ref([
|
|
const dataTypes = ref([
|
|
{ dictValue: '1', dictLabel: '训练' },
|
|
{ dictValue: '1', dictLabel: '训练' },
|
|
{ dictValue: '2', dictLabel: '测试' }
|
|
{ dictValue: '2', dictLabel: '测试' }
|
|
// 添加更多数据类型
|
|
// 添加更多数据类型
|
|
])
|
|
])
|
|
|
|
+
|
|
const dialogVisible = ref(false)
|
|
const dialogVisible = ref(false)
|
|
const parameter = ref<ParameterProps>({
|
|
const parameter = ref<ParameterProps>({
|
|
title: '',
|
|
title: '',
|
|
@@ -124,12 +125,27 @@ const parameter = ref<ParameterProps>({
|
|
ZipFileType: ['application/zip', 'application/x-zip-compressed', 'application/x-rar-compressed']
|
|
ZipFileType: ['application/zip', 'application/x-zip-compressed', 'application/x-rar-compressed']
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+// 定义表单校验规则
|
|
|
|
+const rules = ref({
|
|
|
|
+ batchNum: [{ required: true, message: '批次号不能为空', trigger: 'blur' }],
|
|
|
|
+ objectType: [{ required: true, message: '目标类型不能为空', trigger: 'blur' }],
|
|
|
|
+ objectSubtype: [{ required: true, message: '目标子类型不能为空', trigger: 'blur' }],
|
|
|
|
+ scene: [{ required: true, message: '场景不能为空', trigger: 'blur' }],
|
|
|
|
+ dataSource: [{ required: true, message: '数据源不能为空', trigger: 'blur' }],
|
|
|
|
+ gatherSpot: [{ required: true, message: '采集地点不能为空', trigger: 'blur' }],
|
|
|
|
+ gatherTime: [{ required: true, message: '采集时间不能为空', trigger: 'change' }],
|
|
|
|
+ dataType: [{ required: true, message: '数据类型不能为空', trigger: 'change' }]
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+// 用于存储表单引用
|
|
|
|
+const formRef = ref(null)
|
|
|
|
+
|
|
|
|
+// 接收参数并初始化对话框
|
|
const acceptParams = (params: ParameterProps) => {
|
|
const acceptParams = (params: ParameterProps) => {
|
|
parameter.value = { ...parameter.value, ...params }
|
|
parameter.value = { ...parameter.value, ...params }
|
|
dialogVisible.value = true
|
|
dialogVisible.value = true
|
|
formModel.value = {
|
|
formModel.value = {
|
|
batchNum: '',
|
|
batchNum: '',
|
|
- name: '',
|
|
|
|
objectType: '',
|
|
objectType: '',
|
|
objectSubtype: '',
|
|
objectSubtype: '',
|
|
scene: '',
|
|
scene: '',
|
|
@@ -140,41 +156,56 @@ const acceptParams = (params: ParameterProps) => {
|
|
labeled: false
|
|
labeled: false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
const formData = new FormData()
|
|
const formData = new FormData()
|
|
|
|
+
|
|
const handleSubmit = async () => {
|
|
const handleSubmit = async () => {
|
|
- const zipFile = formData.get('file')
|
|
|
|
- console.log(zipFile)
|
|
|
|
- if (!zipFile) {
|
|
|
|
- ElNotification({
|
|
|
|
- title: '温馨提示',
|
|
|
|
- message: '请上传一个压缩文件!',
|
|
|
|
- type: 'warning'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- const formDataInfo = new FormData()
|
|
|
|
- formDataInfo.append('file', zipFile)
|
|
|
|
- for (const key in formModel.value) {
|
|
|
|
- if (Object.prototype.hasOwnProperty.call(formModel.value, key)) {
|
|
|
|
- formDataInfo.append(key, formModel.value[key])
|
|
|
|
|
|
+ // 先进行表单验证
|
|
|
|
+ formRef.value.validate(async valid => {
|
|
|
|
+ if (!valid) {
|
|
|
|
+ ElNotification({
|
|
|
|
+ title: '温馨提示',
|
|
|
|
+ message: '请检查表单的输入项!',
|
|
|
|
+ type: 'warning'
|
|
|
|
+ })
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- }
|
|
|
|
- try {
|
|
|
|
- await parameter.value.importApi!(formDataInfo)
|
|
|
|
- ElNotification({
|
|
|
|
- title: '温馨提示',
|
|
|
|
- message: `文件上传成功`,
|
|
|
|
- type: 'success'
|
|
|
|
- })
|
|
|
|
- parameter.value.getTableList && parameter.value.getTableList()
|
|
|
|
- dialogVisible.value = false
|
|
|
|
- } catch (error) {
|
|
|
|
- // ElNotification({
|
|
|
|
- // // title: '温馨提示',
|
|
|
|
- // // message: `文件上传失败,请重新上传`,
|
|
|
|
- // // type: 'error'
|
|
|
|
- // })
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ const zipFile = formData.get('file')
|
|
|
|
+ if (!zipFile) {
|
|
|
|
+ ElNotification({
|
|
|
|
+ title: '温馨提示',
|
|
|
|
+ message: '请上传一个压缩文件!',
|
|
|
|
+ type: 'warning'
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const formDataInfo = new FormData()
|
|
|
|
+ formDataInfo.append('file', zipFile)
|
|
|
|
+ for (const key in formModel.value) {
|
|
|
|
+ if (Object.prototype.hasOwnProperty.call(formModel.value, key)) {
|
|
|
|
+ formDataInfo.append(key, formModel.value[key])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ await parameter.value.importApi!(formDataInfo)
|
|
|
|
+ ElNotification({
|
|
|
|
+ title: '温馨提示',
|
|
|
|
+ message: `文件上传成功`,
|
|
|
|
+ type: 'success'
|
|
|
|
+ })
|
|
|
|
+ parameter.value.getTableList && parameter.value.getTableList()
|
|
|
|
+ dialogVisible.value = false
|
|
|
|
+ } catch (error) {
|
|
|
|
+ ElNotification({
|
|
|
|
+ title: '温馨提示',
|
|
|
|
+ message: `文件上传失败,请重新上传`,
|
|
|
|
+ type: 'error'
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
const uploadZip = (param: UploadRequestOptions) => {
|
|
const uploadZip = (param: UploadRequestOptions) => {
|
|
@@ -184,13 +215,14 @@ const uploadZip = (param: UploadRequestOptions) => {
|
|
const beforeZipUpload = (file: UploadRawFile) => {
|
|
const beforeZipUpload = (file: UploadRawFile) => {
|
|
const isZip = parameter.value.ZipFileType!.includes(file.type as File.ZipMimeType)
|
|
const isZip = parameter.value.ZipFileType!.includes(file.type as File.ZipMimeType)
|
|
const fileSize = file.size / 1024 / 1024 < parameter.value.fileSize!
|
|
const fileSize = file.size / 1024 / 1024 < parameter.value.fileSize!
|
|
- if (!isZip)
|
|
|
|
|
|
+ if (!isZip) {
|
|
ElNotification({
|
|
ElNotification({
|
|
title: '温馨提示',
|
|
title: '温馨提示',
|
|
message: '上传文件只能是 zip 格式!',
|
|
message: '上传文件只能是 zip 格式!',
|
|
type: 'warning'
|
|
type: 'warning'
|
|
})
|
|
})
|
|
- if (!fileSize)
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!fileSize) {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
ElNotification({
|
|
ElNotification({
|
|
title: '温馨提示',
|
|
title: '温馨提示',
|
|
@@ -198,6 +230,7 @@ const beforeZipUpload = (file: UploadRawFile) => {
|
|
type: 'warning'
|
|
type: 'warning'
|
|
})
|
|
})
|
|
}, 0)
|
|
}, 0)
|
|
|
|
+ }
|
|
return isZip && fileSize
|
|
return isZip && fileSize
|
|
}
|
|
}
|
|
|
|
|