in src/framework/MViewer.tsx [122:176]
export function SubmitBar(props: {
style?: React.CSSProperties,
onSubmit?: (finalData: any) => Promise<any>,
children?: React.ReactNode | ((loading: boolean) => React.ReactNode)
}): JSX.Element {
const [loading, setLoading] = useState(false);
let style: React.CSSProperties = props.children ? undefined : { textAlign: "center", ...props.style }
return <MContext.Consumer>{
ctx => {
const onClick = () => {
if (loading) {
message.warn("正在提交,请稍候");
return;
}
const r = assembly.validate(ctx.rootProps.schema, ctx.rootProps.database);
const submit = props.onSubmit ?? ctx.rootProps.onSubmit;
ctx.setForceValid(true);
if (r) {
Modal.warning({
content: '还没填完呢',
onOk: () => {
const viewer = document.getElementById(r.path);
if (viewer) {
viewer.scrollIntoView({ behavior: 'smooth', block: 'start' });
} else {
console.error("viewer not found", r);
}
}
});
} else {
if (submit) {
setLoading(true);
const finalData = MUtil.filterHide(ctx.rootProps.schema, ctx.rootProps.database)
submit(finalData).then(() => {
PersistantTool.clear(ctx.rootProps.persistant)
}).finally(() => {
setLoading(false);
});
} else {
message.success("填是填完了,但提交功能还在开发中,请联系程序员解决");
}
}
};
return <div style={style} onClick={props.children ? onClick : undefined}>
{
props.children
? (_.isFunction(props.children) ? props.children(loading) : props.children)
: <Button style={{ width: "40%" }} type="primary" loading={loading} onClick={props.children ? undefined : onClick}>提交</Button>
}
</div>
}
}</MContext.Consumer>
}