提交 | 用户 | 时间
|
820397
|
1 |
export function makeRequiredRule() { |
H |
2 |
return { |
|
3 |
type: 'Required', |
|
4 |
field: 'formCreate$required', |
|
5 |
title: '是否必填' |
|
6 |
} |
|
7 |
} |
|
8 |
|
|
9 |
export const localeProps = (t, prefix, rules) => { |
|
10 |
return rules.map((rule) => { |
|
11 |
if (rule.field === 'formCreate$required') { |
|
12 |
rule.title = t('props.required') || rule.title |
|
13 |
} else if (rule.field && rule.field !== '_optionType') { |
|
14 |
rule.title = t('components.' + prefix + '.' + rule.field) || rule.title |
|
15 |
} |
|
16 |
return rule |
|
17 |
}) |
|
18 |
} |
3e359e
|
19 |
|
H |
20 |
/** |
|
21 |
* 解析表单组件的 field, title 等字段(递归,如果组件包含子组件) |
|
22 |
* |
|
23 |
* @param rule 组件的生成规则 https://www.form-create.com/v3/guide/rule |
|
24 |
* @param fields 解析后表单组件字段 |
|
25 |
* @param parentTitle 如果是子表单,子表单的标题,默认为空 |
|
26 |
*/ |
|
27 |
export const parseFormFields = ( |
|
28 |
rule: Record<string, any>, |
|
29 |
fields: Array<Record<string, any>> = [], |
|
30 |
parentTitle: string = '' |
|
31 |
) => { |
|
32 |
const { type, field, $required, title: tempTitle, children } = rule |
|
33 |
if (field && tempTitle) { |
|
34 |
let title = tempTitle |
|
35 |
if (parentTitle) { |
|
36 |
title = `${parentTitle}.${tempTitle}` |
|
37 |
} |
|
38 |
let required = false |
|
39 |
if ($required) { |
|
40 |
required = true |
|
41 |
} |
|
42 |
fields.push({ |
|
43 |
field, |
|
44 |
title, |
|
45 |
type, |
|
46 |
required |
|
47 |
}) |
|
48 |
// TODO 子表单 需要处理子表单字段 |
|
49 |
// if (type === 'group' && rule.props?.rule && Array.isArray(rule.props.rule)) { |
|
50 |
// // 解析子表单的字段 |
|
51 |
// rule.props.rule.forEach((item) => { |
|
52 |
// parseFields(item, fieldsPermission, title) |
|
53 |
// }) |
|
54 |
// } |
|
55 |
} |
|
56 |
if (children && Array.isArray(children)) { |
|
57 |
children.forEach((rule) => { |
|
58 |
parseFormFields(rule, fields) |
|
59 |
}) |
|
60 |
} |
|
61 |
} |