From 8ab2aa8c29cf41d6700163c1e0f50af3fdbeb59d Mon Sep 17 00:00:00 2001 From: "xinxin.wu" Date: Wed, 11 Sep 2024 16:41:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/assets/style/arco-reset.less | 1 + frontend/src/models/setting/template.ts | 19 +++++- frontend/src/views/bug-management/edit.vue | 62 ++++++++++--------- frontend/src/views/bug-management/utils.ts | 18 ++++++ .../components/caseTemplateDetail.vue | 25 ++------ .../template/components/addTemplate.vue | 2 +- .../template/components/viewTemplate.vue | 2 +- 7 files changed, 78 insertions(+), 51 deletions(-) diff --git a/frontend/src/assets/style/arco-reset.less b/frontend/src/assets/style/arco-reset.less index 27c6c210f0..1266f709d4 100644 --- a/frontend/src/assets/style/arco-reset.less +++ b/frontend/src/assets/style/arco-reset.less @@ -340,6 +340,7 @@ } } .arco-select-view-inner .arco-select-view-tag { + max-width: 144px; border-color: transparent !important; } .arco-select-view-icon svg, diff --git a/frontend/src/models/setting/template.ts b/frontend/src/models/setting/template.ts index ac96bd39a9..29b8deaba8 100644 --- a/frontend/src/models/setting/template.ts +++ b/frontend/src/models/setting/template.ts @@ -103,7 +103,7 @@ export interface CustomField { fieldId: string; required?: boolean; // 是否必填 apiFieldId?: string; // api字段名 - defaultValue?: string | string[] | null | number; // 默认值 + defaultValue: string | (string | number)[] | number; // 默认值 [key: string]: any; } @@ -188,3 +188,20 @@ export interface defaultCaseField { description: string; [key: string]: any; } + +export interface DetailCustomField extends CustomField { + fieldId: string; + fieldName: string; + fieldKey: string; + required: boolean; + type: string; + internal: boolean; + internalFieldKey: string; // 系统字段标识 例如用例等级 + options: FieldOptions[]; + supportSearch?: boolean; + optionMethod?: string; + platformOptionJson?: string; // 三方平台下拉选项 + platformPlaceHolder?: string; + platformSystemField?: any; // 三方平台字段 + apiFieldId?: string; // 三方api +} diff --git a/frontend/src/views/bug-management/edit.vue b/frontend/src/views/bug-management/edit.vue index d2fe10e89a..3c22dd1b11 100644 --- a/frontend/src/views/bug-management/edit.vue +++ b/frontend/src/views/bug-management/edit.vue @@ -230,11 +230,11 @@ import { AssociatedList, AttachFileInfo } from '@/models/caseManagement/featureCase'; import { TableQueryParams } from '@/models/common'; import { SelectValue } from '@/models/projectManagement/menuManagement'; - import type { CustomField } from '@/models/setting/template'; + import type { CustomField, DetailCustomField, FieldOptions } from '@/models/setting/template'; import { CaseLinkEnum } from '@/enums/caseEnum'; import { convertToFile } from '../case-management/caseManagementFeature/components/utils'; - import { convertToFileByBug } from './utils'; + import { convertToFileByBug, getDefaultMemberValue } from './utils'; import { getCaseTemplateContent } from '@/views/case-management/components/addDefectDrawer/utils'; const props = defineProps<{ @@ -356,37 +356,42 @@ transferVisible.value = true; } - // 处理表单格式 - const getFormRules = (arr: BugEditCustomField[]) => { - formRules.value = []; + // 获取模板初始值 + function getInitValue(item: DetailCustomField, initOptions: FieldOptions[]) { const memberType = ['MEMBER', 'MULTIPLE_MEMBER']; const multipleType = ['MULTIPLE_SELECT', 'CHECKBOX']; const numberType = ['INT', 'FLOAT']; + if (isEditOrCopy.value) return null; + const initValue = item.defaultValue; + // 成员类型 + if (memberType.includes(item.type)) { + return getDefaultMemberValue(item, initOptions); + } + // 多选类型 + if (multipleType.includes(item.type)) { + if (Array.isArray(item.defaultValue) && item.defaultValue.length > 0) { + return item.defaultValue; + } + if (typeof item.defaultValue === 'string') { + return JSON.parse(item.defaultValue || '[]'); + } + } + // 数字和浮点格式 + if (numberType.includes(item.type)) { + return Number(initValue); + } + + return initValue; + } + + // 处理表单格式 + const getFormRules = (arr: BugEditCustomField[]) => { + formRules.value = []; if (Array.isArray(arr) && arr.length) { formRules.value = arr.map((item: any) => { - const initOptions = item.options ? item.options : JSON.parse(item.platformOptionJson); - let initValue; - if (!isEditOrCopy.value) { - initValue = item.defaultValue; - if (memberType.includes(item.type)) { - if (item.defaultValue === 'CREATE_USER' || item.defaultValue.includes('CREATE_USER')) { - initValue = item.type === 'MEMBER' ? userStore.id : [userStore.id]; - } else if (item.type === 'MULTIPLE_MEMBER' && item.defaultValue) { - initValue = JSON.parse(item.defaultValue); - } - } else if (multipleType.includes(item.type)) { - if (item.defaultValue && Array.isArray(item.defaultValue) && item.defaultValue.length > 0) { - initValue = item.defaultValue; - } else if (item.defaultValue && typeof item.defaultValue === 'string') { - initValue = item.defaultValue ? JSON.parse(item.defaultValue) : []; - } - } else if (numberType.includes(item.type)) { - initValue = Number(initValue); - } - } else { - initValue = null; - } + const initOptions = item.options || JSON.parse(item.platformOptionJson || '{}'); + const initValue = getInitValue(item, initOptions); return { type: item.type, name: item.fieldId, @@ -439,7 +444,8 @@ } getFormRules(res.customFields.filter((field: Record) => !field.platformSystemField)); // 回显默认系统模板字段 - res.systemFields.forEach((item: CustomField) => { + const systemFieldsDetail = res.systemFields || []; + systemFieldsDetail.forEach((item: CustomField) => { form.value[item.fieldId] = item.defaultValue; }); diff --git a/frontend/src/views/bug-management/utils.ts b/frontend/src/views/bug-management/utils.ts index 5170873127..1ac38fc1f8 100644 --- a/frontend/src/views/bug-management/utils.ts +++ b/frontend/src/views/bug-management/utils.ts @@ -8,10 +8,14 @@ import { FormRuleItem } from '@/components/pure/ms-form-create/types'; import { getFileEnum } from '@/components/pure/ms-upload/iconMap'; import { MsFileItem } from '@/components/pure/ms-upload/types'; +import useUserStore from '@/store/modules/user'; import { findParents, Option } from '@/utils/recursion'; import { BugEditCustomFieldItem } from '@/models/bug-management'; import { AssociatedList } from '@/models/caseManagement/featureCase'; +import type { DetailCustomField, FieldOptions } from '@/models/setting/template'; + +const userStore = useUserStore(); export function convertToFileByBug(fileInfo: AssociatedList): MsFileItem { const gatewayAddress = `${window.location.protocol}//${window.location.hostname}:${window.location.port}`; @@ -91,3 +95,17 @@ export function makeCustomFieldsParams(formItem: FormRuleItem[]) { } return customFields; } + +// 设置成员默认值 +export function getDefaultMemberValue(item: DetailCustomField, initOptions: FieldOptions[]) { + if ((item.defaultValue as string | string[]).includes('CREATE_USER')) { + const optionsIds = initOptions.map((e: any) => e.value); + const userId = userStore.id as string; + if (optionsIds.includes(userId)) { + item.defaultValue = item.type === 'MEMBER' ? userId : [userId]; + } else { + item.defaultValue = item.type === 'MEMBER' ? '' : []; + } + } + return item.defaultValue; +} diff --git a/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue b/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue index b241225312..3ff8f68a22 100644 --- a/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue +++ b/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue @@ -267,7 +267,6 @@ import { useI18n } from '@/hooks/useI18n'; import useAppStore from '@/store/modules/app'; import useFeatureCaseStore from '@/store/modules/case/featureCase'; - import useUserStore from '@/store/modules/user'; import { downloadByteFile, filterTreeNode, getGenerateId } from '@/utils'; import type { @@ -276,15 +275,13 @@ CreateOrUpdateCase, CustomAttributes, DetailCase, - OptionsField, StepList, } from '@/models/caseManagement/featureCase'; import type { ModuleTreeNode, TableQueryParams } from '@/models/common'; - import type { CustomField } from '@/models/setting/template'; + import type { CustomField, FieldOptions } from '@/models/setting/template'; import { convertToFile, initFormCreate } from './utils'; - - const userStore = useUserStore(); + import { getDefaultMemberValue } from '@/views/bug-management/utils'; const { t } = useI18n(); const route = useRoute(); @@ -359,16 +356,6 @@ fileList: [], // 总文件列表 }); - // 获取类型样式 - function getSelectTypeClass(type: string) { - return form.value.caseEditType === type ? ['bg-[rgb(var(--primary-1))]', '!text-[rgb(var(--primary-5))]'] : []; - } - - // 更改类型 - const handleSelectType = (value: string | number | Record | undefined) => { - form.value.caseEditType = value as string; - }; - const isLoading = ref(true); const rowLength = ref(0); @@ -409,11 +396,9 @@ const result = customFields.map((item: any) => { const memberType = ['MEMBER', 'MULTIPLE_MEMBER']; let initValue = item.defaultValue; - const optionsValue: OptionsField[] = item.options; + const optionsValue: FieldOptions[] = item.options; if (memberType.includes(item.type)) { - if (item.defaultValue === 'CREATE_USER' || item.defaultValue.includes('CREATE_USER')) { - initValue = item.type === 'MEMBER' ? userStore.id : [userStore.id]; - } + initValue = getDefaultMemberValue(item, optionsValue); } return { @@ -430,7 +415,7 @@ }; }); formRules.value = result; - setSystemDefault(systemFields); + setSystemDefault(systemFields || []); isLoading.value = false; } catch (error) { // eslint-disable-next-line no-console diff --git a/frontend/src/views/setting/organization/template/components/addTemplate.vue b/frontend/src/views/setting/organization/template/components/addTemplate.vue index 9ee17995eb..708e9431eb 100644 --- a/frontend/src/views/setting/organization/template/components/addTemplate.vue +++ b/frontend/src/views/setting/organization/template/components/addTemplate.vue @@ -686,7 +686,7 @@ templateForm.value.id = undefined; } selectData.value = getSelectData(customFields); - setCaseSystemFormField(systemFields); + setCaseSystemFormField(systemFields || []); } catch (error) { // eslint-disable-next-line no-console console.log(error); diff --git a/frontend/src/views/setting/organization/template/components/viewTemplate.vue b/frontend/src/views/setting/organization/template/components/viewTemplate.vue index bdaa8f971d..5dd4225166 100644 --- a/frontend/src/views/setting/organization/template/components/viewTemplate.vue +++ b/frontend/src/views/setting/organization/template/components/viewTemplate.vue @@ -122,7 +122,7 @@ const defaultBugForm = ref(cloneDeep(initBugField)); function getSystemField() { - props.systemFields.forEach((item: CustomField) => { + (props.systemFields || []).forEach((item: CustomField) => { if (props.templateType === 'BUG') { defaultBugForm.value[item.fieldId] = item.defaultValue; } else {