From f4513e1e387909cb33a2a0205c87308f89f16a51 Mon Sep 17 00:00:00 2001 From: Soybean Date: Sun, 5 May 2024 00:41:50 +0800 Subject: [PATCH] fix(projects): fix manage page drawer operate about data reset. fixed #415, fixed #417 --- src/hooks/common/table.ts | 4 +++- .../manage/menu/modules/menu-operate-drawer.vue | 16 +++++++--------- .../manage/role/modules/role-operate-drawer.vue | 9 +++------ .../manage/user/modules/user-operate-drawer.vue | 9 +++------ 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/hooks/common/table.ts b/src/hooks/common/table.ts index c83bbbceb..05ddb71f1 100644 --- a/src/hooks/common/table.ts +++ b/src/hooks/common/table.ts @@ -1,6 +1,7 @@ import { computed, effectScope, onScopeDispose, reactive, ref, watch } from 'vue'; import type { Ref } from 'vue'; import type { PaginationProps } from 'naive-ui'; +import { cloneDeep } from 'lodash-es'; import { useBoolean, useHookTable } from '@sa/hooks'; import { useAppStore } from '@/store/modules/app'; import { $t } from '@/locales'; @@ -186,7 +187,8 @@ export function useTableOperate(data: Ref, function handleEdit(id: T['id']) { operateType.value = 'edit'; - editingData.value = data.value.find(item => item.id === id) || null; + const findItem = data.value.find(item => item.id === id) || null; + editingData.value = cloneDeep(findItem); openDrawer(); } diff --git a/src/views/manage/menu/modules/menu-operate-drawer.vue b/src/views/manage/menu/modules/menu-operate-drawer.vue index 795f264aa..e7526ab50 100644 --- a/src/views/manage/menu/modules/menu-operate-drawer.vue +++ b/src/views/manage/menu/modules/menu-operate-drawer.vue @@ -136,20 +136,18 @@ const layoutOptions: CommonType.Option[] = [ } ]; -function handleUpdateModel() { - if (props.operateType === 'add') { - Object.assign(model, createDefaultModel()); +function handleInitModel() { + Object.assign(model, createDefaultModel()); - return; - } + if (!props.rowData) return; - if (props.operateType === 'addChild' && props.rowData) { + if (props.operateType === 'addChild') { const { id } = props.rowData; - Object.assign(model, createDefaultModel(), { parentId: id }); + Object.assign(model, { parentId: id }); } - if (props.operateType === 'edit' && props.rowData) { + if (props.operateType === 'edit') { const { component, ...rest } = props.rowData; const { layout, page } = getLayoutAndPage(component); @@ -175,7 +173,7 @@ async function handleSubmit() { watch(visible, () => { if (visible.value) { - handleUpdateModel(); + handleInitModel(); restoreValidation(); } }); diff --git a/src/views/manage/role/modules/role-operate-drawer.vue b/src/views/manage/role/modules/role-operate-drawer.vue index 48c8e099e..41c8ef11f 100644 --- a/src/views/manage/role/modules/role-operate-drawer.vue +++ b/src/views/manage/role/modules/role-operate-drawer.vue @@ -68,11 +68,8 @@ const roleId = computed(() => props.rowData?.id || -1); const isEdit = computed(() => props.operateType === 'edit'); -function handleUpdateModelWhenEdit() { - if (props.operateType === 'add') { - Object.assign(model, createDefaultModel()); - return; - } +function handleInitModel() { + Object.assign(model, createDefaultModel()); if (props.operateType === 'edit' && props.rowData) { Object.assign(model, props.rowData); @@ -93,7 +90,7 @@ async function handleSubmit() { watch(visible, () => { if (visible.value) { - handleUpdateModelWhenEdit(); + handleInitModel(); restoreValidation(); } }); diff --git a/src/views/manage/user/modules/user-operate-drawer.vue b/src/views/manage/user/modules/user-operate-drawer.vue index 546b142e7..20d3683a8 100644 --- a/src/views/manage/user/modules/user-operate-drawer.vue +++ b/src/views/manage/user/modules/user-operate-drawer.vue @@ -89,11 +89,8 @@ async function getRoleOptions() { } } -function handleUpdateModelWhenEdit() { - if (props.operateType === 'add') { - Object.assign(model, createDefaultModel()); - return; - } +function handleInitModel() { + Object.assign(model, createDefaultModel()); if (props.operateType === 'edit' && props.rowData) { Object.assign(model, props.rowData); @@ -114,7 +111,7 @@ async function handleSubmit() { watch(visible, () => { if (visible.value) { - handleUpdateModelWhenEdit(); + handleInitModel(); restoreValidation(); getRoleOptions(); }