@@ -42,28 +42,146 @@ npm i form-render --save
42
42
*/
43
43
import React from ' react' ;
44
44
import FormRender , { useForm } from ' form-render' ;
45
- import schema from ' ./schema/simple' ;
45
+ // import schema from './schema/simple';
46
+
47
+
48
+ const schema = {
49
+ type: ' object' ,
50
+ properties: {
51
+ countryCode: {
52
+ type: ' number' ,
53
+ placeholder: ' 区域-目的地' ,
54
+ widget: ' select' ,
55
+ width: ' 50%' ,
56
+ required: true ,
57
+ props: {}
58
+ },
59
+ cityCode: {
60
+ type: ' number' ,
61
+ placeholder: ' 区域-城市' ,
62
+ widget: ' select' ,
63
+ width: ' 50%' ,
64
+ props: {}
65
+ },
66
+ subConfigValue: {
67
+ title: ' 热门日期' ,
68
+ type: ' array' ,
69
+ widget: ' simpleList' ,
70
+ props: {
71
+ hideCopy: true ,
72
+ delConfirmProps: {
73
+ overlayClassName: ' del-confirm-hot-date'
74
+ }
75
+ },
76
+ items: {
77
+ type: ' object' ,
78
+ properties: {
79
+ date: {
80
+ type: ' range' ,
81
+ widget: ' dateRange' ,
82
+ required: true ,
83
+ props: {}
84
+ }
85
+ }
86
+ }
87
+ }
88
+ },
89
+ displayType: " row" ,
90
+ labelWidth: 100 ,
91
+ };
46
92
47
93
export default () => {
48
94
const form = useForm ();
49
95
50
- const onFinish = (formData ) => {
51
- console .log (' formData:' , formData);
96
+ const onMount = () => {
97
+ debugger ;
98
+ form .setSchemaByPath (' countryCode' , {
99
+ props: {
100
+ options: [{ value: 1 , label: 1 }],
101
+ },
102
+ });
103
+ };
104
+
105
+ const watch = {
106
+ countryCode : (value : string ) => {
107
+ // form.setValues({ cityCode: undefined });
108
+ // form.setSchemaByPath('cityCode', {
109
+ // props: {
110
+ // options: cityMap[value].map((item: any) => ({
111
+ // label: item.provinceName,
112
+ // value: item.provinceCode,
113
+ // })),
114
+ // },
115
+ // });
116
+ },
52
117
};
53
118
54
119
return (
55
- < FormRender
56
- form= {form}
57
- schema= {schema}
58
- onFinish= {onFinish}
59
- maxWidth= {360 }
60
- footer= {true }
61
- / >
62
- );
120
+ < FormRender form= {form} schema= {schema} onMount= {onMount} watch= {watch} / >
121
+
122
+
123
+ )
63
124
}
125
+ // export default () => {
126
+ // const form = useForm();
127
+
128
+ // const onFinish = (formData) => {
129
+ // console.log('formData:', formData);
130
+ // };
131
+
132
+ // return (
133
+ // <FormRender
134
+ // form={form}
135
+ // schema={schema}
136
+ // onFinish={onFinish}
137
+ // maxWidth={360}
138
+ // footer={true}
139
+ // watch={{
140
+ // "#": (allValues, changedValues) => {
141
+ // // '#': () => {} 等同于 onValuesChange
142
+ // // console.log('表单 allValues:', allValues);
143
+ // setTimeout(() => {
144
+ // form.setSchema(
145
+ // {
146
+ // type: "object",
147
+ // displayType: "row",
148
+ // column: 2,
149
+ // properties: {
150
+ // input12: {
151
+ // title: "输入框xxxx",
152
+ // displayType: "row",
153
+ // type: "string",
154
+ // widget: "input",
155
+ // },
156
+ // number12: {
157
+ // title: "数字输入框",
158
+ // type: "number",
159
+ // widget: "inputNumber",
160
+ // },
161
+ // select12: {
162
+ // title: "下啦单选",
163
+ // widget: "select",
164
+ // props: {
165
+ // options: [
166
+ // { label: "东", value: "east" },
167
+ // { label: "西", value: "west" },
168
+ // ],
169
+ // },
170
+ // },
171
+ // },
172
+ // },
173
+ // true
174
+ // );
175
+ // }, 0);
176
+
177
+ // }
178
+ // }}
179
+ // />
180
+ // );
181
+ // }
64
182
```
65
183
66
- ** 类组件**
184
+ <!-- **类组件**
67
185
68
186
对于使用类组件的同学,可以使用 `connectForm` 替代 `useForm` hooks。
69
187
@@ -106,4 +224,4 @@ export default connectForm(Demo);
106
224
107
225
<div>
108
226
<img src="https://gw.alipayobjects.com/mdn/rms_e18934/afts/img/A*4QYNTbKU6xAAAAAAAAAAAABkARQnAQ?raw=true" width="80%"/>
109
- </div >
227
+ </div> -->
0 commit comments