|
@@ -78,7 +78,7 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="ImportPicDataset">
|
|
<script setup lang="ts" name="ImportPicDataset">
|
|
-import { ref, defineExpose, onMounted } from 'vue'
|
|
|
|
|
|
+import { ref } from 'vue'
|
|
import { ElNotification, UploadRequestOptions, UploadRawFile } from 'element-plus'
|
|
import { ElNotification, UploadRequestOptions, UploadRawFile } from 'element-plus'
|
|
|
|
|
|
export interface ParameterProps {
|
|
export interface ParameterProps {
|
|
@@ -110,7 +110,6 @@ const formModel = ref({
|
|
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)
|
|
@@ -125,6 +124,9 @@ 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']
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+// 存储上传文件
|
|
|
|
+let uploadedFile: UploadRawFile | null = null
|
|
|
|
+
|
|
// 定义表单校验规则
|
|
// 定义表单校验规则
|
|
const rules = ref({
|
|
const rules = ref({
|
|
batchNum: [{ required: true, message: '批次号不能为空', trigger: 'blur' }],
|
|
batchNum: [{ required: true, message: '批次号不能为空', trigger: 'blur' }],
|
|
@@ -144,6 +146,11 @@ 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
|
|
|
|
+ resetFormModel()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 重置表单模型
|
|
|
|
+const resetFormModel = () => {
|
|
formModel.value = {
|
|
formModel.value = {
|
|
batchNum: '',
|
|
batchNum: '',
|
|
objectType: '',
|
|
objectType: '',
|
|
@@ -157,64 +164,53 @@ const acceptParams = (params: ParameterProps) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const formData = new FormData()
|
|
|
|
-
|
|
|
|
|
|
+// 提交表单
|
|
const handleSubmit = async () => {
|
|
const handleSubmit = async () => {
|
|
- // 先进行表单验证
|
|
|
|
- formRef.value.validate(async valid => {
|
|
|
|
- if (!valid) {
|
|
|
|
- ElNotification({
|
|
|
|
- title: '温馨提示',
|
|
|
|
- message: '请检查表单的输入项!',
|
|
|
|
- type: 'warning'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const zipFile = formData.get('file')
|
|
|
|
- if (!zipFile) {
|
|
|
|
- ElNotification({
|
|
|
|
- title: '温馨提示',
|
|
|
|
- message: '请上传一个压缩文件!',
|
|
|
|
- type: 'warning'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ if (!uploadedFile) {
|
|
|
|
+ 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])
|
|
|
|
- }
|
|
|
|
|
|
+ const formDataInfo = new FormData()
|
|
|
|
+ formDataInfo.append('file', uploadedFile)
|
|
|
|
+ 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'
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ 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) => {
|
|
- formData.append('file', param.file)
|
|
|
|
|
|
+ uploadedFile = param.file // 将文件保存到变量中
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 上传前的校验
|
|
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: '温馨提示',
|
|
@@ -222,6 +218,7 @@ const beforeZipUpload = (file: UploadRawFile) => {
|
|
type: 'warning'
|
|
type: 'warning'
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
if (!fileSize) {
|
|
if (!fileSize) {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
ElNotification({
|
|
ElNotification({
|
|
@@ -231,9 +228,11 @@ const beforeZipUpload = (file: UploadRawFile) => {
|
|
})
|
|
})
|
|
}, 0)
|
|
}, 0)
|
|
}
|
|
}
|
|
- return isZip && fileSize
|
|
|
|
|
|
+
|
|
|
|
+ return isZip && fileSize // 只有同时满足两个条件才允许上传
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 处理文件超出限制的情况
|
|
const handleExceed = () => {
|
|
const handleExceed = () => {
|
|
ElNotification({
|
|
ElNotification({
|
|
title: '温馨提示',
|
|
title: '温馨提示',
|