From b60b534f481cab45a45ac3e5ef0d426f55490867 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 23 Mar 2021 20:10:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E6=9F=A5=E8=AF=A2=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/components/ExistFiles.vue | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/frontend/src/business/components/performance/test/components/ExistFiles.vue b/frontend/src/business/components/performance/test/components/ExistFiles.vue index 9a3843f6c4..ad48447019 100644 --- a/frontend/src/business/components/performance/test/components/ExistFiles.vue +++ b/frontend/src/business/components/performance/test/components/ExistFiles.vue @@ -201,7 +201,7 @@ export default { }); }, - async beforeUploadFile(file) { + beforeUploadFile(file) { if (!this.fileValidator(file)) { /// todo: 显示错误信息 return false; @@ -211,14 +211,14 @@ export default { this.$error(this.$t('load_test.delete_file')); return false; } - let valid = false; - + }, + checkFileExist(file, callback) { // 检查数据库是否存在同名文件 async function f() { return await axios.post('/performance/file/' + getCurrentProjectID() + '/getMetadataByName', {name: file.name}) } - await f().then(res => { + f().then(res => { let response = res.data; if (response.data.length === 0) { let type = file.name.substring(file.name.lastIndexOf(".") + 1); @@ -229,33 +229,34 @@ export default { type: type.toUpperCase(), updateTime: file.lastModified, }); - valid = true; + + callback(); } else { this.$error(this.$t('load_test.project_file_exist')); } }); - - - return valid; }, handleUpload(uploadResources) { let self = this; + let file = uploadResources.file; - self.uploadList.push(file); - let type = file.name.substring(file.name.lastIndexOf(".") + 1); - if (type.toLowerCase() !== 'jmx') { - return; - } - let jmxReader = new FileReader(); - jmxReader.onload = (event) => { - let threadGroups = findThreadGroup(event.target.result, file.name); - threadGroups.forEach(tg => { - tg.options = {}; - this.scenarios.push(tg); - }); - self.$emit('fileChange', self.scenarios); - }; - jmxReader.readAsText(file); + this.checkFileExist(file, () => { + self.uploadList.push(file); + let type = file.name.substring(file.name.lastIndexOf(".") + 1); + if (type.toLowerCase() !== 'jmx') { + return; + } + let jmxReader = new FileReader(); + jmxReader.onload = (event) => { + let threadGroups = findThreadGroup(event.target.result, file.name); + threadGroups.forEach(tg => { + tg.options = {}; + self.scenarios.push(tg); + }); + self.$emit('fileChange', self.scenarios); + }; + jmxReader.readAsText(file); + }) }, handleExceed() { this.$error(this.$t('load_test.file_size_limit'));