refactor: 用例和缺陷存储自定义字段更详细信息

This commit is contained in:
chenjianxing 2021-04-27 15:55:07 +08:00 committed by jianxing
parent 2a9cec1461
commit 6644f2e3f3
2 changed files with 49 additions and 16 deletions

View File

@ -590,15 +590,17 @@ export default {
let customFieldsStr = param.customFields; let customFieldsStr = param.customFields;
if (customFieldsStr) { if (customFieldsStr) {
let customFields = JSON.parse(customFieldsStr); let customFields = JSON.parse(customFieldsStr);
if (customFields['i43sf4_testCasePriority']) { customFields.forEach(item => {
param.priority = JSON.parse(customFields['i43sf4_testCasePriority']); if (item.name === 'i43sf4_testCasePriority') {
} param.priority = item.value;
if (customFields['i43sf4_testCaseMaintainer']) { }
param.maintainer = JSON.parse(customFields['i43sf4_testCaseMaintainer']); if (item.name === 'i43sf4_testCaseMaintainer') {
} param.maintainer = item.value;
if (customFields['i43sf4_testCaseStatus']) { }
param.status = JSON.parse(customFields['i43sf4_testCaseStatus']); if (item.name === 'i43sf4_testCaseStatus') {
} param.status = item.value;
}
});
} }
}, },
getOption(param) { getOption(param) {

View File

@ -16,9 +16,10 @@ export function parseCustomField(data, template, customFieldForm, rules, oldFiel
hasOldData = true; hasOldData = true;
data.customFields = {}; data.customFields = {};
} }
if (!(data.customFields instanceof Object)) { if (!(data.customFields instanceof Object) && !(data.customFields instanceof Array)) {
data.customFields = JSON.parse(data.customFields); data.customFields = JSON.parse(data.customFields);
} }
// 设置页面显示的默认值 // 设置页面显示的默认值
template.customFields.forEach(item => { template.customFields.forEach(item => {
if (item.defaultValue) { if (item.defaultValue) {
@ -46,13 +47,26 @@ export function parseCustomField(data, template, customFieldForm, rules, oldFiel
} }
} }
for (const key in data.customFields) { // 将保存的值赋值给template
if (item.name === key) { if (data.customFields instanceof Array) {
if (data.customFields[key]) { for (const index in data.customFields) {
item.defaultValue = JSON.parse(data.customFields[key]); 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) { if (customFieldForm) {
customFieldForm[item.name] = item.defaultValue; customFieldForm[item.name] = item.defaultValue;
} }
@ -62,10 +76,27 @@ export function parseCustomField(data, template, customFieldForm, rules, oldFiel
// 将template的属性值设置给customFields // 将template的属性值设置给customFields
export function buildCustomFields(data, param, template) { export function buildCustomFields(data, param, template) {
if (template.customFields) { if (template.customFields) {
if (!(data.customFields instanceof Array)) {
data.customFields = [];
}
let customFields = data.customFields; let customFields = data.customFields;
template.customFields.forEach(item => { template.customFields.forEach(item => {
if (item.defaultValue) { let hasField = false;
customFields[item.name] = JSON.stringify(item.defaultValue); 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); param.customFields = JSON.stringify(customFields);