This commit is contained in:
parent
734ef9852c
commit
f4513e1e38
@ -1,6 +1,7 @@
|
|||||||
import { computed, effectScope, onScopeDispose, reactive, ref, watch } from 'vue';
|
import { computed, effectScope, onScopeDispose, reactive, ref, watch } from 'vue';
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import type { PaginationProps } from 'naive-ui';
|
import type { PaginationProps } from 'naive-ui';
|
||||||
|
import { cloneDeep } from 'lodash-es';
|
||||||
import { useBoolean, useHookTable } from '@sa/hooks';
|
import { useBoolean, useHookTable } from '@sa/hooks';
|
||||||
import { useAppStore } from '@/store/modules/app';
|
import { useAppStore } from '@/store/modules/app';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
@ -186,7 +187,8 @@ export function useTableOperate<T extends TableData = TableData>(data: Ref<T[]>,
|
|||||||
|
|
||||||
function handleEdit(id: T['id']) {
|
function handleEdit(id: T['id']) {
|
||||||
operateType.value = 'edit';
|
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();
|
openDrawer();
|
||||||
}
|
}
|
||||||
|
@ -136,20 +136,18 @@ const layoutOptions: CommonType.Option[] = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
function handleUpdateModel() {
|
function handleInitModel() {
|
||||||
if (props.operateType === 'add') {
|
Object.assign(model, createDefaultModel());
|
||||||
Object.assign(model, createDefaultModel());
|
|
||||||
|
|
||||||
return;
|
if (!props.rowData) return;
|
||||||
}
|
|
||||||
|
|
||||||
if (props.operateType === 'addChild' && props.rowData) {
|
if (props.operateType === 'addChild') {
|
||||||
const { id } = props.rowData;
|
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 { component, ...rest } = props.rowData;
|
||||||
|
|
||||||
const { layout, page } = getLayoutAndPage(component);
|
const { layout, page } = getLayoutAndPage(component);
|
||||||
@ -175,7 +173,7 @@ async function handleSubmit() {
|
|||||||
|
|
||||||
watch(visible, () => {
|
watch(visible, () => {
|
||||||
if (visible.value) {
|
if (visible.value) {
|
||||||
handleUpdateModel();
|
handleInitModel();
|
||||||
restoreValidation();
|
restoreValidation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -68,11 +68,8 @@ const roleId = computed(() => props.rowData?.id || -1);
|
|||||||
|
|
||||||
const isEdit = computed(() => props.operateType === 'edit');
|
const isEdit = computed(() => props.operateType === 'edit');
|
||||||
|
|
||||||
function handleUpdateModelWhenEdit() {
|
function handleInitModel() {
|
||||||
if (props.operateType === 'add') {
|
Object.assign(model, createDefaultModel());
|
||||||
Object.assign(model, createDefaultModel());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' && props.rowData) {
|
||||||
Object.assign(model, props.rowData);
|
Object.assign(model, props.rowData);
|
||||||
@ -93,7 +90,7 @@ async function handleSubmit() {
|
|||||||
|
|
||||||
watch(visible, () => {
|
watch(visible, () => {
|
||||||
if (visible.value) {
|
if (visible.value) {
|
||||||
handleUpdateModelWhenEdit();
|
handleInitModel();
|
||||||
restoreValidation();
|
restoreValidation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -89,11 +89,8 @@ async function getRoleOptions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpdateModelWhenEdit() {
|
function handleInitModel() {
|
||||||
if (props.operateType === 'add') {
|
Object.assign(model, createDefaultModel());
|
||||||
Object.assign(model, createDefaultModel());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' && props.rowData) {
|
||||||
Object.assign(model, props.rowData);
|
Object.assign(model, props.rowData);
|
||||||
@ -114,7 +111,7 @@ async function handleSubmit() {
|
|||||||
|
|
||||||
watch(visible, () => {
|
watch(visible, () => {
|
||||||
if (visible.value) {
|
if (visible.value) {
|
||||||
handleUpdateModelWhenEdit();
|
handleInitModel();
|
||||||
restoreValidation();
|
restoreValidation();
|
||||||
getRoleOptions();
|
getRoleOptions();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user