fix(测试跟踪): 功能用例导入多选输入自定义字段后,数据无法显示

--bug=1020905 --user=陈建星 【测试跟踪】导入带自定义字段的用例后列表中不显示,但是左侧模块树中有统计 https://www.tapd.cn/55049933/s/1316327
This commit is contained in:
chenjianxing 2022-12-16 14:45:22 +08:00 committed by jianxing
parent 4186917f83
commit 9fffef10fd
3 changed files with 35 additions and 11 deletions

View File

@ -541,9 +541,11 @@ export function getCustomFieldValue(row, field, members) {
return val; return val;
} else if (field.type === 'multipleInput') { } else if (field.type === 'multipleInput') {
let val = ''; let val = '';
if (item.value instanceof Array) {
item.value.forEach(i => { item.value.forEach(i => {
val += i + ' '; val += i + ' ';
}); });
}
return val; return val;
} else if (field.type === 'datetime' || field.type === 'date') { } else if (field.type === 'datetime' || field.type === 'date') {
return datetimeFormat(item.value); return datetimeFormat(item.value);

View File

@ -52,11 +52,21 @@ public abstract class AbstractCustomFieldValidator {
try { try {
// [a, b] => ["a","b"] // [a, b] => ["a","b"]
if (!StringUtils.equals(value, "[]")) { if (!StringUtils.equals(value, "[]")) {
value = value.replace("[", "[\"") if (!value.contains("[\"")) {
.replace("]", "\"]") value = value.replace("[", "[\"");
.replace(",", "\",\"") }
.replace("", "\"\"") if (!value.contains("\"]")) {
.replace(StringUtils.SPACE, StringUtils.EMPTY); value = value.replace("]", "\"]");
}
if (!value.contains("\",\"")) {
value = value.replace(",", "\",\"");
}
if (!value.contains("\"\"")) {
value = value.replace("", "\"\"");
}
value = value.replace(StringUtils.SPACE, StringUtils.EMPTY);
} }
return JSON.parseArray(value, String.class); return JSON.parseArray(value, String.class);
} catch (Exception e) { } catch (Exception e) {

View File

@ -1,21 +1,33 @@
package io.metersphere.validate; package io.metersphere.validate;
import io.metersphere.commons.utils.JSON;
import io.metersphere.exception.CustomFieldValidateException;
import io.metersphere.dto.CustomFieldDao; import io.metersphere.dto.CustomFieldDao;
import io.metersphere.exception.CustomFieldValidateException;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class CustomFieldMultipleTextValidator extends AbstractCustomFieldValidator { public class CustomFieldMultipleTextValidator extends AbstractCustomFieldValidator {
public CustomFieldMultipleTextValidator() {
this.isKVOption = true;
}
@Override
public void validate(CustomFieldDao customField, String value) throws CustomFieldValidateException { public void validate(CustomFieldDao customField, String value) throws CustomFieldValidateException {
validateRequired(customField, value); validateRequired(customField, value);
if (StringUtils.isNotBlank(value)) { if (StringUtils.isNotBlank(value)) {
try { try {
JSON.parseArray(value); parse2Array(customField.getName(), value);
} catch (Exception e) { } catch (Exception e) {
CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_array_tip"), customField.getName())); CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_array_tip"), customField.getName()));
} }
} }
} }
@Override
public Object parse2Key(String keyOrValuesStr, CustomFieldDao customField) {
if (StringUtils.isBlank(keyOrValuesStr)) {
return StringUtils.EMPTY;
}
return parse2Array(keyOrValuesStr);
}
} }