UNPKG

@wufengteam/wform

Version:

@wufengteam/wform

88 lines 4.36 kB
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /* eslint-disable no-console */ import React, { useContext } from 'react'; import { Col, Form } from 'antd'; import TooltipView from '@lingxiteam/pcfactory/lib/TooltipView'; import { DummyFormContext } from '@lingxiteam/pcfactory/lib/utils/DummyFormContext'; import WithSyncValue from '@lingxiteam/pcfactory/lib/utils/WithSyncValue'; import useFieldAttr from '../../hooks/useFieldAttr'; import "./index.css"; var PCFieldItem = function PCFieldItem(props) { var _a; // console.log('FieldItemProps', props); var fieldAttr = props.fieldAttr, labelCol = props.labelCol, wrapperCol = props.wrapperCol, validateStatus = props.validateStatus, help = props.help, _props$rules = props.rules, externalRules = _props$rules === void 0 ? [] : _props$rules, initialValue = props.initialValue, children = props.children, name = props.name, fieldName = props.fieldName, required = props.required, titleTip = props.titleTip, tipLocation = props.tipLocation, tipContent = props.tipContent, tipIcon = props.tipIcon, tipPlacement = props.tipPlacement, selfSpan = props.selfSpan, colSpan = props.colSpan, style = props.style; // 获取当前表单实例 var form = useContext(DummyFormContext); // 若组件的状态设置为隐藏 直接返回 null 不渲染 var _useFieldAttr = useFieldAttr({ fieldAttr: fieldAttr || [] }), hidden = _useFieldAttr.hidden; if (hidden) return null; var rules = required ? [{ required: true, message: "".concat(name, "\u4E0D\u80FD\u4E3A\u7A7A") }] : []; var isRequired = required; if (Array.isArray(externalRules) && externalRules.length > 0) { // 如果业务规则中有必填的校验,要把required属性置为true externalRules.forEach(function (item) { if (item === null || item === void 0 ? void 0 : item.required) { isRequired = true; } }); rules.push.apply(rules, _toConsumableArray(externalRules)); } return /*#__PURE__*/React.createElement(React.Fragment, null, (form === null || form === void 0 ? void 0 : form.getFieldDecorator) ? ( /*#__PURE__*/React.createElement(Col, { style: style, span: selfSpan || colSpan || 12 }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({ label: titleTip === 'notext' ? name : ( /*#__PURE__*/React.createElement(TooltipView, { label: name, tipContent: tipContent, tipIcon: tipIcon, titleTip: titleTip, tipLocation: tipLocation, tipPlacement: tipPlacement })), labelCol: labelCol, wrapperCol: wrapperCol, validateStatus: validateStatus, help: help, hasFeedback: !!validateStatus, required: isRequired }, (_a = form === null || form === void 0 ? void 0 : form.nowValidateMsg) === null || _a === void 0 ? void 0 : _a[fieldName]), form.getFieldDecorator(fieldName, { rules: rules, initialValue: initialValue, validateTrigger: 'onChange' }, fieldName)( /*#__PURE__*/React.createElement(WithSyncValue, { compId: fieldName }, /*#__PURE__*/React.cloneElement(children, { form: form })))))) : children); }; export default PCFieldItem;