From 8d8c5685031834992ed4f5085f0a2b350dd2b5d2 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Fri, 22 Nov 2024 14:32:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E5=86=85=E7=BD=AE=E5=AD=97=E6=AE=B5=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1049213 --user=宋昌昌 【缺陷管理】LOCAL平台-新建缺陷-处理人、状态展示为英文 https://www.tapd.cn/55049933/s/1615277 --- .../bug/controller/BugController.java | 4 +-- .../bug/enums/BugTemplateCustomField.java | 12 ++++--- .../metersphere/bug/service/BugService.java | 24 +++++++------- frontend/src/utils/index.ts | 33 ++++++++++++------- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java index e75ea8a72b..17374ee031 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java @@ -133,7 +133,7 @@ public class BugController { @Operation(summary = "缺陷管理-列表-查看缺陷(详情&&编辑&&复制)") @RequiresPermissions(PermissionConstants.PROJECT_BUG_READ) public BugDetailDTO get(@PathVariable String id) { - return bugService.get(id, SessionUtils.getUserId()); + return bugService.get(id, SessionUtils.getUserId(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage()); } @GetMapping("/delete/{id}") @@ -229,7 +229,7 @@ public class BugController { @RequiresPermissions(PermissionConstants.PROJECT_BUG_READ) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public TemplateDTO getTemplateDetail(@RequestBody BugTemplateRequest request) { - return bugService.getTemplate(request.getId(), request.getProjectId(), request.getFromStatusId(), request.getPlatformBugKey(), request.getShowLocal()); + return bugService.getTemplate(request.getId(), request.getProjectId(), request.getFromStatusId(), request.getPlatformBugKey(), request.getShowLocal(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage()); } @GetMapping("/follow/{id}") diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/enums/BugTemplateCustomField.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/enums/BugTemplateCustomField.java index cded91a019..262bb50b30 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/enums/BugTemplateCustomField.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/enums/BugTemplateCustomField.java @@ -3,20 +3,20 @@ package io.metersphere.bug.enums; import io.metersphere.sdk.util.Translator; import lombok.Getter; -@Getter public enum BugTemplateCustomField { /** * 处理人 */ - HANDLE_USER("handleUser", Translator.get("bug.handle_user")), + HANDLE_USER("handleUser", "bug.handle_user"), /** * 状态 */ - STATUS("status", Translator.get("bug.status")); + STATUS("status", "bug.status"); - private final String id; + @Getter + private final String id; private final String name; @@ -24,4 +24,8 @@ public enum BugTemplateCustomField { this.id = id; this.name = name; } + + public String getName(String language) { + return Translator.get(name, language); + } } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java index 0527344140..c3d76b0e4f 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java @@ -252,9 +252,9 @@ public class BugService { * @param id 缺陷ID * @return 缺陷详情 */ - public BugDetailDTO get(String id, String currentUser) { + public BugDetailDTO get(String id, String currentUser, String language) { Bug bug = checkBugExist(id); - TemplateDTO template = getTemplate(bug.getTemplateId(), bug.getProjectId(), null, null, StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName())); + TemplateDTO template = getTemplate(bug.getTemplateId(), bug.getProjectId(), null, null, StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName()), language); List allCustomFields = extBugCustomFieldMapper.getBugAllCustomFields(List.of(id), bug.getProjectId()); BugDetailDTO detail = new BugDetailDTO(); detail.setId(id); @@ -381,21 +381,21 @@ public class BugService { * @param platformBugKey 平台缺陷key * @return 模板详情 */ - public TemplateDTO getTemplate(String templateId, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) { + public TemplateDTO getTemplate(String templateId, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal, String language) { Template template = templateMapper.selectByPrimaryKey(templateId); if (template != null) { // 属于系统模板 - return injectPlatformTemplateBugField(baseTemplateService.getTemplateDTO(template), projectId, fromStatusId, platformBugKey, showLocal); + return injectPlatformTemplateBugField(baseTemplateService.getTemplateDTO(template), projectId, fromStatusId, platformBugKey, showLocal, language); } else { // 不属于系统模板 List option = projectTemplateService.getOption(projectId, TemplateScene.BUG.name()); Optional isThirdPartyDefaultTemplate = option.stream().filter(projectTemplateOptionDTO -> StringUtils.equals(projectTemplateOptionDTO.getId(), templateId)).findFirst(); if (isThirdPartyDefaultTemplate.isPresent()) { // 属于第三方平台默认模板(平台生成的默认模板无需注入配置中的字段) - return attachTemplateStatusField(getPluginBugDefaultTemplate(projectId, true), projectId, fromStatusId, platformBugKey, false); + return attachTemplateStatusField(getPluginBugDefaultTemplate(projectId, true), projectId, fromStatusId, platformBugKey, false, language); } else { // 不属于系统模板&&不属于第三方平台默认模板, 则该模板已被删除 - return injectPlatformTemplateBugField(projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.BUG.name()), projectId, fromStatusId, platformBugKey, showLocal); + return injectPlatformTemplateBugField(projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.BUG.name()), projectId, fromStatusId, platformBugKey, showLocal, language); } } } @@ -883,20 +883,21 @@ public class BugService { * @param platformBugKey 平台缺陷key * @return 模板 */ - private TemplateDTO injectPlatformTemplateBugField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) { + private TemplateDTO injectPlatformTemplateBugField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, + Boolean showLocal, String language) { // 来自平台模板 templateDTO.setPlatformDefault(false); String platformName = projectApplicationService.getPlatformName(projectId); // 状态字段 - attachTemplateStatusField(templateDTO, projectId, fromStatusId, platformBugKey, showLocal); + attachTemplateStatusField(templateDTO, projectId, fromStatusId, platformBugKey, showLocal, language); // 内置字段(处理人字段) if (StringUtils.equals(platformName, BugPlatform.LOCAL.getName()) || BooleanUtils.isTrue(showLocal)) { // Local(处理人) TemplateCustomFieldDTO handleUserField = new TemplateCustomFieldDTO(); handleUserField.setFieldId(BugTemplateCustomField.HANDLE_USER.getId()); - handleUserField.setFieldName(BugTemplateCustomField.HANDLE_USER.getName()); + handleUserField.setFieldName(BugTemplateCustomField.HANDLE_USER.getName(language)); handleUserField.setFieldKey(BugTemplateCustomField.HANDLE_USER.getId()); handleUserField.setType(CustomFieldType.SELECT.name()); handleUserField.setOptions(getMemberOption(projectId)); @@ -952,13 +953,14 @@ public class BugService { * @param platformBugKey 平台缺陷key * @return 模板 */ - public TemplateDTO attachTemplateStatusField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) { + public TemplateDTO attachTemplateStatusField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, + Boolean showLocal, String language) { if (templateDTO == null) { return null; } TemplateCustomFieldDTO statusField = new TemplateCustomFieldDTO(); statusField.setFieldId(BugTemplateCustomField.STATUS.getId()); - statusField.setFieldName(BugTemplateCustomField.STATUS.getName()); + statusField.setFieldName(BugTemplateCustomField.STATUS.getName(language)); statusField.setFieldKey(BugTemplateCustomField.STATUS.getId()); statusField.setType(CustomFieldType.SELECT.name()); List statusOption = bugStatusService.getToStatusItemOption(projectId, fromStatusId, platformBugKey, showLocal); diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index cb310e05a5..a25505c340 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -960,17 +960,19 @@ export interface CascaderOption { /** * 解析级联选择器的值 - * @param value + * @param arr 值 * @param options 级联选项 (默认层级2) */ -export function cascaderValueToLabel(value: string, options: CascaderOption[]) { - if (!value || !options) return ''; +export function cascaderValueToLabel(arr: string[], options: CascaderOption[]) { + if (!arr || !options || arr.length === 0) return ''; let targetLabel = ''; options.forEach((option) => { - if (option.children) { - option.children.forEach((child) => { - if (child.value === value) { - targetLabel = child.text; + if (option.value === arr[0]) { + targetLabel += option.text; + if (arr.length === 1) return; + option.children?.forEach((child) => { + if (child.value === arr[1]) { + targetLabel += `/${child.text}`; } }); } @@ -1009,11 +1011,20 @@ export function customFieldDataToTableData(customFieldData: Record[ .map((val: string) => field.options.find((option: { value: string }) => option.value === val)?.text) .join(','); } catch (e) { - console.log('自定义字段值不是数组'); + // eslint-disable-next-line no-console + console.error('multiple field value is not array!'); + } + } else if (field.type === 'CASCADER' && field.value) { + try { + const arr = JSON.parse(field.value); + if (arr.length > 1) { + // 特殊的三方字段-级联选择器 + tableData[field.id] = cascaderValueToLabel(arr, field.options); + } + } catch (e) { + // eslint-disable-next-line no-console + console.error('cascader field value is nor array!'); } - } else if (field.type === 'CASCADER') { - // 特殊的三方字段-级联选择器 - tableData[field.id] = cascaderValueToLabel(JSON.parse(field.value)[1], field.options); } else { tableData[field.id] = field.value; }