diff --git a/backend/src/main/java/io/metersphere/controller/ProjectController.java b/backend/src/main/java/io/metersphere/controller/ProjectController.java index 790bb76b50..1711633b9b 100644 --- a/backend/src/main/java/io/metersphere/controller/ProjectController.java +++ b/backend/src/main/java/io/metersphere/controller/ProjectController.java @@ -2,6 +2,7 @@ package io.metersphere.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.Project; import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.utils.PageUtils; @@ -86,8 +87,8 @@ public class ProjectController { } @PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"}) - public void uploadFiles(@PathVariable String projectId, @RequestPart(value = "file") List files) { - projectService.uploadFiles(projectId, files); + public List uploadFiles(@PathVariable String projectId, @RequestPart(value = "file") List files) { + return projectService.uploadFiles(projectId, files); } @GetMapping(value = "delete/file/{fileId}") diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index d0b601c31c..4723f29dc3 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -28,6 +28,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @@ -169,18 +170,20 @@ public class ProjectService { return projectMapper.selectByPrimaryKey(id); } - public void uploadFiles(String projectId, List files) { + public List uploadFiles(String projectId, List files) { + List result = new ArrayList<>(); if (files != null) { for (MultipartFile file : files) { QueryProjectFileRequest request = new QueryProjectFileRequest(); request.setName(file.getOriginalFilename()); if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) { - fileService.saveFile(file, projectId); + result.add(fileService.saveFile(file, projectId)); } else { MSException.throwException(Translator.get("project_file_already_exists")); } } } + return result; } public void deleteFile(String fileId) { diff --git a/frontend/src/business/components/performance/test/components/ExistFiles.vue b/frontend/src/business/components/performance/test/components/ExistFiles.vue index 53f7541e98..fc75b9f832 100644 --- a/frontend/src/business/components/performance/test/components/ExistFiles.vue +++ b/frontend/src/business/components/performance/test/components/ExistFiles.vue @@ -141,7 +141,13 @@ export default { this.existFiles = data.listObject; }) }, - handleImport() { + handleImport(file) { + if (file) { // 接口测试创建的性能测试 + console.log(file); + this.selectIds.add(file.id); + this.getJmxContents(); + return; + } if (this.selectIds.size === 0) { this.loadFileVisible = false; return; @@ -163,7 +169,7 @@ export default { this.tableData.push({ name: row.name, size: (row.size / 1024).toFixed(2) + ' KB', - type: 'JMX', + type: row.type.toUpperCase(), updateTime: row.lastModified, }); }) @@ -173,6 +179,9 @@ export default { return; } + this.getJmxContents(); + }, + getJmxContents() { this.projectLoadingResult = this.$post('/performance/export/jmx', [...this.selectIds], (response) => { let data = response.data; if (!data) { @@ -199,7 +208,6 @@ export default { this.loadFileVisible = false; this.selectIds.clear(); }); - }, beforeUploadFile(file) { if (!this.fileValidator(file)) { @@ -227,7 +235,7 @@ export default { } }); }, - handleUpload(uploadResources) { + handleUpload(uploadResources, apiImport) { let self = this; let file = uploadResources.file; @@ -246,6 +254,10 @@ export default { self.$request(options, (response) => { self.$success(this.$t('commons.save_success')); self.getProjectFiles(); + if (apiImport) { + let row = response.data[0]; + self.handleImport(row); + } }); }) }, diff --git a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue index 7cf3d68831..bd5272b216 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue @@ -333,7 +333,8 @@ export default { this.$refs.existFiles.beforeUploadFile(file); }, handleUpload(file) { - this.$refs.existFiles.handleUpload(file); + // 从api创建的测试 + this.$refs.existFiles.handleUpload(file, true); }, }, }