From 4e32cffacddb8f72842b3c67951ffff214ff91e0 Mon Sep 17 00:00:00 2001 From: yuri0528 <72436066+yuri0528@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:07:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=88=A0=E9=99=A4=E6=9E=9A=E4=B8=BE=E5=80=BC=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E4=BC=98=E5=8C=96=20(#1530)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/src/views/setting/FieldSetting.vue | 3 +- src/pages/src/views/setting/FieldsAdd.vue | 41 +++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/pages/src/views/setting/FieldSetting.vue b/src/pages/src/views/setting/FieldSetting.vue index f03bea196..6fa50de26 100644 --- a/src/pages/src/views/setting/FieldSetting.vue +++ b/src/pages/src/views/setting/FieldSetting.vue @@ -84,8 +84,7 @@ :set-type="fieldData.setType" :current-editor-data="fieldData.currentEditorData" @submitData="submitData" - @handleCancel="handleCancel" - @updateFields="getFieldsList" /> + @handleCancel="handleCancel" /> diff --git a/src/pages/src/views/setting/FieldsAdd.vue b/src/pages/src/views/setting/FieldsAdd.vue index b95ddfe8f..8c21681c0 100644 --- a/src/pages/src/views/setting/FieldsAdd.vue +++ b/src/pages/src/views/setting/FieldsAdd.vue @@ -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, @@ -372,16 +372,20 @@ 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); } @@ -389,16 +393,7 @@ const changeEnumValue = async () => { } 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) @@ -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) { @@ -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;