From bfc17f9eebfd04d531561a3134abfd9bccf7c894 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Tue, 10 Sep 2024 11:56:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --task=1016193 --user=宋昌昌 系统配置支持自定义文件大小限制-后端-V2 https://www.tapd.cn/55049933/s/1576397 --- .../frontend/src/i18n/lang/en-US.js | 3 ++ .../frontend/src/i18n/lang/zh-CN.js | 3 ++ .../frontend/src/i18n/lang/zh-TW.js | 3 ++ .../metersphere/dto/BaseSystemConfigDTO.java | 1 + .../commons/constants/ParamConstants.java | 5 ++-- .../service/SystemParameterService.java | 16 +++++----- .../business/system/setting/BaseSetting.vue | 30 +++++++++++++++++-- 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/framework/sdk-parent/frontend/src/i18n/lang/en-US.js b/framework/sdk-parent/frontend/src/i18n/lang/en-US.js index 23135654c2..c8667228c9 100644 --- a/framework/sdk-parent/frontend/src/i18n/lang/en-US.js +++ b/framework/sdk-parent/frontend/src/i18n/lang/en-US.js @@ -622,6 +622,9 @@ const message = { url_tip: 'example: http://localhost:4444', }, local_selenium_url: 'Local selenium-server URL', + file_upload_size: 'File size limit(MB)', + file_upload_size_is_null: 'The file size limit cannot be empty', + file_upload_tips: 'Please fill in the integer [1-1024]' }, custom_field: { add_option: 'Add Option', diff --git a/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js b/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js index 9015741bee..079ccd26ed 100644 --- a/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js +++ b/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js @@ -620,6 +620,9 @@ const message = { url_tip: '例如:http://localhost:4444', }, local_selenium_url: '本地 selenium-server 地址', + file_upload_size: '文件大小限制(MB)', + file_upload_size_is_null: '文件大小限制不能为空', + file_upload_tips: '请填写[1-1024]的整数' }, custom_field: { add_option: '添加选项', diff --git a/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js b/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js index d9d4e43aac..6573f2ef7d 100644 --- a/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js +++ b/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js @@ -619,6 +619,9 @@ const message = { url_tip: '例如:http://localhost:4444', }, local_selenium_url: '本地 selenium-server 地址', + file_upload_size: '文件大小限制(MB)', + file_upload_size_is_null: '文件大小限制不能爲空', + file_upload_tips: '請填寫[1-1024]的整數' }, custom_field: { add_option: '添加選項', diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/BaseSystemConfigDTO.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/BaseSystemConfigDTO.java index 8daf5d82ed..fde38711f2 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/BaseSystemConfigDTO.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/BaseSystemConfigDTO.java @@ -12,4 +12,5 @@ public class BaseSystemConfigDTO { private String seleniumDockerUrl; private String runMode; private String docUrl; + private String maxSize; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ParamConstants.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ParamConstants.java index a7b7e4c6ef..53be11bac0 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ParamConstants.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ParamConstants.java @@ -106,7 +106,7 @@ public interface ParamConstants { @Override public String getValue() { - return this.value; + return value; } } @@ -117,7 +117,8 @@ public interface ParamConstants { PROMETHEUS_HOST("base.prometheus.host"), SELENIUM_DOCKER_URL("base.selenium.docker.url"), RUN_MODE("base.run.mode"), - DOC_URL("base.doc.url"); + DOC_URL("base.doc.url"), + MAX_SIZE("base.file.upload.size"); private String value; diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java index b19ad44ed9..7b72daf480 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java @@ -28,7 +28,6 @@ import io.metersphere.quota.service.BaseQuotaService; import io.metersphere.request.HeaderRequest; import io.metersphere.request.resourcepool.QueryResourcePoolRequest; import jakarta.annotation.Resource; -import jakarta.mail.MessagingException; import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeMessage; import org.apache.commons.collections.CollectionUtils; @@ -96,7 +95,7 @@ public class SystemParameterService { } public void editMail(List parameters) { - List paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue()); + List paramList = getParamList(ParamConstants.Classify.MAIL.getValue()); boolean empty = paramList.size() <= 0; parameters.forEach(parameter -> { @@ -188,7 +187,7 @@ public class SystemParameterService { } public MailInfo mailInfo(String type) { - List paramList = this.getParamList(type); + List paramList = getParamList(type); MailInfo mailInfo = new MailInfo(); if (!CollectionUtils.isEmpty(paramList)) { for (SystemParameter param : paramList) { @@ -275,7 +274,7 @@ public class SystemParameterService { public BaseSystemConfigDTO getBaseInfo() { BaseSystemConfigDTO baseSystemConfigDTO = new BaseSystemConfigDTO(); - List paramList = this.getParamList(ParamConstants.Classify.BASE.getValue()); + List paramList = getParamList(ParamConstants.Classify.BASE.getValue()); if (!CollectionUtils.isEmpty(paramList)) { for (SystemParameter param : paramList) { if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.URL.getValue())) { @@ -296,6 +295,9 @@ public class SystemParameterService { if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.DOC_URL.getValue())) { baseSystemConfigDTO.setDocUrl(param.getParamValue()); } + if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.MAX_SIZE.getValue())) { + baseSystemConfigDTO.setMaxSize(param.getParamValue()); + } } } return baseSystemConfigDTO; @@ -469,7 +471,7 @@ public class SystemParameterService { } public String getLogDetails() { - LdapInfo ldapInfo = this.getLdapInfo(ParamConstants.Classify.LDAP.getValue()); + LdapInfo ldapInfo = getLdapInfo(ParamConstants.Classify.LDAP.getValue()); if (ldapInfo != null) { List columns = ReflexObjectUtil.getColumns(ldapInfo, SystemReference.ldapColumns); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ldapInfo.getUrl()), null, "LDAP设置", null, columns); @@ -479,7 +481,7 @@ public class SystemParameterService { } public String getMailLogDetails() { - MailInfo mailInfo = this.mailInfo(ParamConstants.Classify.MAIL.getValue()); + MailInfo mailInfo = mailInfo(ParamConstants.Classify.MAIL.getValue()); if (mailInfo != null) { List columns = ReflexObjectUtil.getColumns(mailInfo, SystemReference.mailColumns); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(mailInfo.getAccount()), null, "邮件设置", null, columns); @@ -489,7 +491,7 @@ public class SystemParameterService { } public String getBaseLogDetails() { - BaseSystemConfigDTO configDTO = this.getBaseInfo(); + BaseSystemConfigDTO configDTO = getBaseInfo(); if (configDTO != null) { List columns = ReflexObjectUtil.getColumns(configDTO, SystemReference.baseColumns); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(configDTO.getUrl()), null, "基本配置", null, columns); diff --git a/system-setting/frontend/src/business/system/setting/BaseSetting.vue b/system-setting/frontend/src/business/system/setting/BaseSetting.vue index 6e023abea2..8c9c496082 100644 --- a/system-setting/frontend/src/business/system/setting/BaseSetting.vue +++ b/system-setting/frontend/src/business/system/setting/BaseSetting.vue @@ -19,6 +19,9 @@ + + + @@ -39,8 +42,23 @@ import {getSystemBaseSetting, saveSystemBaseSetting} from "../../../api/system"; export default { name: "BaseSetting", data() { + const checkUploadSize = (rule, value, callback) => { + if (!value) { + return callback(new Error(this.$t('system_config.file_upload_size_is_null'))); + } + if (isNaN(value) || !Number.isInteger(Number(value))) { + callback(new Error(this.$t('system_config.file_upload_tips'))); + } else { + const size = Number.parseInt(value); + if (size < 1 || size > 1024) { + callback(new Error(this.$t('system_config.file_upload_tips'))); + } else { + callback(); + } + } + }; return { - formInline: {runMode: true, docUrl: 'https://metersphere.io/docs/index.html'}, + formInline: {runMode: true, docUrl: 'https://metersphere.io/docs/index.html', maxSize: null}, input: '', visible: true, showEdit: true, @@ -65,6 +83,12 @@ export default { trigger: ['change', 'blur'] }, ], + maxSize: [ + { + validator: checkUploadSize, + trigger: ['change', 'blur'] + } + ], } } }, @@ -82,6 +106,7 @@ export default { res.data.docUrl = 'https://metersphere.io/docs/index.html' } this.formInline = res.data; + console.log(this.formInline); this.$nextTick(() => { if (this.$refs.formInline) { this.$refs.formInline.clearValidate(); @@ -109,7 +134,8 @@ export default { {paramKey: "base.concurrency", paramValue: this.formInline.concurrency, type: "text", sort: 2}, {paramKey: "base.prometheus.host", paramValue: this.formInline.prometheusHost, type: "text", sort: 1}, {paramKey: "base.selenium.docker.url", paramValue: this.formInline.seleniumDockerUrl, type: "text", sort: 1}, - {paramKey: "base.doc.url", paramValue: this.formInline.docUrl, type: "text", sort: 1} + {paramKey: "base.doc.url", paramValue: this.formInline.docUrl, type: "text", sort: 1}, + {paramKey: "base.file.upload.size", paramValue: this.formInline.maxSize, type: "text", sort: 1}, ]; this.loading = saveSystemBaseSetting(param).then(res => { if (res.success) {