1 | "use strict";
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
10 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const react_1 = __importStar(require("react"));
|
14 | const react_native_1 = require("react-native");
|
15 | const antd_mobile_rn_1 = require("@sishuguojixuefu/antd-mobile-rn");
|
16 | const rc_form_1 = require("rc-form");
|
17 | const components_1 = __importDefault(require("./components"));
|
18 | const getFieldDecorator_1 = __importDefault(require("./utils/getFieldDecorator"));
|
19 | class Form extends react_1.Component {
|
20 | constructor(props) {
|
21 | super(props);
|
22 |
|
23 | this._getChilds = () => {
|
24 | const { children } = this.props;
|
25 | let childs = children;
|
26 | if (children && !children.length) {
|
27 | childs = [children];
|
28 | }
|
29 | return childs;
|
30 | };
|
31 | this._onChange = () => {
|
32 | react_native_1.DeviceEventEmitter.emit('SsDynamicFormValueChanged', {
|
33 | values: this.props.form.getFieldsValue(),
|
34 | });
|
35 | };
|
36 |
|
37 | const childs = this._getChilds();
|
38 | if (childs && childs.length) {
|
39 | childs.forEach((item) => {
|
40 | if (item.props.custom) {
|
41 | const { id, initialValue, rules } = item.props;
|
42 | this[id] = getFieldDecorator_1.default(props.form, id, initialValue, rules, props.options);
|
43 | }
|
44 | });
|
45 | }
|
46 | }
|
47 | render() {
|
48 | const { items, renderHeader, renderFooter, form, noBorder, style } = this.props;
|
49 | const childs = this._getChilds();
|
50 | return (react_1.default.createElement(antd_mobile_rn_1.List, { renderHeader: renderHeader, renderFooter: renderFooter, style: [styles.container, style], noBorder: noBorder },
|
51 | items && items.length
|
52 | ? items.map(item => {
|
53 | if (Object.keys(components_1.default).indexOf(item.componentName) >= 0) {
|
54 | return react_1.default.createElement(components_1.default[item.componentName], {
|
55 | key: item.props.id,
|
56 | form,
|
57 | onChange: () => this._onChange(),
|
58 | ...item.props,
|
59 | });
|
60 | }
|
61 | return null;
|
62 | })
|
63 | : null,
|
64 | childs && childs.length
|
65 | ? childs.map((item, index) => {
|
66 | const child = react_1.default.cloneElement(item, {
|
67 | key: item.props.id || index.toString(),
|
68 | form,
|
69 | id: item.props.id,
|
70 | onChange: () => this._onChange(),
|
71 | ...item.props,
|
72 | });
|
73 | return item.props.custom ? this[item.props.id](child) : child;
|
74 | })
|
75 | : null,
|
76 | react_1.default.createElement(react_native_1.View, { style: { height: noBorder ? 1 : 0 } })));
|
77 | }
|
78 | }
|
79 | Form.defaultProps = {
|
80 | noBorder: true,
|
81 | };
|
82 | const styles = react_native_1.StyleSheet.create({
|
83 | container: {
|
84 | backgroundColor: '#ffffff',
|
85 | flex: 1,
|
86 | },
|
87 | });
|
88 | exports.default = rc_form_1.createForm({})(Form);
|
89 |
|
\ | No newline at end of file |