@@ -39,21 +39,47 @@ export function useFormFieldsPermission() {
39
39
fieldsPermissionConfig . value =
40
40
cloneDeep ( nodeFormFields ) || getDefaultFieldsPermission ( unref ( formFields ) )
41
41
}
42
- // 获取默认的表单权限。 所有字段只读
42
+ // 默认的表单权限: 获取表单的所有字段,设置字段默认权限为只读
43
43
const getDefaultFieldsPermission = ( formFields ?: string [ ] ) => {
44
44
const defaultFieldsPermission : Array < Record < string , string > > = [ ]
45
45
if ( formFields ) {
46
46
formFields . forEach ( ( fieldStr : string ) => {
47
- const { field, title } = JSON . parse ( fieldStr )
48
- defaultFieldsPermission . push ( {
49
- field,
50
- title,
51
- permission : '1' // 只读
52
- } )
47
+ parseFieldsSetDefaultPermission ( JSON . parse ( fieldStr ) , defaultFieldsPermission )
53
48
} )
54
49
}
55
50
return defaultFieldsPermission
56
51
}
52
+ // 解析字段。赋给默认权限
53
+ const parseFieldsSetDefaultPermission = (
54
+ rule : Record < string , any > ,
55
+ fieldsPermission : Array < Record < string , string > > ,
56
+ parentTitle : string = ''
57
+ ) => {
58
+ const { type, field, title : tempTitle , children } = rule
59
+ if ( field && tempTitle ) {
60
+ let title = tempTitle
61
+ if ( parentTitle ) {
62
+ title = `${ parentTitle } .${ tempTitle } `
63
+ }
64
+ fieldsPermission . push ( {
65
+ field,
66
+ title,
67
+ permission : '1' // 只读
68
+ } )
69
+ // TODO 子表单 需要处理子表单字段
70
+ // if (type === 'group' && rule.props?.rule && Array.isArray(rule.props.rule)) {
71
+ // // 解析子表单的字段
72
+ // rule.props.rule.forEach((item) => {
73
+ // parseFieldsSetDefaultPermission(item, fieldsPermission, title)
74
+ // })
75
+ // }
76
+ }
77
+ if ( children && Array . isArray ( children ) ) {
78
+ children . forEach ( ( rule ) => {
79
+ parseFieldsSetDefaultPermission ( rule , fieldsPermission )
80
+ } )
81
+ }
82
+ }
57
83
58
84
return {
59
85
formType,
0 commit comments