mirror of
https://github.com/certd/certd.git
synced 2026-04-14 12:30:54 +08:00
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { useFormWrapper } from "@fast-crud/fast-crud";
|
|
import { merge } from "lodash-es";
|
|
|
|
export type FormOptionReq = {
|
|
title: string;
|
|
columns?: any;
|
|
onSubmit?: any;
|
|
body?: any;
|
|
initialForm?: any;
|
|
zIndex?: number;
|
|
wrapper?: any;
|
|
};
|
|
|
|
export function useFormDialog() {
|
|
const { openCrudFormDialog } = useFormWrapper();
|
|
|
|
async function openFormDialog(req: FormOptionReq) {
|
|
function createCrudOptions() {
|
|
const warpper = merge(
|
|
{
|
|
zIndex: req.zIndex,
|
|
title: req.title,
|
|
saveRemind: false,
|
|
slots: {
|
|
"form-body-top": req.body,
|
|
},
|
|
},
|
|
req.wrapper
|
|
);
|
|
return {
|
|
crudOptions: {
|
|
columns: req.columns,
|
|
form: {
|
|
initialForm: req.initialForm,
|
|
wrapper: warpper,
|
|
async afterSubmit() {},
|
|
async doSubmit({ form }: any) {
|
|
if (req.onSubmit) {
|
|
await req.onSubmit(form);
|
|
}
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
const { crudOptions } = createCrudOptions();
|
|
await openCrudFormDialog({ crudOptions });
|
|
}
|
|
return {
|
|
openFormDialog,
|
|
};
|
|
}
|