UNPKG

dareway-rui

Version:

390 lines (339 loc) 16.8 kB
'use strict'; var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault'); Object.defineProperty(exports, '__esModule', { value: true }); exports.default = void 0; var _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends')); var _objectSpread3 = _interopRequireDefault(require('@babel/runtime/helpers/objectSpread')); var _classCallCheck2 = _interopRequireDefault(require('@babel/runtime/helpers/classCallCheck')); var _createClass2 = _interopRequireDefault(require('@babel/runtime/helpers/createClass')); var _possibleConstructorReturn2 = _interopRequireDefault(require('@babel/runtime/helpers/possibleConstructorReturn')); var _getPrototypeOf2 = _interopRequireDefault(require('@babel/runtime/helpers/getPrototypeOf')); var _assertThisInitialized2 = _interopRequireDefault(require('@babel/runtime/helpers/assertThisInitialized')); var _inherits2 = _interopRequireDefault(require('@babel/runtime/helpers/inherits')); var _defineProperty2 = _interopRequireDefault(require('@babel/runtime/helpers/defineProperty')); var _react = _interopRequireDefault(require('react')); var _reactRedux = require('react-redux'); var _uuid = _interopRequireDefault(require('../../util/uuid')); var _Model = require('./Model'); var _code = require('../../code'); var _WrapViewWithFocus = _interopRequireDefault(require('./WrapViewWithFocus')); var _utils = require('./utils'); var _TaglibConstants = require('../TaglibConstants'); var _dec, _class, _temp; var FormRegister = ((_dec = (0, _reactRedux.connect)()), _dec( (_class = ((_temp = /*#__PURE__*/ (function(_React$PureComponent) { (0, _inherits2.default)(FormRegister, _React$PureComponent); function FormRegister(_props) { var _this; (0, _classCallCheck2.default)(this, FormRegister); _this = (0, _possibleConstructorReturn2.default)( this, (0, _getPrototypeOf2.default)(FormRegister).call(this, _props) ); // 标签名 (0, _defineProperty2.default)( (0, _assertThisInitialized2.default)(_this), '_connectFormItemView', function(formItemName, FormItemView) { var connector = (0, _reactRedux.connect)(function(store) { return store[ _this.props.modelNamespace ]['@@tags'][_this.tagName]['formItems'][formItemName.toLowerCase()]; }); return connector(FormItemView); } ); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), '_addFormItem', function( props, _ref ) { var _objectSpread2; var _ref$TAG_ATTRS_GENERA = _ref.TAG_ATTRS_GENERATOR, TAG_ATTRS_GENERATOR = _ref$TAG_ATTRS_GENERA === void 0 ? null : _ref$TAG_ATTRS_GENERA, _ref$TAG_TYPE = _ref.TAG_TYPE, TAG_TYPE = _ref$TAG_TYPE === void 0 ? null : _ref$TAG_TYPE, _ref$TAG_API_GENERATO = _ref.TAG_API_GENERATOR, TAG_API_GENERATOR = _ref$TAG_API_GENERATO === void 0 ? null : _ref$TAG_API_GENERATO; if (!_this.isFormMounted) { return; } var tagAttrs = TAG_ATTRS_GENERATOR(props); tagAttrs.name = tagAttrs.name.toLowerCase(); // 大小写不敏感 tagAttrs.inputDomId = (0, _uuid.default)(); tagAttrs.forwardedRef = _react.default.createRef(); var attributes = (0, _objectSpread3.default)( {}, tagAttrs, ((_objectSpread2 = {}), (0, _defineProperty2.default)(_objectSpread2, _TaglibConstants.TAG_TYPE_KEY_IN_STATE, TAG_TYPE), (0, _defineProperty2.default)( _objectSpread2, '@@api', (0, _utils.wrapFormItemTagApis)( _this.props.modelNamespace, _this.tagName, tagAttrs.name, TAG_API_GENERATOR ) ), _objectSpread2) ); var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormAPI_addFormItemSuccess'), payload: { tagName: _this.tagName, payload: (0, _objectSpread3.default)( { name: tagAttrs.name }, attributes ) } }); }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), '_removeFormItem', function( name ) { if (_this.isUnmounting) { return; } var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormAPI_removeFormItemSuccess'), payload: { tagName: _this.tagName, payload: { name: name.toLowerCase() // 大小写不敏感 } } }); }); (0, _defineProperty2.default)( (0, _assertThisInitialized2.default)(_this), '_saveValueOnChange', function(name, value) { var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormItemDataSyncAPI_saveValueOnChangeSuccess'), payload: { tagName: _this.tagName, payload: { name: name.toLowerCase(), value: value } } }); } ); (0, _defineProperty2.default)( (0, _assertThisInitialized2.default)(_this), '_savaOldValue4SimulateOnHTMLChange', function(formItemName, value) { var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat( bizModelNamespace, '/FormItemDataSyncAPI_savaOldValue4SimulateOnHTMLChangeSuccess' ), payload: { tagName: _this.tagName, payload: { meta: { formItemName: formItemName }, params: { value: value } } } }); } ); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), '_setCollapsed', function( formItemName, collapsed ) { var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormItemAPI_setCollapsedSuccess'), payload: { tagName: _this.tagName, payload: { meta: { formItemName: formItemName.toLowerCase() }, params: { collapsed: collapsed } } } }); }); (0, _defineProperty2.default)( (0, _assertThisInitialized2.default)(_this), '_clearLovMappings', function(formItemName) { var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormItemAPI_lovClearMappingValuesAction'), payload: { tagName: _this.tagName, payload: { meta: { formItemName: formItemName.toLowerCase() } } } }); } ); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), '_checkValue', function( name ) { var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormItemAPI_checkValue'), payload: { tagName: _this.tagName, payload: { meta: { formItemName: name.toLowerCase() }, params: {} } } }); }); (0, _defineProperty2.default)( (0, _assertThisInitialized2.default)(_this), '_setCodeMapByCode', function(name, code, prefix, excludeCodes) { if (!_this.isFormMounted) { return; } var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormItemAPI_initSingleCodeMap'), payload: { tagName: _this.tagName, payload: { meta: { formItemName: name.toLowerCase() }, params: { code: code, prefix: prefix, excludeCodes: excludeCodes } } } }); } ); (0, _defineProperty2.default)( (0, _assertThisInitialized2.default)(_this), 'initCodeMapList', function() { var codeInfoArray = (0, _utils.getSelectChildrenCodeInfo)(_this.props.children); if (!codeInfoArray.length) { return; } var bizModelNamespace = _this.props.modelNamespace; _this.props.dispatch({ type: ''.concat(bizModelNamespace, '/FormItemAPI_initCodeMapList'), payload: { tagName: _this.tagName, payload: codeInfoArray } }); } ); var _name = _this.props.name || 'Form_'.concat((0, _uuid.default)()); // 模型名 _this.tagName = _name; _this.codeManagerNamespace = (0, _uuid.default)(); // 模型注入 _this.props.dispatch({ type: ''.concat(_this.props.modelNamespace, '/__privateAddTag'), payload: { tagName: _this.tagName, tagInitState: (0, _objectSpread3.default)( {}, (0, _Model.genState)(_this.props.modelNamespace, _this.tagName, _this.props), { codeManagerNamespace: _this.codeManagerNamespace, '@@api': (0, _Model.genApi)(_this.props.modelNamespace, _this.tagName) } ) } }); // 链接View var _connector = (0, _reactRedux.connect)(function(store) { // 这个地方要时刻与 state 保持一致; var hidden = store[_this.props.modelNamespace]['@@tags'][_this.tagName].hidden; return { hidden: hidden }; }); _this.ConnectedComponent = _connector(_WrapViewWithFocus.default); // 给 Form 创建独立的 Code 管理器; _code.CodeManager.register(_this.codeManagerNamespace); _this.isFormMounted = false; _this.isUnmounting = false; return _this; } (0, _createClass2.default)(FormRegister, [ { key: 'componentWillUnmount', value: function componentWillUnmount() { var bizModelNamespace = this.props.modelNamespace; this.props.dispatch({ type: ''.concat(bizModelNamespace, '/__privateRemoveTag'), payload: { tagName: this.tagName } }); // 给 Form 创建独立的 Code 管理器; _code.CodeManager.unregister(this.codeManagerNamespace); } }, { key: 'componentDidMount', value: function componentDidMount() { this.isFormMounted = true; this.initCodeMapList(); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { this.isUnmounting = true; } }, { key: 'render', value: function render() { var ConnectedComponent = this.ConnectedComponent; return _react.default.createElement( ConnectedComponent, (0, _extends2.default)({}, this.props, { _addFormItem: this._addFormItem, _removeFormItem: this._removeFormItem, _connectFormItemView: this._connectFormItemView, _saveValueOnChange: this._saveValueOnChange, _savaOldValue4SimulateOnHTMLChange: this._savaOldValue4SimulateOnHTMLChange, _setCollapsed: this._setCollapsed, _checkValue: this._checkValue, _clearLovMappings: this._clearLovMappings, _setCodeMapByCode: this._setCodeMapByCode }) ); } } ]); return FormRegister; })(_react.default.PureComponent)), _temp)) ) || _class); exports.default = FormRegister; //@ sourceMappingURL=Register.js.map