vue-admin-core
Version:
A Component Library for Vue 3
65 lines (62 loc) • 1.79 kB
JavaScript
import { defineComponent } from 'vue';
import { useParentForm, h } from '@formily/vue';
import { observer } from '@formily/reactive-vue';
import { buttonProps, ElButton } from 'element-plus';
import { buildProps } from 'element-plus/es/utils/index';
const submitProps = buildProps({
onClick: {
type: Function
},
onSubmit: {
type: Function
},
onSubmitSuccess: {
type: Function
},
onSubmitFailed: {
type: Function
}
});
const Submit = observer(
defineComponent({
name: "FSubmit",
props: { ...buttonProps, ...submitProps },
setup(props, { slots }) {
const formRef = useParentForm();
return () => {
const {
onClick = props == null ? void 0 : props.onClick,
onSubmit = props == null ? void 0 : props.onSubmit,
onSubmitSuccess = props == null ? void 0 : props.onSubmitSuccess,
onSubmitFailed = props == null ? void 0 : props.onSubmitFailed,
type,
nativeType,
loading,
...reset
} = props;
const form = formRef == null ? void 0 : formRef.value;
return h(
ElButton,
{
...reset,
nativeType: nativeType || "submit",
type: type || "primary",
loading: loading || (form == null ? void 0 : form.submitting),
onClick: (e) => {
if (onClick) {
if (onClick(e) === false)
return;
}
if (onSubmit) {
form == null ? void 0 : form.submit(onSubmit).then(onSubmitSuccess).catch(onSubmitFailed);
}
}
},
slots
);
};
}
})
);
export { Submit, Submit as default, submitProps };
//# sourceMappingURL=index.mjs.map