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,6 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { clientAdd, clientInfo, clientUpdate } from '#/api/system/client'; import { clientAdd, clientInfo, clientUpdate } from '#/api/system/client';
@@ -12,11 +13,6 @@ import SecretInput from './secret-input.vue';
const emit = defineEmits<{ reload: [] }>(); const emit = defineEmits<{ reload: [] }>();
interface DrawerProps {
update: boolean;
id?: number | string;
}
const isUpdate = ref(false); const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add'); return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -64,11 +60,11 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
return null; return null;
} }
drawerApi.drawerLoading(true); drawerApi.drawerLoading(true);
const { id, update } = drawerApi.getData() as DrawerProps; const { id } = drawerApi.getData() as { id?: number | string };
isUpdate.value = update; isUpdate.value = !!id;
// 初始化 // 初始化
setupForm(update); setupForm(isUpdate.value);
if (update && id) { if (isUpdate.value && id) {
const record = await clientInfo(id); const record = await clientInfo(id);
// 不能禁用id为1的记录 // 不能禁用id为1的记录
formApi.updateSchema([ formApi.updateSchema([
@@ -79,10 +75,7 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
fieldName: 'status', fieldName: 'status',
}, },
]); ]);
await formApi.setValues(record);
for (const key in record) {
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
drawerApi.drawerLoading(false); drawerApi.drawerLoading(false);
}, },
@@ -95,7 +88,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? clientUpdate(data) : clientAdd(data)); await (isUpdate.value ? clientUpdate(data) : clientAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -3,6 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { configAdd, configInfo, configUpdate } from '#/api/system/config'; import { configAdd, configInfo, configUpdate } from '#/api/system/config';
@@ -53,7 +54,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? configUpdate(data) : configAdd(data)); await (isUpdate.value ? configUpdate(data) : configAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -3,7 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { addFullName, listToTree } from '@vben/utils'; import { addFullName, cloneDeep, listToTree } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { import {
@@ -120,10 +120,8 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
if (id) { if (id) {
await formApi.setFieldValue('parentId', id); await formApi.setFieldValue('parentId', id);
if (update) { if (update) {
const ret = await deptInfo(id); const record = await deptInfo(id);
Object.keys(ret).forEach((key) => { await formApi.setValues(record);
formApi.setFieldValue(key, ret[key as keyof typeof ret]);
});
} }
} }
@@ -142,7 +140,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? deptUpdate(data) : deptAdd(data)); await (isUpdate.value ? deptUpdate(data) : deptAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -3,6 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { clientAdd, clientUpdate } from '#/api/system/client'; import { clientAdd, clientUpdate } from '#/api/system/client';
@@ -69,9 +70,7 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
if (dictCode && isUpdate.value) { if (dictCode && isUpdate.value) {
const record = await dictDetailInfo(dictCode); const record = await dictDetailInfo(dictCode);
setupSelectType(record.listClass); setupSelectType(record.listClass);
for (const key in record) { await formApi.setValues(record);
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
drawerApi.drawerLoading(false); drawerApi.drawerLoading(false);
@@ -85,7 +84,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? clientUpdate(data) : clientAdd(data)); await (isUpdate.value ? clientUpdate(data) : clientAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -3,19 +3,19 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { dictTypeAdd, dictTypeUpdate } from '#/api/system/dict/dict-type'; import {
dictTypeAdd,
dictTypeInfo,
dictTypeUpdate,
} from '#/api/system/dict/dict-type';
import { modalSchema } from './data'; import { modalSchema } from './data';
const emit = defineEmits<{ reload: [] }>(); const emit = defineEmits<{ reload: [] }>();
interface ModalProps {
update: boolean;
record?: any;
}
const isUpdate = ref(false); const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add'); return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -38,12 +38,11 @@ const [BasicModal, modalApi] = useVbenModal({
return null; return null;
} }
modalApi.modalLoading(true); modalApi.modalLoading(true);
const { record, update } = modalApi.getData() as ModalProps; const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = update; isUpdate.value = !!id;
if (update && record) { if (isUpdate.value && id) {
for (const key in record) { const record = await dictTypeInfo(id);
await formApi.setFieldValue(key, record[key]); await formApi.setValues(record);
}
} }
modalApi.modalLoading(false); modalApi.modalLoading(false);
}, },
@@ -56,7 +55,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? dictTypeUpdate(data) : dictTypeAdd(data)); await (isUpdate.value ? dictTypeUpdate(data) : dictTypeAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

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

View File

@@ -3,6 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { noticeAdd, noticeInfo, noticeUpdate } from '#/api/system/notice'; import { noticeAdd, noticeInfo, noticeUpdate } from '#/api/system/notice';
@@ -12,11 +13,6 @@ import { modalSchema } from './data';
const emit = defineEmits<{ reload: [] }>(); const emit = defineEmits<{ reload: [] }>();
interface ModalProps {
update: boolean;
id?: number | string;
}
const isUpdate = ref(false); const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add'); return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -38,13 +34,11 @@ const [BasicModal, modalApi] = useVbenModal({
return null; return null;
} }
modalApi.modalLoading(true); modalApi.modalLoading(true);
const { id, update } = modalApi.getData() as ModalProps; const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = update; isUpdate.value = !!id;
if (update && id) { if (isUpdate.value && id) {
const record = await noticeInfo(id); const record = await noticeInfo(id);
for (const key in record) { await formApi.setValues(record);
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
modalApi.modalLoading(false); modalApi.modalLoading(false);
}, },
@@ -57,8 +51,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
console.log(data);
await (isUpdate.value ? noticeUpdate(data) : noticeAdd(data)); await (isUpdate.value ? noticeUpdate(data) : noticeAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -3,6 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { import {
@@ -15,11 +16,6 @@ import { drawerSchema } from './data';
const emit = defineEmits<{ reload: [] }>(); const emit = defineEmits<{ reload: [] }>();
interface DrawerProps {
update: boolean;
id?: number | string;
}
const isUpdate = ref(false); const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add'); return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -43,13 +39,11 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
return null; return null;
} }
drawerApi.drawerLoading(true); drawerApi.drawerLoading(true);
const { id, update } = drawerApi.getData() as DrawerProps; const { id } = drawerApi.getData() as { id?: number | string };
isUpdate.value = update; isUpdate.value = !!id;
if (update && id) { if (isUpdate.value && id) {
const record = await ossConfigInfo(id); const record = await ossConfigInfo(id);
for (const key in record) { await formApi.setValues(record);
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
drawerApi.drawerLoading(false); drawerApi.drawerLoading(false);
}, },
@@ -66,7 +60,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? ossConfigUpdate(data) : ossConfigAdd(data)); await (isUpdate.value ? ossConfigUpdate(data) : ossConfigAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -3,7 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { addFullName } from '@vben/utils'; import { addFullName, cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { postAdd, postInfo, postUpdate } from '#/api/system/post'; import { postAdd, postInfo, postUpdate } from '#/api/system/post';
@@ -13,11 +13,6 @@ import { drawerSchema } from './data';
const emit = defineEmits<{ reload: [] }>(); const emit = defineEmits<{ reload: [] }>();
interface DrawerProps {
update: boolean;
id?: number | string;
}
const isUpdate = ref(false); const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add'); return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -59,16 +54,14 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
return null; return null;
} }
drawerApi.drawerLoading(true); drawerApi.drawerLoading(true);
const { id, update } = drawerApi.getData() as DrawerProps; const { id } = drawerApi.getData() as { id?: number | string };
isUpdate.value = update; isUpdate.value = !!id;
// 初始化 // 初始化
await setupDeptSelect(); await setupDeptSelect();
// 更新 && 赋值 // 更新 && 赋值
if (update && id) { if (isUpdate.value && id) {
const record = await postInfo(id); const record = await postInfo(id);
for (const key in record) { await formApi.setValues(record);
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
drawerApi.drawerLoading(false); drawerApi.drawerLoading(false);
}, },
@@ -81,7 +74,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? postUpdate(data) : postAdd(data)); await (isUpdate.value ? postUpdate(data) : postAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -2,8 +2,7 @@
import { ref } from 'vue'; import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { cloneDeep } from '@vben/utils';
import { cloneDeep } from 'lodash-es';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { roleDataScope, roleDeptTree, roleInfo } from '#/api/system/role'; import { roleDataScope, roleDeptTree, roleInfo } from '#/api/system/role';
@@ -46,9 +45,7 @@ const [BasicModal, modalApi] = useVbenModal({
setupDeptTree(id); setupDeptTree(id);
const record = await roleInfo(id); const record = await roleInfo(id);
for (const key in record) { await formApi.setValues(record);
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
modalApi.modalLoading(false); modalApi.modalLoading(false);
}, },

View File

@@ -3,8 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { cloneDeep } from 'lodash-es';
import { useVbenForm } from '#/adapter'; import { useVbenForm } from '#/adapter';
import { menuTreeSelect, roleMenuTreeSelect } from '#/api/system/menu'; import { menuTreeSelect, roleMenuTreeSelect } from '#/api/system/menu';
@@ -61,9 +60,7 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
if (isUpdate.value && id) { if (isUpdate.value && id) {
const record = await roleInfo(id); const record = await roleInfo(id);
for (const key in record) { await formApi.setValues(record);
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
// init菜单 注意顺序要放在赋值record之后 内部watch会依赖record // init菜单 注意顺序要放在赋值record之后 内部watch会依赖record
await setupMenuTree(id); await setupMenuTree(id);

View File

@@ -3,6 +3,7 @@ import { computed, h, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { Tag } from 'ant-design-vue'; import { Tag } from 'ant-design-vue';
@@ -15,11 +16,6 @@ import { drawerSchema } from './data';
const emit = defineEmits<{ reload: [] }>(); const emit = defineEmits<{ reload: [] }>();
interface DrawerProps {
update: boolean;
id?: number | string;
}
const isUpdate = ref(false); const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add'); return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -66,15 +62,13 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
return null; return null;
} }
drawerApi.drawerLoading(true); drawerApi.drawerLoading(true);
const { id, update } = drawerApi.getData() as DrawerProps; const { id } = drawerApi.getData() as { id?: number | string };
isUpdate.value = update; isUpdate.value = !!id;
// 初始化 // 初始化
await setupPackageSelect(); await setupPackageSelect();
if (update && id) { if (isUpdate.value && id) {
const record = await tenantInfo(id); const record = await tenantInfo(id);
for (const key in record) { await formApi.setValues(record);
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
drawerApi.drawerLoading(false); drawerApi.drawerLoading(false);
}, },
@@ -87,7 +81,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? clientUpdate(data) : clientAdd(data)); await (isUpdate.value ? clientUpdate(data) : clientAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -3,6 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { Card, Tree } from 'ant-design-vue'; import { Card, Tree } from 'ant-design-vue';
@@ -13,11 +14,6 @@ import { drawerSchema } from './data';
const emit = defineEmits<{ reload: [] }>(); const emit = defineEmits<{ reload: [] }>();
interface DrawerProps {
update: boolean;
id?: number | string;
}
const isUpdate = ref(false); const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add'); return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@@ -65,11 +61,11 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
return null; return null;
} }
drawerApi.drawerLoading(true); drawerApi.drawerLoading(true);
const { id, update } = drawerApi.getData() as DrawerProps; const { id } = drawerApi.getData() as { id?: number | string };
isUpdate.value = update; isUpdate.value = !!id;
// 初始化 // 初始化
setupForm(update); setupForm(isUpdate.value);
if (update && id) { if (isUpdate.value && id) {
const record = await clientInfo(id); const record = await clientInfo(id);
// 不能禁用id为1的记录 // 不能禁用id为1的记录
formApi.updateSchema([ formApi.updateSchema([
@@ -80,10 +76,7 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
fieldName: 'status', fieldName: 'status',
}, },
]); ]);
await formApi.setValues(record);
for (const key in record) {
await formApi.setFieldValue(key, record[key as keyof typeof record]);
}
} }
drawerApi.drawerLoading(false); drawerApi.drawerLoading(false);
}, },
@@ -96,7 +89,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? clientUpdate(data) : clientAdd(data)); await (isUpdate.value ? clientUpdate(data) : clientAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();

View File

@@ -5,7 +5,7 @@ import { computed, h, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui'; import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { addFullName, getPopupContainer } from '@vben/utils'; import { addFullName, cloneDeep, getPopupContainer } from '@vben/utils';
import { Tag } from 'ant-design-vue'; import { Tag } from 'ant-design-vue';
@@ -125,7 +125,7 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
return null; return null;
} }
drawerApi.drawerLoading(true); drawerApi.drawerLoading(true);
const { id } = drawerApi.getData() as { id: number | string }; const { id } = drawerApi.getData() as { id?: number | string };
isUpdate.value = !!id; isUpdate.value = !!id;
/** update时 禁用用户名修改 不显示密码框 */ /** update时 禁用用户名修改 不显示密码框 */
formApi.updateSchema([ formApi.updateSchema([
@@ -155,11 +155,13 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
// 部门选择 // 部门选择
await setupDeptSelect(); await setupDeptSelect();
if (user) { if (user) {
await Promise.all([
// 添加基础信息 // 添加基础信息
formApi.setValues(user); formApi.setValues(user),
// 添加角色和岗位 // 添加角色和岗位
await formApi.setFieldValue('postIds', postIds); formApi.setFieldValue('postIds', postIds),
await formApi.setFieldValue('roleIds', roleIds); formApi.setFieldValue('roleIds', roleIds),
]);
} }
drawerApi.drawerLoading(false); drawerApi.drawerLoading(false);
}, },
@@ -172,7 +174,7 @@ async function handleConfirm() {
if (!valid) { if (!valid) {
return; return;
} }
const data = await formApi.getValues(); const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? userUpdate(data) : userAdd(data)); await (isUpdate.value ? userUpdate(data) : userAdd(data));
emit('reload'); emit('reload');
await handleCancel(); await handleCancel();