refactor: 改为从info获取
This commit is contained in:
parent
c7ba5b4b1d
commit
b13fafdaf5
@ -5,7 +5,7 @@ import { useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { useVbenForm } from '#/adapter';
|
||||
import { configAdd, configUpdate } from '#/api/system/config';
|
||||
import { configAdd, configInfo, configUpdate } from '#/api/system/config';
|
||||
|
||||
import { modalSchema } from './data';
|
||||
|
||||
@ -13,7 +13,7 @@ const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
interface ModalProps {
|
||||
update: boolean;
|
||||
record?: any;
|
||||
id: number | string;
|
||||
}
|
||||
|
||||
const isUpdate = ref(false);
|
||||
@ -38,11 +38,12 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
return null;
|
||||
}
|
||||
modalApi.modalLoading(true);
|
||||
const { record, update } = modalApi.getData() as ModalProps;
|
||||
const { id, update } = modalApi.getData() as ModalProps;
|
||||
isUpdate.value = update;
|
||||
if (update && record) {
|
||||
if (update && id) {
|
||||
const record = await configInfo(id);
|
||||
for (const key in record) {
|
||||
await formApi.setFieldValue(key, record[key]);
|
||||
await formApi.setFieldValue(key, record[key as keyof typeof record]);
|
||||
}
|
||||
}
|
||||
modalApi.modalLoading(false);
|
||||
@ -57,7 +58,6 @@ async function handleConfirm() {
|
||||
return;
|
||||
}
|
||||
const data = await formApi.getValues();
|
||||
console.log(data);
|
||||
await (isUpdate.value ? configUpdate(data) : configAdd(data));
|
||||
emit('reload');
|
||||
await handleCancel();
|
||||
|
@ -27,7 +27,7 @@ function handleAdd() {
|
||||
}
|
||||
|
||||
async function handleEdit(record: Recordable<any>) {
|
||||
modalApi.setData({ record, update: true });
|
||||
modalApi.setData({ id: record.configId, update: true });
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user