perf: 更新写法

This commit is contained in:
dap
2024-09-25 14:46:02 +08:00
parent 27e976c40d
commit b68d746fdd
14 changed files with 84 additions and 133 deletions

View File

@@ -3,7 +3,12 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { addFullName, getPopupContainer, listToTree } from '@vben/utils';
import {
addFullName,
cloneDeep,
getPopupContainer,
listToTree,
} from '@vben/utils';
import { useVbenForm } from '#/adapter';
import { menuAdd, menuInfo, menuList, menuUpdate } from '#/api/system/menu';
@@ -12,11 +17,6 @@ import { drawerSchema } from './data';
const emit = defineEmits<{ reload: [] }>();
interface DrawerProps {
update: boolean;
id?: number | string;
}
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -81,15 +81,13 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
return null;
}
drawerApi.drawerLoading(true);
const { id, update } = drawerApi.getData() as DrawerProps;
isUpdate.value = update;
const { id } = drawerApi.getData() as { id?: number | string };
isUpdate.value = !!id;
// 加载菜单树选择
await setupMenuSelect();
if (update && id) {
if (isUpdate.value && id) {
const record = await menuInfo(id);
for (const key in record) {
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
await formApi.setValues(record);
}
drawerApi.drawerLoading(false);
},
@@ -102,7 +100,7 @@ async function handleConfirm() {
if (!valid) {
return;
}
const data = await formApi.getValues();
const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? menuUpdate(data) : menuAdd(data));
emit('reload');
await handleCancel();