feat(缺陷管理): 缺陷管理自定义字段优化

This commit is contained in:
xinxin.wu 2024-09-11 16:41:56 +08:00 committed by Craftsman
parent 4452a7ed23
commit 8ab2aa8c29
7 changed files with 78 additions and 51 deletions

View File

@ -340,6 +340,7 @@
} }
} }
.arco-select-view-inner .arco-select-view-tag { .arco-select-view-inner .arco-select-view-tag {
max-width: 144px;
border-color: transparent !important; border-color: transparent !important;
} }
.arco-select-view-icon svg, .arco-select-view-icon svg,

View File

@ -103,7 +103,7 @@ export interface CustomField {
fieldId: string; fieldId: string;
required?: boolean; // 是否必填 required?: boolean; // 是否必填
apiFieldId?: string; // api字段名 apiFieldId?: string; // api字段名
defaultValue?: string | string[] | null | number; // 默认值 defaultValue: string | (string | number)[] | number; // 默认值
[key: string]: any; [key: string]: any;
} }
@ -188,3 +188,20 @@ export interface defaultCaseField {
description: string; description: string;
[key: string]: any; [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
}

View File

@ -230,11 +230,11 @@
import { AssociatedList, AttachFileInfo } from '@/models/caseManagement/featureCase'; import { AssociatedList, AttachFileInfo } from '@/models/caseManagement/featureCase';
import { TableQueryParams } from '@/models/common'; import { TableQueryParams } from '@/models/common';
import { SelectValue } from '@/models/projectManagement/menuManagement'; 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 { CaseLinkEnum } from '@/enums/caseEnum';
import { convertToFile } from '../case-management/caseManagementFeature/components/utils'; 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'; import { getCaseTemplateContent } from '@/views/case-management/components/addDefectDrawer/utils';
const props = defineProps<{ const props = defineProps<{
@ -356,37 +356,42 @@
transferVisible.value = true; transferVisible.value = true;
} }
// //
const getFormRules = (arr: BugEditCustomField[]) => { function getInitValue(item: DetailCustomField, initOptions: FieldOptions[]) {
formRules.value = [];
const memberType = ['MEMBER', 'MULTIPLE_MEMBER']; const memberType = ['MEMBER', 'MULTIPLE_MEMBER'];
const multipleType = ['MULTIPLE_SELECT', 'CHECKBOX']; const multipleType = ['MULTIPLE_SELECT', 'CHECKBOX'];
const numberType = ['INT', 'FLOAT']; 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) { if (Array.isArray(arr) && arr.length) {
formRules.value = arr.map((item: any) => { formRules.value = arr.map((item: any) => {
const initOptions = item.options ? item.options : JSON.parse(item.platformOptionJson); const initOptions = item.options || JSON.parse(item.platformOptionJson || '{}');
let initValue; const initValue = getInitValue(item, initOptions);
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;
}
return { return {
type: item.type, type: item.type,
name: item.fieldId, name: item.fieldId,
@ -439,7 +444,8 @@
} }
getFormRules(res.customFields.filter((field: Record<string, any>) => !field.platformSystemField)); getFormRules(res.customFields.filter((field: Record<string, any>) => !field.platformSystemField));
// //
res.systemFields.forEach((item: CustomField) => { const systemFieldsDetail = res.systemFields || [];
systemFieldsDetail.forEach((item: CustomField) => {
form.value[item.fieldId] = item.defaultValue; form.value[item.fieldId] = item.defaultValue;
}); });

View File

@ -8,10 +8,14 @@ import { FormRuleItem } from '@/components/pure/ms-form-create/types';
import { getFileEnum } from '@/components/pure/ms-upload/iconMap'; import { getFileEnum } from '@/components/pure/ms-upload/iconMap';
import { MsFileItem } from '@/components/pure/ms-upload/types'; import { MsFileItem } from '@/components/pure/ms-upload/types';
import useUserStore from '@/store/modules/user';
import { findParents, Option } from '@/utils/recursion'; import { findParents, Option } from '@/utils/recursion';
import { BugEditCustomFieldItem } from '@/models/bug-management'; import { BugEditCustomFieldItem } from '@/models/bug-management';
import { AssociatedList } from '@/models/caseManagement/featureCase'; import { AssociatedList } from '@/models/caseManagement/featureCase';
import type { DetailCustomField, FieldOptions } from '@/models/setting/template';
const userStore = useUserStore();
export function convertToFileByBug(fileInfo: AssociatedList): MsFileItem { export function convertToFileByBug(fileInfo: AssociatedList): MsFileItem {
const gatewayAddress = `${window.location.protocol}//${window.location.hostname}:${window.location.port}`; const gatewayAddress = `${window.location.protocol}//${window.location.hostname}:${window.location.port}`;
@ -91,3 +95,17 @@ export function makeCustomFieldsParams(formItem: FormRuleItem[]) {
} }
return customFields; 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;
}

View File

@ -267,7 +267,6 @@
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app'; import useAppStore from '@/store/modules/app';
import useFeatureCaseStore from '@/store/modules/case/featureCase'; import useFeatureCaseStore from '@/store/modules/case/featureCase';
import useUserStore from '@/store/modules/user';
import { downloadByteFile, filterTreeNode, getGenerateId } from '@/utils'; import { downloadByteFile, filterTreeNode, getGenerateId } from '@/utils';
import type { import type {
@ -276,15 +275,13 @@
CreateOrUpdateCase, CreateOrUpdateCase,
CustomAttributes, CustomAttributes,
DetailCase, DetailCase,
OptionsField,
StepList, StepList,
} from '@/models/caseManagement/featureCase'; } from '@/models/caseManagement/featureCase';
import type { ModuleTreeNode, TableQueryParams } from '@/models/common'; 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'; import { convertToFile, initFormCreate } from './utils';
import { getDefaultMemberValue } from '@/views/bug-management/utils';
const userStore = useUserStore();
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
@ -359,16 +356,6 @@
fileList: [], // 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<string, any> | undefined) => {
form.value.caseEditType = value as string;
};
const isLoading = ref<boolean>(true); const isLoading = ref<boolean>(true);
const rowLength = ref<number>(0); const rowLength = ref<number>(0);
@ -409,11 +396,9 @@
const result = customFields.map((item: any) => { const result = customFields.map((item: any) => {
const memberType = ['MEMBER', 'MULTIPLE_MEMBER']; const memberType = ['MEMBER', 'MULTIPLE_MEMBER'];
let initValue = item.defaultValue; let initValue = item.defaultValue;
const optionsValue: OptionsField[] = item.options; const optionsValue: FieldOptions[] = item.options;
if (memberType.includes(item.type)) { if (memberType.includes(item.type)) {
if (item.defaultValue === 'CREATE_USER' || item.defaultValue.includes('CREATE_USER')) { initValue = getDefaultMemberValue(item, optionsValue);
initValue = item.type === 'MEMBER' ? userStore.id : [userStore.id];
}
} }
return { return {
@ -430,7 +415,7 @@
}; };
}); });
formRules.value = result; formRules.value = result;
setSystemDefault(systemFields); setSystemDefault(systemFields || []);
isLoading.value = false; isLoading.value = false;
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

View File

@ -686,7 +686,7 @@
templateForm.value.id = undefined; templateForm.value.id = undefined;
} }
selectData.value = getSelectData(customFields); selectData.value = getSelectData(customFields);
setCaseSystemFormField(systemFields); setCaseSystemFormField(systemFields || []);
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);

View File

@ -122,7 +122,7 @@
const defaultBugForm = ref<defaultBugField>(cloneDeep(initBugField)); const defaultBugForm = ref<defaultBugField>(cloneDeep(initBugField));
function getSystemField() { function getSystemField() {
props.systemFields.forEach((item: CustomField) => { (props.systemFields || []).forEach((item: CustomField) => {
if (props.templateType === 'BUG') { if (props.templateType === 'BUG') {
defaultBugForm.value[item.fieldId] = item.defaultValue; defaultBugForm.value[item.fieldId] = item.defaultValue;
} else { } else {