From 07e50117a234943d67f54acb0f88a034e5d16f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E7=8E=89=E7=90=A6?= <7507756+jiang_yuqi@user.noreply.gitee.com> Date: Mon, 22 Jul 2024 16:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/dataSet/index.js | 4 +- src/views/manage/calculate/edit.vue | 2 +- src/views/manage/datas/add.vue | 10 +- src/views/manage/datas/edit.vue | 223 +++++++++++++++++++++------- 4 files changed, 173 insertions(+), 66 deletions(-) diff --git a/src/api/dataSet/index.js b/src/api/dataSet/index.js index 423362e..f7237cf 100644 --- a/src/api/dataSet/index.js +++ b/src/api/dataSet/index.js @@ -31,7 +31,7 @@ const dataSetInfo = (id) => { }); } //更新指定数据集的内容 -const updateDataSet = (id) => { +const updateDataSet = (id,data) => { return request({ url: `/dataset/raw/${id}`, method: "put", @@ -61,7 +61,7 @@ const rawFiles = (id) => { method: "get" }); } -//获取设备信息 +//上传数据文件 const rawUpload = (id, data) => { return request({ url: `/dataset/raw/${id}/upload`, diff --git a/src/views/manage/calculate/edit.vue b/src/views/manage/calculate/edit.vue index e64abf6..aa29017 100644 --- a/src/views/manage/calculate/edit.vue +++ b/src/views/manage/calculate/edit.vue @@ -193,7 +193,7 @@ function handleFileChange(file) { } uploadFile(file).then((res) => { if (isJSON(res)) { - formData.parameters = JSON.parse(str); + formData.parameters = JSON.parse(res); formRef.value.validateField("parameters"); codeHtml.value = res; fileStatus.value = true; diff --git a/src/views/manage/datas/add.vue b/src/views/manage/datas/add.vue index 13b2fe9..e11639a 100644 --- a/src/views/manage/datas/add.vue +++ b/src/views/manage/datas/add.vue @@ -134,18 +134,16 @@ - - 数据集参数文件预览 - 数据集参数文件预览 + - diff --git a/src/views/manage/datas/edit.vue b/src/views/manage/datas/edit.vue index 6d0f168..c77f432 100644 --- a/src/views/manage/datas/edit.vue +++ b/src/views/manage/datas/edit.vue @@ -143,18 +143,16 @@ - - 数据集参数文件预览 - - + 数据集参数文件预览 + @@ -170,7 +168,7 @@ type="primary" style="position: absolute; right: 30px" @click="handleRemoveAll" - :disabled="imageList.length==0" + :disabled="imageList.length == 0" >清空全部 @@ -179,60 +177,50 @@ class="upload-demo upload-demo-2" :before-remove="beforeRemove" /> - + - 上传图片 + 上传图片 确 定 取 消 - - - - + + 选择文件 + + + 请上传大小不超过 10M,格式为 + png/jpg/jpeg/json 的文件 + + - - - - - - + + @@ -259,7 +247,13 @@ const remImageList = ref([]); // 删除图片列表 // 上传组件 const uploadRef = ref(); +const autoTime = ref(""); // 自动上传 +const autoUpload = ref(false); // 自动上传 const dialogVisible = ref(false); // 加载状态 +const uploadLoading = ref(false); // 加载状态 +const uploadAllList = ref([]); // 待上传文件列表 +const uploadJsonList = ref([]); // 待上传JSON列表 +const uploadImgFileList = ref([]); // 待上传图片列表 // 基础数据列表 let listOpt = reactive({ @@ -294,7 +288,7 @@ const handleSubmit = useThrottleFn(() => { return false; } loading.value = true; - DataSetApi.add(form) + DataSetApi.updateDataSet(form.value.dataset_id, form.value) .then((res) => { if (res.data.code == 0) { ElMessage.success("保存成功"); @@ -308,6 +302,106 @@ const handleSubmit = useThrottleFn(() => { }); }, 3000); +/** 上传文件 */ +function handleChangeFiles(uploadFile, uploadFiles) { + //uploadFile.status = 'success'; + clearTimeout(autoTime.value); + if (uploadFile.raw.type == "application/json") { + uploadJsonList.value.push(uploadFile); + } + autoTime.value = setTimeout(doEquipmentFiles, 280); +} + +/** 上传文件>回调 */ +const doEquipmentFiles = () => { + uploadImgFileList.value = uploadImgFileList.value.filter( + (it) => it.raw.type != "application/json" + ); + if (form.value.dats_label_type != "no_label") { + var element = document.getElementsByClassName("upload-demo-3")[0]; + var children = element.querySelectorAll(".el-upload-list__item"); + children.forEach((item) => { + var mylabel = item.querySelectorAll(".mylabel"); + //console.log("mylabel.length==>" + mylabel.length); + if (mylabel.length > 0) { + mylabel.forEach((lab) => { + lab.remove(); + }); + } + let name = item.querySelector(".el-upload-list__item-file-name").textContent; + let disp = uploadJsonList.value.filter((it) => disName(name, it.name)); + //console.log("disp==>" + disp.length); + if (disp.length > 0) { + item.insertAdjacentHTML( + "beforeend", + "已标注JSON" + ); + } else { + item.insertAdjacentHTML( + "beforeend", + "未标注JSON" + ); + } + }); + } +}; + +/** 标注文件名称比对 */ +function disName(img, json) { + if ( + img.substring(0, img.lastIndexOf(".")) == json.substring(0, json.lastIndexOf(".")) + ) { + return true; + } else { + return false; + } +} + +/** 删除图片的json标注 */ +function handleRemoveFiles(uploadFile, uploadFiles) { + uploadJsonList.value = uploadJsonList.value.filter( + (it) => !disName(uploadFile.name, it.name) + ); + return true; +} + +/** 开始上传文件 */ +function startUploadFiles() { + var element = document.getElementsByClassName("upload-demo-3")[0]; + var errors = element.querySelectorAll(".mylabel--error"); + if (errors.length > 0) { + ElMessage.error(errors.length + " 个图片未上传标注文件!请上传或删除图片。"); + return false; + } + uploadImgFileList.value.forEach((item) => { + let json = uploadJsonList.value.filter((it) => disName(item.name, it.name)); + let data = { + image_file_name: item.name, + image_file: item, + label_file: json.length > 0 ? json[0] : null, + }; + uploadLoading.value = true; + DataSetApi.rawUpload(form.value.dataset_id, data) + .then((res) => { + if (res.data.code == 0) { + uploadImgFileList.value = uploadImgFileList.value.filter( + (it) => item.name != it.name + ); + uploadJsonList.value = uploadJsonList.value.filter( + (it) => !disName(item.name, it.name) + ); + if (uploadImgFileList.value.length == 0) { + handleQuery(); + dialogVisible.value = false; + } + } + }) + .finally(() => { + uploadLoading.value = false; + }); + }); +} + /** 删除文件 */ function beforeRemove(file) { remImageList.value.push(file.name); @@ -348,8 +442,8 @@ function handleRemoveAll() { } /** 打开文件上传弹窗 */ -function handleImageDialog(){ - dialogVisible.value=true; +function handleImageDialog() { + dialogVisible.value = true; } // 文件上传 @@ -509,6 +603,12 @@ onMounted(() => { }