refactor: 重构config
This commit is contained in:
parent
c2511b13e1
commit
f6dc7213ea
@ -11,11 +11,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,14 +33,17 @@ const [BasicModal, modalApi] = useVbenModal({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
modalApi.modalLoading(true);
|
modalApi.modalLoading(true);
|
||||||
const { id, update } = modalApi.getData() as ModalProps;
|
|
||||||
isUpdate.value = update;
|
const { id } = modalApi.getData() as { id?: number | string };
|
||||||
if (update && id) {
|
isUpdate.value = !!id;
|
||||||
|
|
||||||
|
if (isUpdate.value && id) {
|
||||||
const record = await configInfo(id);
|
const record = await configInfo(id);
|
||||||
for (const key in record) {
|
for (const key in record) {
|
||||||
await formApi.setFieldValue(key, record[key as keyof typeof record]);
|
await formApi.setFieldValue(key, record[key as keyof typeof record]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
modalApi.modalLoading(false);
|
modalApi.modalLoading(false);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -22,12 +22,12 @@ const [ConfigModal, modalApi] = useVbenModal({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
modalApi.setData({ update: false });
|
modalApi.setData({});
|
||||||
modalApi.open();
|
modalApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleEdit(record: Recordable<any>) {
|
async function handleEdit(record: Recordable<any>) {
|
||||||
modalApi.setData({ id: record.configId, update: true });
|
modalApi.setData({ id: record.configId });
|
||||||
modalApi.open();
|
modalApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user