From 6644f2e3f3f919462011d99ceae731dc1f529da1 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 27 Apr 2021 15:55:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=94=A8=E4=BE=8B=E5=92=8C?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E5=AD=98=E5=82=A8=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=9B=B4=E8=AF=A6=E7=BB=86=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/case/components/TestCaseEdit.vue | 20 +++++---- frontend/src/common/js/custom_field.js | 45 ++++++++++++++++--- 2 files changed, 49 insertions(+), 16 deletions(-) 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);