refactor: 修改赋值逻辑

This commit is contained in:
dap 2024-09-25 11:55:53 +08:00
parent a661afc3e8
commit 1d6047c70b

View File

@ -16,11 +16,12 @@ 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');
}); });
const schema = modalSchema();
const [BasicForm, formApi] = useVbenForm({ const [BasicForm, formApi] = useVbenForm({
commonConfig: { commonConfig: {
labelWidth: 80, labelWidth: 80,
}, },
schema: modalSchema(), schema,
showDefaultActions: false, showDefaultActions: false,
}); });
@ -39,9 +40,14 @@ const [BasicModal, modalApi] = useVbenModal({
if (isUpdate.value && id) { if (isUpdate.value && id) {
const record = await configInfo(id); const record = await configInfo(id);
for (const key in record) { //
await formApi.setFieldValue(key, record[key as keyof typeof record]); schema
} .map((item) => item.fieldName)
.forEach((key) => {
if (key in record) {
formApi.setFieldValue(key, record[key as keyof typeof record]);
}
});
} }
modalApi.modalLoading(false); modalApi.modalLoading(false);