diff --git a/frontend/src/business/components/track/case/components/TestCaseEdit.vue b/frontend/src/business/components/track/case/components/TestCaseEdit.vue index 06ad21e17f..9d454a4ca3 100644 --- a/frontend/src/business/components/track/case/components/TestCaseEdit.vue +++ b/frontend/src/business/components/track/case/components/TestCaseEdit.vue @@ -590,15 +590,17 @@ export default { let customFieldsStr = param.customFields; if (customFieldsStr) { let customFields = JSON.parse(customFieldsStr); - if (customFields['i43sf4_testCasePriority']) { - param.priority = JSON.parse(customFields['i43sf4_testCasePriority']); - } - if (customFields['i43sf4_testCaseMaintainer']) { - param.maintainer = JSON.parse(customFields['i43sf4_testCaseMaintainer']); - } - if (customFields['i43sf4_testCaseStatus']) { - param.status = JSON.parse(customFields['i43sf4_testCaseStatus']); - } + customFields.forEach(item => { + if (item.name === 'i43sf4_testCasePriority') { + param.priority = item.value; + } + if (item.name === 'i43sf4_testCaseMaintainer') { + param.maintainer = item.value; + } + if (item.name === 'i43sf4_testCaseStatus') { + param.status = item.value; + } + }); } }, getOption(param) { diff --git a/frontend/src/common/js/custom_field.js b/frontend/src/common/js/custom_field.js index b6d47373ba..26c6136373 100644 --- a/frontend/src/common/js/custom_field.js +++ b/frontend/src/common/js/custom_field.js @@ -16,9 +16,10 @@ export function parseCustomField(data, template, customFieldForm, rules, oldFiel hasOldData = true; data.customFields = {}; } - if (!(data.customFields instanceof Object)) { + if (!(data.customFields instanceof Object) && !(data.customFields instanceof Array)) { data.customFields = JSON.parse(data.customFields); } + // 设置页面显示的默认值 template.customFields.forEach(item => { if (item.defaultValue) { @@ -46,13 +47,26 @@ export function parseCustomField(data, template, customFieldForm, rules, oldFiel } } - for (const key in data.customFields) { - if (item.name === key) { - if (data.customFields[key]) { - item.defaultValue = JSON.parse(data.customFields[key]); + // 将保存的值赋值给template + if (data.customFields instanceof Array) { + for (const index in data.customFields) { + let customField = data.customFields[index]; + if (customField.id === item.id) { + item.defaultValue = customField.value; + break; + } + } + } else if (data.customFields instanceof Object) { + // 兼容旧的存储方式 + for (const key in data.customFields) { + if (item.name === key) { + if (data.customFields[key]) { + item.defaultValue = JSON.parse(data.customFields[key]); + } } } } + if (customFieldForm) { customFieldForm[item.name] = item.defaultValue; } @@ -62,10 +76,27 @@ export function parseCustomField(data, template, customFieldForm, rules, oldFiel // 将template的属性值设置给customFields export function buildCustomFields(data, param, template) { if (template.customFields) { + if (!(data.customFields instanceof Array)) { + data.customFields = []; + } let customFields = data.customFields; template.customFields.forEach(item => { - if (item.defaultValue) { - customFields[item.name] = JSON.stringify(item.defaultValue); + let hasField = false; + for (const index in customFields) { + if (customFields[index].id === item.id) { + hasField = true; + customFields[index].name = item.name; + customFields[index].value = item.defaultValue; + break; + } + } + if (!hasField) { + let customField = { + id: item.id, + name: item.name, + value: item.defaultValue + }; + customFields.push(customField); } }); param.customFields = JSON.stringify(customFields);