feat(缺陷管理): 缺陷管理自定义字段优化
This commit is contained in:
parent
4452a7ed23
commit
8ab2aa8c29
|
@ -340,6 +340,7 @@
|
|||
}
|
||||
}
|
||||
.arco-select-view-inner .arco-select-view-tag {
|
||||
max-width: 144px;
|
||||
border-color: transparent !important;
|
||||
}
|
||||
.arco-select-view-icon svg,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<string, any>) => !field.platformSystemField));
|
||||
// 回显默认系统模板字段
|
||||
res.systemFields.forEach((item: CustomField) => {
|
||||
const systemFieldsDetail = res.systemFields || [];
|
||||
systemFieldsDetail.forEach((item: CustomField) => {
|
||||
form.value[item.fieldId] = item.defaultValue;
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<string, any> | undefined) => {
|
||||
form.value.caseEditType = value as string;
|
||||
};
|
||||
|
||||
const isLoading = ref<boolean>(true);
|
||||
|
||||
const rowLength = ref<number>(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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
const defaultBugForm = ref<defaultBugField>(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 {
|
||||
|
|
Loading…
Reference in New Issue