@kne/form-creator 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +452 -127
- package/dist/index.css +150 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +1918 -325
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1828 -341
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en-US.js +35 -4
- package/dist/locale/en-US.js.map +1 -1
- package/dist/locale/en-US.modern.js +35 -4
- package/dist/locale/en-US.modern.js.map +1 -1
- package/dist/locale/zh-CN.js +37 -6
- package/dist/locale/zh-CN.js.map +1 -1
- package/dist/locale/zh-CN.modern.js +37 -6
- package/dist/locale/zh-CN.modern.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,11 +33,11 @@ npm i --save @kne/form-creator
|
|
|
33
33
|
#### 示例代码
|
|
34
34
|
|
|
35
35
|
- 配置式表单搭建(全屏)
|
|
36
|
-
-
|
|
36
|
+
- 通过模块列表添加/编辑/排序,右侧实时预览;默认示例含列表嵌套与选项切换
|
|
37
37
|
- _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],_JsonView(@kne/json-view)[import * as _JsonView from "@kne/json-view"],(@kne/json-view/dist/index.css)[import "@kne/json-view/dist/index.css"],antd(antd)[import antd from "antd"],_FormInfo(@kne/form-info)[import * as _FormInfo from "@kne/form-info"]
|
|
38
38
|
|
|
39
39
|
```jsx
|
|
40
|
-
const {default: FormCreator, defaultSchema, createBlock, createField, createStep} = _FormCreator;
|
|
40
|
+
const {default: FormCreator, defaultSchema, createBlock, createField, createStep, createChoiceOption} = _FormCreator;
|
|
41
41
|
const {default: JsonView} = _JsonView;
|
|
42
42
|
const {useState} = React;
|
|
43
43
|
const {Typography} = antd;
|
|
@@ -168,6 +168,167 @@ const BaseExample = () => {
|
|
|
168
168
|
})
|
|
169
169
|
]
|
|
170
170
|
}),
|
|
171
|
+
createBlock('list', {
|
|
172
|
+
title: '项目经历(含嵌套)',
|
|
173
|
+
name: 'projects',
|
|
174
|
+
addText: '添加项目',
|
|
175
|
+
minLength: 0,
|
|
176
|
+
list: [
|
|
177
|
+
createField({
|
|
178
|
+
type: 'Input',
|
|
179
|
+
name: 'projectName',
|
|
180
|
+
label: '项目名称',
|
|
181
|
+
rule: 'REQ',
|
|
182
|
+
props: {placeholder: '请输入项目名称'}
|
|
183
|
+
}),
|
|
184
|
+
createField({
|
|
185
|
+
type: 'Input',
|
|
186
|
+
name: 'role',
|
|
187
|
+
label: '担任角色',
|
|
188
|
+
props: {placeholder: '如:前端开发'}
|
|
189
|
+
})
|
|
190
|
+
],
|
|
191
|
+
itemBlocks: [
|
|
192
|
+
createBlock('object', {
|
|
193
|
+
name: 'period',
|
|
194
|
+
title: '项目周期',
|
|
195
|
+
column: 2,
|
|
196
|
+
list: [
|
|
197
|
+
createField({
|
|
198
|
+
type: 'DatePicker',
|
|
199
|
+
name: 'start',
|
|
200
|
+
label: '开始时间',
|
|
201
|
+
props: {placeholder: '请选择'}
|
|
202
|
+
}),
|
|
203
|
+
createField({
|
|
204
|
+
type: 'DatePicker',
|
|
205
|
+
name: 'end',
|
|
206
|
+
label: '结束时间',
|
|
207
|
+
props: {placeholder: '请选择'}
|
|
208
|
+
})
|
|
209
|
+
]
|
|
210
|
+
}),
|
|
211
|
+
createBlock('list', {
|
|
212
|
+
title: '项目成果',
|
|
213
|
+
name: 'achievements',
|
|
214
|
+
addText: '添加成果',
|
|
215
|
+
list: [
|
|
216
|
+
createField({
|
|
217
|
+
type: 'Input',
|
|
218
|
+
name: 'content',
|
|
219
|
+
label: '成果说明',
|
|
220
|
+
props: {placeholder: '请输入成果'}
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
})
|
|
224
|
+
]
|
|
225
|
+
}),
|
|
226
|
+
createBlock('choice', {
|
|
227
|
+
title: '客户类型',
|
|
228
|
+
mode: 'single',
|
|
229
|
+
selectorName: 'customerType',
|
|
230
|
+
selectorInData: true,
|
|
231
|
+
options: [
|
|
232
|
+
createChoiceOption({
|
|
233
|
+
id: 'enterprise',
|
|
234
|
+
title: '企业',
|
|
235
|
+
list: [
|
|
236
|
+
createField({
|
|
237
|
+
type: 'Input',
|
|
238
|
+
name: 'companyName',
|
|
239
|
+
label: '公司名',
|
|
240
|
+
rule: 'REQ',
|
|
241
|
+
props: {placeholder: '公司名称'}
|
|
242
|
+
}),
|
|
243
|
+
createField({
|
|
244
|
+
type: 'Input',
|
|
245
|
+
name: 'creditCode',
|
|
246
|
+
label: '信用代码',
|
|
247
|
+
props: {placeholder: '统一社会信用代码'}
|
|
248
|
+
})
|
|
249
|
+
]
|
|
250
|
+
}),
|
|
251
|
+
createChoiceOption({
|
|
252
|
+
id: 'person',
|
|
253
|
+
title: '个人',
|
|
254
|
+
list: [
|
|
255
|
+
createField({
|
|
256
|
+
type: 'Input',
|
|
257
|
+
name: 'idName',
|
|
258
|
+
label: '姓名',
|
|
259
|
+
rule: 'REQ',
|
|
260
|
+
props: {placeholder: '姓名'}
|
|
261
|
+
}),
|
|
262
|
+
createField({
|
|
263
|
+
type: 'Input',
|
|
264
|
+
name: 'idNo',
|
|
265
|
+
label: '证件号',
|
|
266
|
+
props: {placeholder: '证件号码'}
|
|
267
|
+
})
|
|
268
|
+
]
|
|
269
|
+
}),
|
|
270
|
+
createChoiceOption({
|
|
271
|
+
id: 'other',
|
|
272
|
+
title: '其他',
|
|
273
|
+
list: [
|
|
274
|
+
createField({
|
|
275
|
+
type: 'TextArea',
|
|
276
|
+
name: 'otherNote',
|
|
277
|
+
label: '说明',
|
|
278
|
+
block: true,
|
|
279
|
+
props: {rows: 3, placeholder: '补充说明'}
|
|
280
|
+
})
|
|
281
|
+
]
|
|
282
|
+
})
|
|
283
|
+
]
|
|
284
|
+
}),
|
|
285
|
+
createBlock('choice', {
|
|
286
|
+
title: '兴趣标签',
|
|
287
|
+
mode: 'multiple',
|
|
288
|
+
minLength: 1,
|
|
289
|
+
maxLength: 2,
|
|
290
|
+
selectorName: 'interests',
|
|
291
|
+
selectorInData: true,
|
|
292
|
+
options: [
|
|
293
|
+
createChoiceOption({
|
|
294
|
+
id: 'sports',
|
|
295
|
+
title: '运动',
|
|
296
|
+
list: [
|
|
297
|
+
createField({
|
|
298
|
+
type: 'Input',
|
|
299
|
+
name: 'sportsNote',
|
|
300
|
+
label: '擅长项目',
|
|
301
|
+
props: {placeholder: '如:篮球'}
|
|
302
|
+
})
|
|
303
|
+
]
|
|
304
|
+
}),
|
|
305
|
+
createChoiceOption({
|
|
306
|
+
id: 'music',
|
|
307
|
+
title: '音乐',
|
|
308
|
+
list: [
|
|
309
|
+
createField({
|
|
310
|
+
type: 'Input',
|
|
311
|
+
name: 'musicNote',
|
|
312
|
+
label: '偏好风格',
|
|
313
|
+
props: {placeholder: '如:古典'}
|
|
314
|
+
})
|
|
315
|
+
]
|
|
316
|
+
}),
|
|
317
|
+
createChoiceOption({
|
|
318
|
+
id: 'reading',
|
|
319
|
+
title: '阅读',
|
|
320
|
+
list: [
|
|
321
|
+
createField({
|
|
322
|
+
type: 'TextArea',
|
|
323
|
+
name: 'readingNote',
|
|
324
|
+
label: '近期书单',
|
|
325
|
+
block: true,
|
|
326
|
+
props: {rows: 2, placeholder: '选填'}
|
|
327
|
+
})
|
|
328
|
+
]
|
|
329
|
+
})
|
|
330
|
+
]
|
|
331
|
+
}),
|
|
171
332
|
createBlock('multiField', {
|
|
172
333
|
title: '备用联系方式',
|
|
173
334
|
name: 'backupContacts',
|
|
@@ -254,7 +415,7 @@ const BaseExample = () => {
|
|
|
254
415
|
<FormCreator value={schema} onChange={setSchema} />
|
|
255
416
|
<div style={{marginTop: 16}}>
|
|
256
417
|
<JsonView data={schema} theme="light" collapsedFrom={2} searchable={false} />
|
|
257
|
-
<Text type="secondary"
|
|
418
|
+
<Text type="secondary">初始示例已包含表单分组、列表、表格列表、列表嵌套、选项切换、多字段、分步等模块。</Text>
|
|
258
419
|
</div>
|
|
259
420
|
</div>;
|
|
260
421
|
};
|
|
@@ -365,100 +526,218 @@ render(<SchemaRenderExample />);
|
|
|
365
526
|
|
|
366
527
|
```
|
|
367
528
|
|
|
529
|
+
- 列表嵌套与选项切换
|
|
530
|
+
- 列表每一条里可再放分组或子列表;选项切换支持单选/多选,每个选项可添加填写项
|
|
531
|
+
- _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],_JsonView(@kne/json-view)[import * as _JsonView from "@kne/json-view"],(@kne/json-view/dist/index.css)[import "@kne/json-view/dist/index.css"],antd(antd)[import antd from "antd"]
|
|
532
|
+
|
|
533
|
+
```jsx
|
|
534
|
+
const { SchemaRenderer, createBlock, createField, createChoiceOption } = _FormCreator;
|
|
535
|
+
const { default: JsonView } = _JsonView;
|
|
536
|
+
const { useState } = React;
|
|
537
|
+
const { Alert, Space, Switch } = antd;
|
|
538
|
+
|
|
539
|
+
const NestedChoiceExample = () => {
|
|
540
|
+
const [multiple, setMultiple] = useState(false);
|
|
541
|
+
const [result, setResult] = useState(null);
|
|
542
|
+
|
|
543
|
+
const schema = {
|
|
544
|
+
actions: {
|
|
545
|
+
showSubmit: true,
|
|
546
|
+
showReset: true,
|
|
547
|
+
submitText: '提交',
|
|
548
|
+
resetText: '重置'
|
|
549
|
+
},
|
|
550
|
+
blocks: [
|
|
551
|
+
createBlock('list', {
|
|
552
|
+
title: '教育经历',
|
|
553
|
+
name: 'education',
|
|
554
|
+
addText: '添加教育经历',
|
|
555
|
+
minLength: 1,
|
|
556
|
+
list: [
|
|
557
|
+
createField({ type: 'Input', name: 'schoolName', label: '学校', rule: 'REQ', props: { placeholder: '学校名称' } }),
|
|
558
|
+
createField({ type: 'Input', name: 'major', label: '专业', props: { placeholder: '专业' } })
|
|
559
|
+
],
|
|
560
|
+
itemBlocks: [
|
|
561
|
+
createBlock('object', {
|
|
562
|
+
name: 'time',
|
|
563
|
+
title: '在校时间',
|
|
564
|
+
column: 2,
|
|
565
|
+
list: [
|
|
566
|
+
createField({ type: 'Input', name: 'startTime', label: '开始', props: { placeholder: '开始时间' } }),
|
|
567
|
+
createField({ type: 'Input', name: 'endTime', label: '结束', props: { placeholder: '结束时间' } })
|
|
568
|
+
]
|
|
569
|
+
}),
|
|
570
|
+
createBlock('list', {
|
|
571
|
+
title: '课程',
|
|
572
|
+
name: 'courses',
|
|
573
|
+
addText: '添加课程',
|
|
574
|
+
list: [createField({ type: 'Input', name: 'courseName', label: '课程名', props: { placeholder: '课程名' } })]
|
|
575
|
+
})
|
|
576
|
+
]
|
|
577
|
+
}),
|
|
578
|
+
createBlock('choice', {
|
|
579
|
+
title: '客户类型',
|
|
580
|
+
mode: multiple ? 'multiple' : 'single',
|
|
581
|
+
minLength: multiple ? 1 : undefined,
|
|
582
|
+
maxLength: multiple ? 2 : undefined,
|
|
583
|
+
selectorName: 'customerType',
|
|
584
|
+
selectorInData: true,
|
|
585
|
+
options: [
|
|
586
|
+
createChoiceOption({
|
|
587
|
+
id: 'enterprise',
|
|
588
|
+
title: '企业',
|
|
589
|
+
blocks: [
|
|
590
|
+
createBlock('formInfo', {
|
|
591
|
+
title: '企业信息',
|
|
592
|
+
column: 2,
|
|
593
|
+
list: [
|
|
594
|
+
createField({ type: 'Input', name: 'companyName', label: '公司名', rule: 'REQ', props: { placeholder: '公司名称' } }),
|
|
595
|
+
createField({ type: 'Input', name: 'creditCode', label: '信用代码', props: { placeholder: '统一社会信用代码' } })
|
|
596
|
+
]
|
|
597
|
+
})
|
|
598
|
+
]
|
|
599
|
+
}),
|
|
600
|
+
createChoiceOption({
|
|
601
|
+
id: 'person',
|
|
602
|
+
title: '个人',
|
|
603
|
+
blocks: [
|
|
604
|
+
createBlock('formInfo', {
|
|
605
|
+
title: '个人信息',
|
|
606
|
+
column: 2,
|
|
607
|
+
list: [
|
|
608
|
+
createField({ type: 'Input', name: 'idName', label: '姓名', rule: 'REQ', props: { placeholder: '姓名' } }),
|
|
609
|
+
createField({ type: 'Input', name: 'idNo', label: '证件号', props: { placeholder: '证件号码' } })
|
|
610
|
+
]
|
|
611
|
+
})
|
|
612
|
+
]
|
|
613
|
+
}),
|
|
614
|
+
createChoiceOption({
|
|
615
|
+
id: 'other',
|
|
616
|
+
title: '其他',
|
|
617
|
+
blocks: [
|
|
618
|
+
createBlock('formInfo', {
|
|
619
|
+
column: 1,
|
|
620
|
+
list: [createField({ type: 'TextArea', name: 'otherNote', label: '说明', block: true, props: { rows: 3, placeholder: '补充说明' } })]
|
|
621
|
+
})
|
|
622
|
+
]
|
|
623
|
+
})
|
|
624
|
+
]
|
|
625
|
+
})
|
|
626
|
+
]
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
return (
|
|
630
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
631
|
+
<Alert
|
|
632
|
+
type="info"
|
|
633
|
+
showIcon
|
|
634
|
+
message="列表嵌套与选项切换"
|
|
635
|
+
description={<span>列表每一条里可以再放分组信息或子列表;选项切换可设为「只能选一个」或「可以选多个」(多选可限制最少/最多几项),下方会显示对应填写内容。</span>}
|
|
636
|
+
/>
|
|
637
|
+
<Space>
|
|
638
|
+
<span>允许多选</span>
|
|
639
|
+
<Switch checked={multiple} onChange={setMultiple} />
|
|
640
|
+
</Space>
|
|
641
|
+
<SchemaRenderer
|
|
642
|
+
key={multiple ? 'multiple' : 'single'}
|
|
643
|
+
schema={schema}
|
|
644
|
+
formProps={{
|
|
645
|
+
onSubmit: data => setResult(data)
|
|
646
|
+
}}
|
|
647
|
+
/>
|
|
648
|
+
{result ? <JsonView data={result} theme="light" collapsedFrom={2} searchable={false} /> : null}
|
|
649
|
+
</Space>
|
|
650
|
+
);
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
render(<NestedChoiceExample />);
|
|
654
|
+
|
|
655
|
+
```
|
|
656
|
+
|
|
368
657
|
- 扩展组件与校验规则
|
|
369
|
-
- 通过
|
|
658
|
+
- 通过 preset({ rules, fields }) 一次扩展运行时校验、规则勾选面板与自定义填写项
|
|
370
659
|
- _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],_ReactFormAntd(@kne/react-form-antd)[import * as _ReactFormAntd from "@kne/react-form-antd"],_JsonView(@kne/json-view)[import * as _JsonView from "@kne/json-view"],(@kne/json-view/dist/index.css)[import "@kne/json-view/dist/index.css"],antd(antd)[import antd from "antd"]
|
|
371
660
|
|
|
372
661
|
```jsx
|
|
373
|
-
const {
|
|
374
|
-
|
|
375
|
-
registerField,
|
|
376
|
-
registerRulePreset,
|
|
377
|
-
defaultSchema,
|
|
378
|
-
createBlock,
|
|
379
|
-
createField
|
|
380
|
-
} = _FormCreator;
|
|
381
|
-
const { Rate, Slider, preset, RULES } = _ReactFormAntd;
|
|
662
|
+
const { default: FormCreator, preset, defaultSchema, createBlock, createField } = _FormCreator;
|
|
663
|
+
const { Rate, Slider } = _ReactFormAntd;
|
|
382
664
|
const { default: JsonView } = _JsonView;
|
|
383
665
|
const { useState } = React;
|
|
384
666
|
const { Alert, Typography, Space } = antd;
|
|
385
667
|
const { Text, Paragraph } = Typography;
|
|
386
668
|
|
|
387
|
-
//
|
|
669
|
+
// 一次 preset:运行时校验 + 编辑器规则面板 + 扩展填写项
|
|
388
670
|
preset({
|
|
389
|
-
rules:
|
|
390
|
-
// 身份证号(简化示例)
|
|
671
|
+
rules: {
|
|
391
672
|
ID_CARD: {
|
|
673
|
+
label: '身份证格式',
|
|
392
674
|
reg: /^\d{17}[\dXx]$/,
|
|
393
675
|
message: '%s格式不正确'
|
|
394
676
|
},
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// 2) 同步注册到 form-creator 规则勾选面板
|
|
407
|
-
registerRulePreset({ value: 'ID_CARD', label: '身份证格式' });
|
|
408
|
-
registerRulePreset({ value: 'RATE_MIN', label: '评分至少3星' });
|
|
409
|
-
|
|
410
|
-
// 3) 扩展自定义填写项:用 propsSchema 声明可编辑的额外参数
|
|
411
|
-
registerField('Rate', {
|
|
412
|
-
label: '评分',
|
|
413
|
-
groupName: '评价组件',
|
|
414
|
-
component: Rate,
|
|
415
|
-
defaultProps: { count: 5, allowHalf: false, allowClear: true },
|
|
416
|
-
propsSchema: [
|
|
417
|
-
{
|
|
418
|
-
name: 'count',
|
|
419
|
-
label: '星星总数',
|
|
420
|
-
type: 'number',
|
|
421
|
-
min: 1,
|
|
422
|
-
max: 10,
|
|
423
|
-
defaultValue: 5
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
name: 'allowHalf',
|
|
427
|
-
label: '允许半星',
|
|
428
|
-
type: 'boolean',
|
|
429
|
-
defaultValue: false
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
name: 'allowClear',
|
|
433
|
-
label: '允许清除',
|
|
434
|
-
type: 'boolean',
|
|
435
|
-
defaultValue: true
|
|
677
|
+
RATE_MIN: {
|
|
678
|
+
label: '评分至少3星',
|
|
679
|
+
validator: value => {
|
|
680
|
+
const score = Number(value) || 0;
|
|
681
|
+
return {
|
|
682
|
+
result: score >= 3,
|
|
683
|
+
errMsg: score >= 3 ? '' : '评分至少 3 星'
|
|
684
|
+
};
|
|
685
|
+
}
|
|
436
686
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
687
|
+
},
|
|
688
|
+
fields: {
|
|
689
|
+
Rate: {
|
|
690
|
+
label: '评分',
|
|
691
|
+
groupName: '评价组件',
|
|
692
|
+
component: Rate,
|
|
693
|
+
defaultProps: { count: 5, allowHalf: false, allowClear: true },
|
|
694
|
+
propsSchema: [
|
|
695
|
+
{
|
|
696
|
+
name: 'count',
|
|
697
|
+
label: '星星总数',
|
|
698
|
+
type: 'number',
|
|
699
|
+
min: 1,
|
|
700
|
+
max: 10,
|
|
701
|
+
defaultValue: 5
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
name: 'allowHalf',
|
|
705
|
+
label: '允许半星',
|
|
706
|
+
type: 'boolean',
|
|
707
|
+
defaultValue: false
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
name: 'allowClear',
|
|
711
|
+
label: '允许清除',
|
|
712
|
+
type: 'boolean',
|
|
713
|
+
defaultValue: true
|
|
714
|
+
}
|
|
458
715
|
]
|
|
459
716
|
},
|
|
460
|
-
|
|
461
|
-
|
|
717
|
+
Slider: {
|
|
718
|
+
label: '滑块',
|
|
719
|
+
component: Slider,
|
|
720
|
+
defaultProps: { min: 0, max: 100, step: 1 },
|
|
721
|
+
propsSchema: [
|
|
722
|
+
{ name: 'min', label: '最小值', type: 'number', defaultValue: 0 },
|
|
723
|
+
{ name: 'max', label: '最大值', type: 'number', defaultValue: 100 },
|
|
724
|
+
{ name: 'step', label: '步长', type: 'number', min: 0, defaultValue: 1 },
|
|
725
|
+
{
|
|
726
|
+
name: 'tooltipPlacement',
|
|
727
|
+
label: '提示位置',
|
|
728
|
+
type: 'select',
|
|
729
|
+
defaultValue: 'top',
|
|
730
|
+
options: [
|
|
731
|
+
{ label: '上', value: 'top' },
|
|
732
|
+
{ label: '下', value: 'bottom' },
|
|
733
|
+
{ label: '左', value: 'left' },
|
|
734
|
+
{ label: '右', value: 'right' }
|
|
735
|
+
]
|
|
736
|
+
},
|
|
737
|
+
{ name: 'dots', label: '显示刻度点', type: 'boolean', defaultValue: false }
|
|
738
|
+
]
|
|
739
|
+
}
|
|
740
|
+
}
|
|
462
741
|
});
|
|
463
742
|
|
|
464
743
|
const PresetExtendExample = () => {
|
|
@@ -467,7 +746,7 @@ const PresetExtendExample = () => {
|
|
|
467
746
|
blocks: [
|
|
468
747
|
createBlock('formInfo', {
|
|
469
748
|
title: '扩展字段与校验',
|
|
470
|
-
subtitle: '演示
|
|
749
|
+
subtitle: '演示 preset({ rules, fields }) 一次注册',
|
|
471
750
|
column: 2,
|
|
472
751
|
list: [
|
|
473
752
|
createField({
|
|
@@ -507,13 +786,10 @@ const PresetExtendExample = () => {
|
|
|
507
786
|
description={
|
|
508
787
|
<div>
|
|
509
788
|
<Paragraph style={{ marginBottom: 4 }}>
|
|
510
|
-
|
|
511
|
-
</Paragraph>
|
|
512
|
-
<Paragraph style={{ marginBottom: 4 }}>
|
|
513
|
-
2. <Text code>registerRulePreset</Text>:把规则挂到「填写规则」勾选面板
|
|
789
|
+
调用 <Text code>{'preset({ rules, fields })'}</Text> 即可同时注册:运行时校验(@kne/react-form-antd)、编辑器「填写规则」勾选面板、扩展填写项类型。
|
|
514
790
|
</Paragraph>
|
|
515
791
|
<Paragraph style={{ marginBottom: 0 }}>
|
|
516
|
-
|
|
792
|
+
规则项在 <Text code>rules</Text> 中写 <Text code>label</Text> + 校验定义(<Text code>reg/message</Text> 或 <Text code>validator</Text>);字段在 <Text code>fields</Text> 中按 type 配置,支持 <Text code>groupName</Text> 与 <Text code>propsSchema</Text>。
|
|
517
793
|
</Paragraph>
|
|
518
794
|
</div>
|
|
519
795
|
}
|
|
@@ -631,11 +907,15 @@ import { Form, SubmitButton } from '@kne/form-info';
|
|
|
631
907
|
},
|
|
632
908
|
blocks: [{
|
|
633
909
|
id: string,
|
|
634
|
-
kind: 'formInfo' | 'list' | 'tableList' | 'multiField' | 'steps',
|
|
910
|
+
kind: 'formInfo' | 'list' | 'tableList' | 'multiField' | 'object' | 'choice' | 'steps',
|
|
635
911
|
title?, subtitle?, column?, gap?, bordered?, important?,
|
|
636
912
|
name?, label?, addText?, maxLength?, minLength?, fieldType?, autoStep?,
|
|
913
|
+
mode?, selectorName?, selectorInData?, discriminator?,
|
|
637
914
|
list?: [{ id, type, name, label, tips?, description?, rule?, block?, hidden?, props? }],
|
|
638
|
-
|
|
915
|
+
itemBlocks?: Block[], // list:列表项内子模块
|
|
916
|
+
blocks?: Block[], // formInfo / object:子模块
|
|
917
|
+
options?: [{ id, title, list?, blocks?: Block[] }], // choice
|
|
918
|
+
items?: [{ id, title, column, list: [...], blocks?: Block[] }] // steps 专用
|
|
639
919
|
}]
|
|
640
920
|
}
|
|
641
921
|
```
|
|
@@ -645,11 +925,15 @@ import { Form, SubmitButton } from '@kne/form-info';
|
|
|
645
925
|
|
|
646
926
|
| kind | 说明 | 主要参数 |
|
|
647
927
|
|------|------|----------|
|
|
648
|
-
| formInfo | 表单信息区块 | title, subtitle, column, gap, bordered, list |
|
|
649
|
-
| list | 动态列表 | name, title, important, bordered, maxLength, list |
|
|
650
|
-
| tableList | 表格列表 | name, title, bordered, maxLength, list |
|
|
651
|
-
|
|
|
652
|
-
|
|
|
928
|
+
| formInfo | 表单信息区块 | title, subtitle, column, gap, bordered, list, **blocks** |
|
|
929
|
+
| list | 动态列表 | name, title, important, bordered, maxLength, list, **itemBlocks** |
|
|
930
|
+
| tableList | 表格列表 | name, title, bordered, maxLength, list(不支持子模块) |
|
|
931
|
+
| object | 对象分组 | name, title, column, gap, list(字段名渲染为 `name.field`), **blocks** |
|
|
932
|
+
| choice | 选项分支 | title, **mode**(`single`\|`multiple`), **minLength** / **maxLength**(仅多选:最少/最多选几项), selectorName, selectorInData, options[{ title, list, **blocks** }] |
|
|
933
|
+
| multiField | 同类型多值 | name, label, fieldType, addText(不支持子模块) |
|
|
934
|
+
| steps | 步骤表单 | title, subtitle, bordered, autoStep, items[{ title, column, list, **blocks** }] |
|
|
935
|
+
|
|
936
|
+
`choice`:顶部同一条选项 UI;`single` 只挂载当前选项内容,`multiple` 平铺所有选中项。多选时可配置 `minLength` / `maxLength` 限制最少、最多选择几个(提交时校验;达到上限后未选项禁用)。JSON Schema 的 oneOf/anyOf 可分别映射为 `mode: 'single'/'multiple'`。`allOf` 无需独立 kind,展开为多个 sibling blocks 即可。
|
|
653
937
|
|
|
654
938
|
兼容旧版:若仅有顶层 `list` 且无 `blocks`,会自动迁移为一个 `formInfo` 区块。
|
|
655
939
|
|
|
@@ -660,51 +944,92 @@ import { Form, SubmitButton } from '@kne/form-info';
|
|
|
660
944
|
|
|
661
945
|
#### 工具方法
|
|
662
946
|
|
|
663
|
-
- `createBlock(kind)` / `createStep()` / `normalizeSchema(schema)`
|
|
664
|
-
- `
|
|
665
|
-
- `registerRulePreset({ value, label })` 扩展「填写规则」勾选面板中的规则项
|
|
947
|
+
- `createBlock(kind)` / `createStep()` / `createChoiceOption()` / `normalizeSchema(schema)`
|
|
948
|
+
- `preset({ rules, fields })` 一次注册扩展规则与填写项(推荐)
|
|
666
949
|
- `parseRuleString(rule)` / `buildRuleString(config)` 校验规则字符串解析/组装
|
|
667
950
|
|
|
668
|
-
####
|
|
951
|
+
#### preset(推荐)
|
|
952
|
+
|
|
953
|
+
应用入口调用一次,同时完成:
|
|
669
954
|
|
|
670
|
-
|
|
955
|
+
1. **运行时校验**:合并进 `@kne/react-form-antd` 的 `RULES`
|
|
956
|
+
2. **编辑器规则面板**:写入「填写规则」勾选列表
|
|
957
|
+
3. **扩展填写项**:注册到字段类型 registry
|
|
671
958
|
|
|
672
|
-
|
|
959
|
+
内置规则 `REQ` / `TEL` / `EMAIL` 已内置,无需重复配置;传入同名 key 可覆盖运行时规则并更新编辑器 label。
|
|
673
960
|
|
|
674
961
|
```js
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
groupName: '评价组件', // 自定义分组;不传则归入「扩展字段」
|
|
678
|
-
component: Rate,
|
|
679
|
-
defaultProps: { count: 5 },
|
|
680
|
-
propsSchema: [
|
|
681
|
-
{ name: 'count', label: '星星总数', type: 'number', min: 1, max: 10, defaultValue: 5 }
|
|
682
|
-
]
|
|
683
|
-
});
|
|
962
|
+
import { preset } from '@kne/form-creator';
|
|
963
|
+
import { Rate, Slider } from '@kne/react-form-antd';
|
|
684
964
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
{ name: 'max', label: '最大值', type: 'number', defaultValue: 100 },
|
|
692
|
-
{ name: 'step', label: '步长', type: 'number', min: 0, defaultValue: 1 },
|
|
693
|
-
{
|
|
694
|
-
name: 'tooltipPlacement',
|
|
695
|
-
label: '提示位置',
|
|
696
|
-
type: 'select',
|
|
697
|
-
defaultValue: 'top',
|
|
698
|
-
options: [
|
|
699
|
-
{ label: '上', value: 'top' },
|
|
700
|
-
{ label: '下', value: 'bottom' }
|
|
701
|
-
]
|
|
965
|
+
preset({
|
|
966
|
+
rules: {
|
|
967
|
+
ID_CARD: {
|
|
968
|
+
label: '身份证格式',
|
|
969
|
+
reg: /^\d{17}[\dXx]$/,
|
|
970
|
+
message: '%s格式不正确'
|
|
702
971
|
},
|
|
703
|
-
|
|
704
|
-
|
|
972
|
+
RATE_MIN: {
|
|
973
|
+
label: '评分至少3星',
|
|
974
|
+
validator: value => ({
|
|
975
|
+
result: Number(value) >= 3,
|
|
976
|
+
errMsg: Number(value) >= 3 ? '' : '评分至少 3 星'
|
|
977
|
+
})
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
fields: {
|
|
981
|
+
Rate: {
|
|
982
|
+
label: '评分',
|
|
983
|
+
groupName: '评价组件',
|
|
984
|
+
component: Rate,
|
|
985
|
+
defaultProps: { count: 5 },
|
|
986
|
+
propsSchema: [
|
|
987
|
+
{ name: 'count', label: '星星总数', type: 'number', min: 1, max: 10, defaultValue: 5 }
|
|
988
|
+
]
|
|
989
|
+
}
|
|
990
|
+
}
|
|
705
991
|
});
|
|
706
992
|
```
|
|
707
993
|
|
|
994
|
+
| 配置 | 类型 | 说明 |
|
|
995
|
+
|------|------|------|
|
|
996
|
+
| `rules` | `Record<string, RuleDef>` | key 为规则 token;`RuleDef` 含 `label` + `reg/message` 或 `validator` |
|
|
997
|
+
| `fields` | `Record<string, FieldDef>` | key 为字段 type;见下方 FieldDef |
|
|
998
|
+
|
|
999
|
+
**FieldDef** 常用字段:`label`、`component`、`groupName`、`defaultProps`、`propsSchema`、`hasOptions`、`hasFieldProps` 等。
|
|
1000
|
+
|
|
1001
|
+
扩展填写项时,用 `fields` 内的 `propsSchema` 声明可编辑的额外参数(写入字段 `props`),编辑器会按声明自动生成「填写项设置」表单:
|
|
1002
|
+
|
|
1003
|
+
```js
|
|
1004
|
+
fields: {
|
|
1005
|
+
Slider: {
|
|
1006
|
+
label: '滑块',
|
|
1007
|
+
component: Slider,
|
|
1008
|
+
defaultProps: { min: 0, max: 100, step: 1 },
|
|
1009
|
+
propsSchema: [
|
|
1010
|
+
{ name: 'min', label: '最小值', type: 'number', defaultValue: 0 },
|
|
1011
|
+
{ name: 'max', label: '最大值', type: 'number', defaultValue: 100 },
|
|
1012
|
+
{ name: 'step', label: '步长', type: 'number', min: 0, defaultValue: 1 },
|
|
1013
|
+
{
|
|
1014
|
+
name: 'tooltipPlacement',
|
|
1015
|
+
label: '提示位置',
|
|
1016
|
+
type: 'select',
|
|
1017
|
+
defaultValue: 'top',
|
|
1018
|
+
options: [
|
|
1019
|
+
{ label: '上', value: 'top' },
|
|
1020
|
+
{ label: '下', value: 'bottom' }
|
|
1021
|
+
]
|
|
1022
|
+
},
|
|
1023
|
+
{ name: 'dots', label: '显示刻度点', type: 'boolean' }
|
|
1024
|
+
]
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
#### 扩展组件与校验(示例见「扩展组件与校验规则」)
|
|
1030
|
+
|
|
1031
|
+
使用 `preset({ rules, fields })` 即可,无需再单独调用 react-form-antd 的 `preset`。
|
|
1032
|
+
|
|
708
1033
|
`propsSchema` 项约定:
|
|
709
1034
|
|
|
710
1035
|
| 字段 | 说明 |
|