Skip to content

Commit fe2ac97

Browse files
committed
refactor: 使用Simple设计器的useFormFieldsPermission
1 parent 4bd0208 commit fe2ac97

File tree

1 file changed

+6
-67
lines changed

1 file changed

+6
-67
lines changed

src/components/bpmnProcessDesigner/package/penal/custom-config/components/UserTaskCustomConfig.vue

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ import {
175175
DEFAULT_BUTTON_SETTING,
176176
FieldPermissionType,
177177
APPROVE_TYPE,
178-
ApproveType
178+
ApproveType,
179+
ButtonSetting
179180
} from '@/components/SimpleProcessDesignerV2/src/consts'
180181
import * as UserApi from '@/api/system/user'
181-
import { cloneDeep } from 'lodash-es'
182+
import { useFormFieldsPermission } from '@/components/SimpleProcessDesignerV2/src/node'
182183
183184
defineOptions({ name: 'ElementCustomConfig4UserTask' })
184185
const props = defineProps({
@@ -206,8 +207,7 @@ const assignEmptyUserIds = ref()
206207
207208
// 操作按钮
208209
const buttonsSettingEl = ref()
209-
const { buttonsSetting, btnDisplayNameEdit, changeBtnDisplayName, btnDisplayNameBlurEvent } =
210-
useButtonsSetting()
210+
const { btnDisplayNameEdit, changeBtnDisplayName, btnDisplayNameBlurEvent } = useButtonsSetting()
211211
212212
// 字段权限
213213
const fieldsPermissionEl = ref([])
@@ -300,6 +300,8 @@ const resetCustomConfigList = () => {
300300
)
301301
fieldsPermissionEl.value = []
302302
getNodeConfigFormFields()
303+
// 由于默认添加了发起人元素,这里需要删掉
304+
fieldsPermissionConfig.value = fieldsPermissionConfig.value.slice(1)
303305
fieldsPermissionConfig.value.forEach((element) => {
304306
element.permission =
305307
fieldsPermissionList?.find((obj) => obj.field === element.field)?.permission ?? '1'
@@ -454,69 +456,6 @@ function useButtonsSetting() {
454456
}
455457
}
456458
457-
// 表单字段权限设置
458-
function useFormFieldsPermission(defaultPermission) {
459-
// 字段权限配置. 需要有 field, title, permissioin 属性
460-
const fieldsPermissionConfig = ref<Array<Record<string, string>>>([])
461-
462-
const formType = inject<Ref<number>>('formType') // 表单类型
463-
464-
const formFields = inject<Ref<string[]>>('formFields') // 流程表单字段
465-
466-
const getNodeConfigFormFields = (nodeFormFields?: Array<Record<string, string>>) => {
467-
nodeFormFields = toRaw(nodeFormFields)
468-
fieldsPermissionConfig.value =
469-
cloneDeep(nodeFormFields) || getDefaultFieldsPermission(unref(formFields))
470-
}
471-
// 默认的表单权限: 获取表单的所有字段,设置字段默认权限为只读
472-
const getDefaultFieldsPermission = (formFields?: string[]) => {
473-
const defaultFieldsPermission: Array<Record<string, string>> = []
474-
if (formFields) {
475-
formFields.forEach((fieldStr: string) => {
476-
parseFieldsSetDefaultPermission(JSON.parse(fieldStr), defaultFieldsPermission)
477-
})
478-
}
479-
return defaultFieldsPermission
480-
}
481-
// 解析字段。赋给默认权限
482-
const parseFieldsSetDefaultPermission = (
483-
rule: Record<string, any>,
484-
fieldsPermission: Array<Record<string, string>>,
485-
parentTitle: string = ''
486-
) => {
487-
const { /**type,*/ field, title: tempTitle, children } = rule
488-
if (field && tempTitle) {
489-
let title = tempTitle
490-
if (parentTitle) {
491-
title = `${parentTitle}.${tempTitle}`
492-
}
493-
fieldsPermission.push({
494-
field,
495-
title,
496-
permission: defaultPermission
497-
})
498-
// TODO 子表单 需要处理子表单字段
499-
// if (type === 'group' && rule.props?.rule && Array.isArray(rule.props.rule)) {
500-
// // 解析子表单的字段
501-
// rule.props.rule.forEach((item) => {
502-
// parseFieldsSetDefaultPermission(item, fieldsPermission, title)
503-
// })
504-
// }
505-
}
506-
if (children && Array.isArray(children)) {
507-
children.forEach((rule) => {
508-
parseFieldsSetDefaultPermission(rule, fieldsPermission)
509-
})
510-
}
511-
}
512-
513-
return {
514-
formType,
515-
fieldsPermissionConfig,
516-
getNodeConfigFormFields
517-
}
518-
}
519-
520459
const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
521460
onMounted(async () => {
522461
// 获得用户列表

0 commit comments

Comments
 (0)