UNPKG

vue-admin-core

Version:
71 lines (68 loc) 1.92 kB
import { getCurrentInstance, defineComponent, computed, createVNode } from 'vue'; import { useForm } from '@formily/vue'; import { createForm } from '@formily/core'; import '../../formily/index.mjs'; import { observer } from '@formily/reactive-vue'; import { formLayoutProps, FormLayout } from '../../formily/form-layout/src/index.mjs'; const useFormilyForm = (schema, options, SchemaField) => { const form = useForm(); const app = getCurrentInstance(); const SelfSchemaField = (app == null ? void 0 : app.appContext.components.SchemaField) || SchemaField; if (!SelfSchemaField) { throw new Error(`SchemaField \u627E\u4E0D\u5230\uFF0C\u5728\u5168\u5C40\u8BBE\u7F6Eapp.use(setupFormily)\u6216\u8005\u4F20\u5165SchemaField`); } if (!form.value) { form.value = createForm(options); } const FormilyForm = defineComponent({ name: "FormilyForm", props: { ...formLayoutProps, schema: { type: Object }, components: { type: Object }, scope: { type: Object }, name: { type: [String, Number] }, definitions: { type: Object } }, setup(props, { slots }) { const { schema: schemaProps, components, scope, name, ...reset } = props; const _schema = computed(() => ({ type: "object", definitions: props.definitions, properties: schemaProps || schema })); return () => createVNode(FormLayout, reset, { default: () => [createVNode(SelfSchemaField, { "schema": _schema.value, "components": components, "scope": scope, "name": name }, null), slots.default && slots.default()] }); } }); return { form, FormilyForm: observer(FormilyForm) }; }; export { useFormilyForm }; //# sourceMappingURL=useFormilyForm.mjs.map