UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

152 lines (128 loc) 6.88 kB
'use strict'; var _list = require('antd-mobile/lib/list'); var _list2 = _interopRequireDefault(_list); var _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; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); require('antd-mobile/lib/list/style/css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _rcForm = require('rc-form'); var _FunctionUtil = require('../../utils/FunctionUtil'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var YYFormDev = function (_Component) { _inherits(YYFormDev, _Component); function YYFormDev() { var _ref; var _temp, _this2, _ret; _classCallCheck(this, YYFormDev); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this2 = _possibleConstructorReturn(this, (_ref = YYFormDev.__proto__ || Object.getPrototypeOf(YYFormDev)).call.apply(_ref, [this].concat(args))), _this2), _this2._renderChildren = function (children) { var _this = _this2; children = children && children.constructor == Array ? children : [children]; var colViews = []; var doCloneElement = function doCloneElement(target) { var props = _this._getCloneProps(target); return _react2.default.cloneElement(target, props); }; (0, _FunctionUtil.forEach)(children, function (child, rowIndex) { if (!_react2.default.isValidElement(child)) { console.warn('FormWidget无法解析非React对象元素', child); } else { colViews.push(_react2.default.createElement('div', { key: "fromwidget_col_" + child.props.nid }, doCloneElement(child))); } }); return _react2.default.createElement( 'div', null, colViews ); }, _temp), _possibleConstructorReturn(_this2, _ret); } _createClass(YYFormDev, [{ key: '_getCloneProps', value: function _getCloneProps(target) { var props = { form: this.props.form }; if (!this.props.visible) { props.visible = false; } if (this.props.disabled) { props.disabled = this.props.disabled; } else { if (target.props.disabled != undefined) { props.disabled = target.props.disabled; } } if (this.props.billType && this.props.billType.code && target.props.field == "billType") { Object.assign(props, { value: this.props.billType.code }); } return props; } }, { key: 'componentDidMount', value: function componentDidMount() { if (this.props.onViewDidMount) { this.props.onViewDidMount(this); } } }, { key: 'render', value: function render() { var _props = this.props, visible = _props.visible, autoSave = _props.autoSave, findUI = _props.findUI, offline = _props.offline, parentType = _props.parentType, uiorigin = _props.uiorigin, RunInDesign = _props.RunInDesign, uititle = _props.uititle, uitype = _props.uitype, uikey = _props.uikey, nid = _props.nid, restProps = _objectWithoutProperties(_props, ['visible', 'autoSave', 'findUI', 'offline', 'parentType', 'uiorigin', 'RunInDesign', 'uititle', 'uitype', 'uikey', 'nid']); return _react2.default.createElement( 'form', _extends({}, restProps, { className: 'yy-form' }), _react2.default.createElement( _list2.default, null, this._renderChildren(this.props.children) ) ); } }]); return YYFormDev; }(_react.Component); YYFormDev.defaultProps = { visible: true, autoSave: true, findUI: '', offline: false, parentType: '', uiorigin: '', RunInDesign: false, uititle: '', uitype: '', uikey: '', nid: '' }; YYFormDev.create = _rcForm.createForm; module.exports = YYFormDev.create({ onFieldsChange: function onFieldsChange(formControl, valueOption) { var values = {}; Object.keys(valueOption).map(function (key) { values[valueOption[key].name] = valueOption[key].value; }); if (formControl && formControl.listDataChange && formControl.autoSave && typeof formControl.listDataChange == "function") { formControl.listDataChange.call(formControl._parent_obj, formControl.sys_front_id, values); } } })(YYFormDev);