Skip to content

Commit

Permalink
fix: 自定义字段删除枚举值交互优化 (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri0528 authored Jan 22, 2024
1 parent 6b861ed commit 4e32cff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/pages/src/views/setting/FieldSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
:set-type="fieldData.setType"
:current-editor-data="fieldData.currentEditorData"
@submitData="submitData"
@handleCancel="handleCancel"
@updateFields="getFieldsList" />
@handleCancel="handleCancel" />
</bk-sideslider>
</bk-loading>
</template>
Expand Down
41 changes: 28 additions & 13 deletions src/pages/src/views/setting/FieldsAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const emit = defineEmits(['handleCancel', 'submitData', 'updateFields']);
const validate = useValidate();
const fieldsRef = ref();
const enumRef = ref();
let fieldsInfor = reactive(JSON.parse(JSON.stringify({ ...props.currentEditorData })));
const fieldsInfor = reactive(JSON.parse(JSON.stringify({ ...props.currentEditorData })));
const state = reactive({
defaultSelected: 'string',
isDeleteOption: true,
Expand Down Expand Up @@ -372,33 +372,28 @@ const handleEnumValue = (item: any) => {
enumDialog.value.activeId = item.id;
};
const deleteList = ref([]);
// 修改枚举值
const changeEnumValue = async () => {
try {
btnLoading.value = true;
enumLoading.value = true;
const { deleteId, activeId } = enumDialog.value;
fieldsInfor.mapping = { [deleteId]: activeId };
deleteList.value.push({ [deleteId]: activeId });
fieldsInfor.mapping = transformArrayToObject(deleteList.value);
if (fieldsInfor.data_type === 'enum') {
fieldsInfor.default = fieldsInfor.options.some(item => item.id === activeId) ? activeId : fieldsInfor.default;
} else {
const newDefault = fieldsInfor.default.map(index => fieldsInfor.options[index].id);
const newDefault = fieldsInfor.default.map(index => fieldsInfor.options[index]?.id);
if (!newDefault.includes(activeId)) {
newDefault.push(activeId);
}
fieldsInfor.default = newDefault.filter(id => id !== deleteId);
}
fieldsInfor.options = fieldsInfor.options.filter(item => item.id !== deleteId);
await putCustomFields(fieldsInfor);
enumDialog.value.isShow = false;
emit('updateFields');
const fieldsRef = await getFields();
fieldsRef.data.custom_fields.forEach((fields) => {
if (fields.id === fieldsInfor.id) {
fieldsInfor = reactive(fields);
}
});
const findIndexById = id => fieldsInfor.options.findIndex(item => item.id === id);
fieldsInfor.default = fieldsInfor.data_type === 'enum' ? findIndexById(fieldsInfor.default)
Expand All @@ -411,6 +406,26 @@ const changeEnumValue = async () => {
enumLoading.value = false;
}
};
// 将数组转换为对象
const transformArrayToObject = (array) => {
const keyValueMap = {};
array.forEach((obj) => {
for (const [key, value] of Object.entries(obj)) {
keyValueMap[key] = value;
}
});
const result = {};
array.forEach((obj) => {
for (const [key, value] of Object.entries(obj)) {
result[key] = keyValueMap[value] || value;
}
});
return result;
};
// 删除枚举
const deleteEg = (item: any, index: number) => {
if (fieldsInfor.options.length <= 1) {
Expand Down Expand Up @@ -502,7 +517,7 @@ const submitInfor = async () => {
if (fieldsInfor.data_type === 'enum') {
newFieldData.default = newFieldData.default[0] || null;
}
newFieldData.mapping = {};
newFieldData.mapping = fieldsInfor?.mapping || {};
}
const action = isEdit.value ? putCustomFields : newCustomFields;
Expand Down

0 comments on commit 4e32cff

Please sign in to comment.