Skip to content

Commit 7cb68da

Browse files
committed
仿钉钉流程设计器- 复杂表单字段解析
1 parent 3a5c93f commit 7cb68da

File tree

1 file changed

+33
-7
lines changed
  • src/components/SimpleProcessDesignerV2/src

1 file changed

+33
-7
lines changed

src/components/SimpleProcessDesignerV2/src/node.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,47 @@ export function useFormFieldsPermission() {
3939
fieldsPermissionConfig.value =
4040
cloneDeep(nodeFormFields) || getDefaultFieldsPermission(unref(formFields))
4141
}
42-
// 获取默认的表单权限。 所有字段只读
42+
// 默认的表单权限: 获取表单的所有字段,设置字段默认权限为只读
4343
const getDefaultFieldsPermission = (formFields?: string[]) => {
4444
const defaultFieldsPermission: Array<Record<string, string>> = []
4545
if (formFields) {
4646
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)
5348
})
5449
}
5550
return defaultFieldsPermission
5651
}
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+
}
5783

5884
return {
5985
formType,

0 commit comments

Comments
 (0)