import * as React from 'react'; import classnames from 'classnames'; import { Form, Grid, Field } from '@alife/cn-ui'; import { FormProps } from 'src/types/op-form'; import Item from './item'; import './index.scss'; import OPButton from '../op-button'; const { Row, Col } = Grid; export default function OPForm(props: FormProps) { const { className = '', formItemLayout = {}, configs = [], columnNumber = 1, field, searchProps, } = props; const newField = Field.useField(); const innerField = field || newField; const avgSpan = 24 / columnNumber; const renderSearchButtons = () => { const { isRightButton = true, buttons, onSearch, onClear, searchText = '查询', clearText = '重置', span, } = searchProps || {}; const getSpanNumber = (_span: string | number | undefined) => _span != null ? Number(_span) : avgSpan; const allSpans = configs?.reduce( (res, curr) => res + getSpanNumber(curr.span), 0, ); const whiteSpan = 24 - (allSpans % 24) - getSpanNumber(span); return ( <> {isRightButton && } } > {Array.isArray(buttons) ? ( buttons ) : ( <> { onSearch?.(innerField, innerField.getValues()); }} > {searchText} { onClear?.(innerField, innerField.getValues()); innerField.reset(); }} > {clearText} )} ); }; return (
{configs?.length ? (
{configs.map((item) => { return ( ); })} {searchProps && renderSearchButtons()}
) : null}
); }