refactor(测试跟踪): 多选自定义字段支持远程检索

--bug=1026196 --user=陈建星 jira 经办人,报告人,自定义用户字段,支持远程检索 https://www.tapd.cn/55049933/s/1371812
This commit is contained in:
chenjianxing 2023-05-16 13:48:11 +08:00 committed by jianxing
parent 08096bf044
commit 31dc592f7c
10 changed files with 123 additions and 23 deletions

View File

@ -13,9 +13,14 @@
:filter-method="data.inputSearch ? handleSelectInput : null"
:remote="data.inputSearch"
:placeholder="$t('commons.default')">
<template v-solt:prefix>
<span v-if="data.inputSearch" class="input-search-tip">
{{ $t("custom_field.remote_search_tip") }}
</span>
</template>
<el-option
v-for="(item,index) in data.options ? data.options : []"
:key="index"
v-for="(item) in data.options ? data.options : []"
:key="item.value"
@change="handleChange"
:label="getTranslateOption(item)"
:value="item.value">
@ -224,23 +229,50 @@ export default {
this.$emit('change', this.data.name);
this.$forceUpdate();
if (this.data.inputSearch) {
// jira sprint
let selectOption = this.data.options.find(item => item.value === this.data[this.prop]);
if (selectOption) {
this.data.optionLabel = OPTION_LABEL_PREFIX + selectOption.text;
// optionLabel
if (this.data[this.prop] instanceof Array) {
//
try {
let optionLabel = this.data.optionLabel;
let optionLabelMap;
if (optionLabel && this.data.optionLabel.startsWith(OPTION_LABEL_PREFIX)) {
optionLabel = this.data.optionLabel.substring(OPTION_LABEL_PREFIX.length);
optionLabelMap = JSON.parse(optionLabel);
}
if (!optionLabelMap) {
optionLabelMap = {};
}
this.data[this.prop].forEach((val) => {
let selectOption = this.data.options.find(item => item.value === val);
if (selectOption) {
optionLabelMap[val] = selectOption.text;
}
});
this.data.optionLabel = OPTION_LABEL_PREFIX + JSON.stringify(optionLabelMap);
} catch (e) {
console.error("set optionLabel error ", e);
}
} else {
//
let selectOption = this.data.options.find(item => item.value === this.data[this.prop]);
if (selectOption) {
this.data.optionLabel = OPTION_LABEL_PREFIX + selectOption.text;
}
}
}
},
handleSelectInput(val) {
this.loading = true;
if (!this.originOptions) {
this.originOptions = this.data.options;
}
if (!val) {
if (val) {
this.loading = true;
this.$emit('inputSearch', this.data, val);
} else {
//
this.$forceUpdate();
this.data.options = this.originOptions;
}
this.$emit('inputSearch', this.data, val);
},
handleClear() {
if (this.originOptions && this.data.inputSearch) {
@ -276,4 +308,9 @@ export default {
:deep( .el-input--suffix .el-input__inner) {
height: 32px;
}
.input-search-tip {
padding-left: 15px;
color: #C0C4CC;
}
</style>

View File

@ -672,6 +672,7 @@ const message = {
"Note: The system will automatically synchronize at 00:00:00 every day",
case_priority_option_check_error:
"Use case levels need to add option values in order, for example: P",
remote_search_tip: "Enter a user name to search users for you"
},
workspace: {
id: "Workspace ID",

View File

@ -658,6 +658,7 @@ const message = {
option_value_check: "请填写完整选项值",
sync_issue_tips: "注: 系统在每天00:00:00会自动同步一次",
case_priority_option_check_error: "用例等级需按照顺序添加选项值, 例: P",
remote_search_tip: "输入用户名,系统会提供更多匹配的用户列表供您选择"
},
workspace: {
id: "工作空间ID",

View File

@ -657,6 +657,7 @@ const message = {
option_value_check: "請填寫完整選項值",
sync_issue_tips: "注系統在每天00:00:00會自動同步一次",
case_priority_option_check_error: "用例等級需按照順序添加選項值, 例: P",
remote_search_tip: "輸入用戶名,系統會提供更多匹配的用戶列表供您選擇"
},
workspace: {
id: "工作空間ID",

View File

@ -85,15 +85,7 @@ export function parseCustomField(data, template, rules, oldFields) {
} else {
setDefaultValue(item, customField.value);
}
if (customField.textValue && customField.textValue.startsWith(OPTION_LABEL_PREFIX)) {
// 处理 jira 的 sprint 字段,没有选项,则添加对应选项
if (item.options && item.options.filter(i => i.value === customField.value).length < 1) {
item.options.push({
'text': customField.textValue.substring(OPTION_LABEL_PREFIX.length),
'value': customField.value
});
}
}
parseCustomFieldOptionLabel(customField, item);
item.isEdit = true;
} catch (e) {
console.error("JSON parse custom field value error.", e);
@ -119,6 +111,44 @@ export function parseCustomField(data, template, rules, oldFields) {
return customFieldForm;
}
export function isMultipleField(type) {
if (type.startsWith('multiple') || type === 'checkbox') {
return true;
}
return false;
}
export function parseCustomFieldOptionLabel(customField, item) {
if (customField.textValue && customField.textValue.startsWith(OPTION_LABEL_PREFIX)) {
// 处理 jira 的远程搜索字段,没有选项,则添加对应选项
let optionLabel = customField.textValue.substring(OPTION_LABEL_PREFIX.length);
if (customField.value instanceof Array) {
// 多选
try {
if (optionLabel) {
let optionLabelMap = JSON.parse(optionLabel);
customField.value.forEach((val) => {
if (item.options && item.options.filter(i => i.value === val).length < 1) {
item.options.push({
'text': optionLabelMap[val],
'value': val
});
}
});
}
} catch (e) {
console.error("parseCustomFieldOptionLabel error ", e);
}
} else if (item.options && item.options.filter(i => i.value === customField.value).length < 1) {
// 单选
item.options.push({
'text': optionLabel,
'value': customField.value
});
}
}
}
// 将template的属性值设置给customFields
export function buildCustomFields(data, param, template) {
if (template.customFields) {

View File

@ -535,13 +535,37 @@ export function getCustomFieldValue(row, field, members) {
for (let i = 0; i < row.fields.length; i++) {
let item = row.fields[i];
if (item.id === field.id) {
if (item.textValue && item.textValue.startsWith(OPTION_LABEL_PREFIX)) {
// 处理 jira 的 sprint 字段
if (field.options && field.options.filter(i => i.value === item.value).length < 1) {
if (!item.value) return '';
if (item.textValue && item.textValue.startsWith(OPTION_LABEL_PREFIX) && field.options) {
// 处理 jira 远程搜索字段
if (item.value instanceof Array) {
// 多选
try {
let optionLabel = item.textValue.substring(OPTION_LABEL_PREFIX.length);
if (optionLabel) {
let optionLabelMap = JSON.parse(optionLabel);
let label = '';
for (let j = 0; j < item.value.length; j++) {
let val = item.value[j];
let option = field.options.find(i => i.value === val);
if (option) {
label += option.text + (j === item.value.length - 1 ? '' : ' , ');
} else {
label += optionLabelMap[val] + (j === item.value.length - 1 ? '' : ' , ');
}
}
return label;
}
} catch (e) {
console.error("getCustomFieldValue error ", e);
}
} else if (field.options.filter(i => i.value === item.value).length < 1) {
// 单选
return item.textValue.substring(OPTION_LABEL_PREFIX.length);
}
}
if (!item.value) return '';
if (field.type === 'member') {
for (let j = 0; j < members.length; j++) {
let member = members[j];

View File

@ -8,5 +8,6 @@ import lombok.Setter;
public class PlatformOptionRequest extends IntegrationRequest {
private String optionMethod;
private String projectConfig;
private String projectId;
private String query;
}

View File

@ -38,6 +38,8 @@ public class PlatformPluginService {
private BasePluginService basePluginService;
@Resource
private BaseIntegrationService baseIntegrationService;
@Resource
private BaseProjectService baseProjectService;
public static final String PLUGIN_DOWNLOAD_URL = "https://github.com/metersphere/metersphere-platform-plugin";
@ -156,7 +158,8 @@ public class PlatformPluginService {
Platform platform = getPlatform(request.getPlatform(), request.getWorkspaceId());
GetOptionRequest getOptionRequest = new GetOptionRequest();
getOptionRequest.setOptionMethod(request.getOptionMethod());
getOptionRequest.setProjectConfig(request.getProjectConfig());
String projectConfig = getCompatibleProjectConfig(baseProjectService.getProjectById(request.getProjectId()));
getOptionRequest.setProjectConfig(projectConfig);
getOptionRequest.setQuery(request.getQuery());
try {
return platform.getFormOptions(getOptionRequest);

View File

@ -459,6 +459,7 @@ export default {
optionMethod: data.optionMethod,
workspaceId: getCurrentWorkspaceId(),
platform: this.issueTemplate.platform,
projectId: this.form.projectId,
query
}).then((r) => {
data.options = r.data;

View File

@ -748,6 +748,7 @@ export default {
optionMethod: data.optionMethod,
workspaceId: getCurrentWorkspaceId(),
platform: this.issueTemplate.platform,
projectId: this.form.projectId,
query
}).then((r) => {
data.options = r.data;