Skip to content

Commit

Permalink
fix(projects): fix manage page drawer operate about data reset. fixed #…
Browse files Browse the repository at this point in the history
…415, fixed #417
  • Loading branch information
honghuangdc committed May 4, 2024
1 parent 734ef98 commit f4513e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/hooks/common/table.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -186,7 +187,8 @@ export function useTableOperate<T extends TableData = TableData>(data: Ref<T[]>,

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();
}
Expand Down
16 changes: 7 additions & 9 deletions src/views/manage/menu/modules/menu-operate-drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -175,7 +173,7 @@ async function handleSubmit() {
watch(visible, () => {
if (visible.value) {
handleUpdateModel();
handleInitModel();
restoreValidation();
}
});
Expand Down
9 changes: 3 additions & 6 deletions src/views/manage/role/modules/role-operate-drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -93,7 +90,7 @@ async function handleSubmit() {
watch(visible, () => {
if (visible.value) {
handleUpdateModelWhenEdit();
handleInitModel();
restoreValidation();
}
});
Expand Down
9 changes: 3 additions & 6 deletions src/views/manage/user/modules/user-operate-drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -114,7 +111,7 @@ async function handleSubmit() {
watch(visible, () => {
if (visible.value) {
handleUpdateModelWhenEdit();
handleInitModel();
restoreValidation();
getRoleOptions();
}
Expand Down

0 comments on commit f4513e1

Please sign in to comment.