Skip to content

Commit 13b3715

Browse files
committed
feat: 修复数据引用带了的副作用
1 parent 7a172b3 commit 13b3715

File tree

4 files changed

+513
-33
lines changed

4 files changed

+513
-33
lines changed

docs/form-render/api-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ group:
4646
| setValues | 外部手动修改 formData,用于已填写的表单的数据回填 | `(formData: any) => void` |
4747
| setValueByPath | 外部修改指定单个 field 的数据(原名 onItemChange) | `(path: Path, value: any) => void` |
4848
| setSchemaByPath | 指定路径修改 schema | `(path: Path, schema: any) => void` |
49-
| setSchema | 指定多个路径修改 schema | `({ path: value }) => void` |
49+
| setSchema | 指定多个路径修改 schema,cover 传true将直接替换 schema | `({ path: value }, cover?: boolean) => void` |
5050
| getValues | 获取表单内部维护的数据, 如果参数为空则返回当前所有数据 | `(nameList?: Path[], filterFunc?: (meta: { touched: boolean, validating: boolean }) => boolean) => any` |
5151
| getHiddenValues | 获取隐藏的表单数据 | `() => any` |
5252
| getSchema | 获取表单的 schema | `()=> object` |

docs/form-render/index.md

Lines changed: 131 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,146 @@ npm i form-render --save
4242
*/
4343
import React from 'react';
4444
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+
};
4692

4793
export default () => {
4894
const form = useForm();
4995

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+
},
52117
};
53118

54119
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+
)
63124
}
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+
// }
64182
```
65183

66-
**类组件**
184+
<!-- **类组件**
67185
68186
对于使用类组件的同学,可以使用 `connectForm` 替代 `useForm` hooks。
69187
@@ -106,4 +224,4 @@ export default connectForm(Demo);
106224
107225
<div>
108226
<img src="https://gw.alipayobjects.com/mdn/rms_e18934/afts/img/A*4QYNTbKU6xAAAAAAAAAAAABkARQnAQ?raw=true" width="80%"/>
109-
</div>
227+
</div> -->

0 commit comments

Comments
 (0)