UNPKG

@lvxiaowu/antd4

Version:

antd4-components

60 lines (47 loc) 2.52 kB
var _excluded = ["store", "children", "form"]; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React, { useEffect } from 'react'; import { observer } from 'mobx-react-lite'; import { FORM_MODAL_STORE } from '../utils'; import Modal from '../Modal'; function getStore(store) { var res = (store === null || store === void 0 ? void 0 : store.$modal) || store; if ((res === null || res === void 0 ? void 0 : res.$storeName) === FORM_MODAL_STORE) { return { modalStore: res.getModalStore(), selfStore: res }; } return {}; } function SdFormModal(_ref) { var store = _ref.store, children = _ref.children, form = _ref.form, rest = _objectWithoutProperties(_ref, _excluded); var _getStore = getStore(store), selfStore = _getStore.selfStore, modalStore = _getStore.modalStore; if (!selfStore) { console.error('FormModal组件必须传store属性,并且是FormModalStore的实例'); return null; } if (!form) { console.error('FormModal组件必须传form属性'); return null; } selfStore.setFormInstance(form); var visible = modalStore.visible, openValues = modalStore.openValues; useEffect(function () { if (visible && openValues) { form.setFieldsValue(openValues); } }, [visible]); return /*#__PURE__*/React.createElement(Modal, _extends({ store: modalStore }, rest), children); } export default observer(SdFormModal);