This commit is contained in:
parent
734ef9852c
commit
f4513e1e38
@ -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<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();
|
||||
}
|
||||
|
@ -136,20 +136,18 @@ const layoutOptions: CommonType.Option[] = [
|
||||
}
|
||||
];
|
||||
|
||||
function handleUpdateModel() {
|
||||
if (props.operateType === 'add') {
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
@ -68,11 +68,8 @@ const roleId = computed(() => props.rowData?.id || -1);
|
||||
|
||||
const isEdit = computed(() => props.operateType === 'edit');
|
||||
|
||||
function handleUpdateModelWhenEdit() {
|
||||
if (props.operateType === 'add') {
|
||||
function handleInitModel() {
|
||||
Object.assign(model, createDefaultModel());
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
@ -89,11 +89,8 @@ async function getRoleOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
function handleUpdateModelWhenEdit() {
|
||||
if (props.operateType === 'add') {
|
||||
function handleInitModel() {
|
||||
Object.assign(model, createDefaultModel());
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user