diff --git a/backend/src/main/java/io/metersphere/controller/CustomFieldTemplateController.java b/backend/src/main/java/io/metersphere/controller/CustomFieldTemplateController.java index 9ed5ac9b1e..1c2be24d60 100644 --- a/backend/src/main/java/io/metersphere/controller/CustomFieldTemplateController.java +++ b/backend/src/main/java/io/metersphere/controller/CustomFieldTemplateController.java @@ -1,12 +1,10 @@ package io.metersphere.controller; +import io.metersphere.base.domain.CustomField; import io.metersphere.base.domain.CustomFieldTemplate; import io.metersphere.dto.CustomFieldTemplateDao; import io.metersphere.service.CustomFieldTemplateService; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @@ -27,4 +25,10 @@ public class CustomFieldTemplateController { public void update(@RequestBody CustomFieldTemplate request) { customFieldTemplateService.update(request); } + + @GetMapping("/{id}") + public CustomField get(@PathVariable String id) { + return customFieldTemplateService.getCustomField(id); + } + } diff --git a/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java b/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java index e0c75a13d6..ad3eac645e 100644 --- a/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java +++ b/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java @@ -4,6 +4,7 @@ package io.metersphere.service; import io.metersphere.base.domain.CustomField; import io.metersphere.base.domain.CustomFieldTemplate; import io.metersphere.base.domain.CustomFieldTemplateExample; +import io.metersphere.base.mapper.CustomFieldMapper; import io.metersphere.base.mapper.CustomFieldTemplateMapper; import io.metersphere.base.mapper.ext.ExtCustomFieldTemplateMapper; import io.metersphere.dto.CustomFieldTemplateDao; @@ -33,6 +34,8 @@ public class CustomFieldTemplateService { SqlSessionFactory sqlSessionFactory; @Resource CustomFieldService customFieldService; + @Resource + private CustomFieldMapper customFieldMapper; public List getCustomFieldIds(String templateId) { return extCustomFieldTemplateMapper.getCustomFieldIds(templateId); @@ -121,4 +124,10 @@ public class CustomFieldTemplateService { public void update(CustomFieldTemplate request) { customFieldTemplateMapper.updateByPrimaryKeySelective(request); } + + public CustomField getCustomField(String id) { + CustomFieldTemplate customFieldTemplate = customFieldTemplateMapper.selectByPrimaryKey(id); + String fieldId = customFieldTemplate.getFieldId(); + return customFieldMapper.selectByPrimaryKey(fieldId); + } } diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java index f6203c7f81..fccf7caa43 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseBatchRequest.java @@ -15,6 +15,7 @@ public class TestCaseBatchRequest extends TestCaseWithBLOBs { private String projectId; private CustomFiledRequest customField; private QueryTestCaseRequest condition; + private String customTemplateFieldId; @Getter @Setter diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 64ca694789..3442390b4b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -1268,15 +1268,18 @@ public class TestCaseService { } boolean hasField = false; - for (int i = 0; i < fields.size(); i++) { - TestCaseBatchRequest.CustomFiledRequest field = fields.get(i); - if (StringUtils.equals(request.getCustomField().getName(), field.getName())) { + for (TestCaseBatchRequest.CustomFiledRequest field : fields) { + if (StringUtils.equals(request.getCustomTemplateFieldId(), field.getId())) { field.setValue(request.getCustomField().getValue()); hasField = true; break; } } if (!hasField) { + TestCaseBatchRequest.CustomFiledRequest customField = request.getCustomField(); + customField.setId(request.getCustomTemplateFieldId()); + customField.setName(request.getCustomField().getName()); + customField.setValue(request.getCustomField().getValue()); fields.add(request.getCustomField()); } if (StringUtils.equals(request.getCustomField().getName(), "用例等级")) { diff --git a/frontend/src/business/components/settings/workspace/template/CustomFiledComponent.vue b/frontend/src/business/components/settings/workspace/template/CustomFiledComponent.vue index 06d502d935..f0549057eb 100644 --- a/frontend/src/business/components/settings/workspace/template/CustomFiledComponent.vue +++ b/frontend/src/business/components/settings/workspace/template/CustomFiledComponent.vue @@ -114,11 +114,9 @@ export default { }; }, mounted() { - if (this.data.type === 'member' || this.data.type === 'multipleMember') { - this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => { - this.memberOptions = response.data; - }); - } + this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => { + this.memberOptions = response.data; + }); }, methods: { getTranslateOption(item) { diff --git a/frontend/src/business/components/track/case/components/BatchEdit.vue b/frontend/src/business/components/track/case/components/BatchEdit.vue index 77550cc490..73552c9153 100644 --- a/frontend/src/business/components/track/case/components/BatchEdit.vue +++ b/frontend/src/business/components/track/case/components/BatchEdit.vue @@ -12,7 +12,7 @@ - + @@ -27,6 +27,9 @@ @setEnvGroup="setEnvGroup" ref="envPopover"/> + + + @@ -51,9 +54,11 @@ import {listenGoBack, removeGoBackListener} from "@/common/js/utils"; import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover"; import {ENV_TYPE} from "@/common/js/constants"; + import CustomFiledComponent from "@/business/components/settings/workspace/template/CustomFiledComponent"; export default { name: "BatchEdit", components: { + CustomFiledComponent, EnvPopover, MsDialogFooter }, @@ -88,7 +93,9 @@ isScenario: '', result: {}, environmentType: ENV_TYPE.JSON, - envGroupId: "" + envGroupId: "", + customField: {}, + fieldType: "" } }, computed: { @@ -107,6 +114,10 @@ } this.form.map = this.map; } + // 处理自定义字段 + if (this.form.type.startsWith("custom")) { + this.form.customField = this.customField; + } this.form.environmentType = this.environmentType; this.form.envGroupId = this.envGroupId; this.$emit("batchEdit", this.form); @@ -150,9 +161,25 @@ handleClose() { this.form = {}; this.options = []; + this.fieldType = ""; removeGoBackListener(this.handleClose); }, + _handleCustomField(val) { + // custom template field id + let id = val.slice(6); + this.fieldType = "custom"; + this.$get("/custom/field/template/" + id, res => { + this.customField = res ? res.data : {}; + this.customField.options = JSON.parse(this.customField.options); + if (this.customField.type === 'checkbox' || this.customField.type === 'multipleMember') { + this.customField.defaultValue = []; + } + }) + }, changeType(val) { + if (val && val.startsWith("custom")) { + this._handleCustomField(val); + } this.$set(this.form, "value", ""); if (val === 'projectEnv' && this.isScenario !== '') { this.projectIds.clear(); diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index 7f51297e42..2977e130e9 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -866,10 +866,14 @@ export default { batchEdit(form) { let ids = this.$refs.table.selectIds; let param = {}; - param.customField = form; - param.customField.name = form.type; param.ids = ids; + param.customTemplateFieldId = form.type.slice(6); param.condition = this.condition; + param.customField = { + id: form.customField.id, + name: form.customField.name, + value: form.customField.defaultValue + }; this.$post('/test/case/batch/edit', param, () => { this.$success(this.$t('commons.save_success')); this.refresh(); diff --git a/frontend/src/common/js/tableUtils.js b/frontend/src/common/js/tableUtils.js index 38a1603dbc..d0be4a8d67 100644 --- a/frontend/src/common/js/tableUtils.js +++ b/frontend/src/common/js/tableUtils.js @@ -511,7 +511,8 @@ export function getCustomFieldBatchEditOption(customFields, typeArr, valueArr, m typeArr.push({ id: item.name, name: item.name, - uuid: item.id + uuid: item.id, + custom: "custom" + item.id }); let options = [];