From fe2ac97f9da4d95b2eb5ebbce7cec11a5c4533a6 Mon Sep 17 00:00:00 2001 From: Lesan <1960681385@qq.com> Date: Wed, 11 Dec 2024 09:18:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8Simple=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=99=A8=E7=9A=84useFormFieldsPermission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/UserTaskCustomConfig.vue | 73 ++----------------- 1 file changed, 6 insertions(+), 67 deletions(-) diff --git a/src/components/bpmnProcessDesigner/package/penal/custom-config/components/UserTaskCustomConfig.vue b/src/components/bpmnProcessDesigner/package/penal/custom-config/components/UserTaskCustomConfig.vue index eae04778..ba385145 100644 --- a/src/components/bpmnProcessDesigner/package/penal/custom-config/components/UserTaskCustomConfig.vue +++ b/src/components/bpmnProcessDesigner/package/penal/custom-config/components/UserTaskCustomConfig.vue @@ -175,10 +175,11 @@ import { DEFAULT_BUTTON_SETTING, FieldPermissionType, APPROVE_TYPE, - ApproveType + ApproveType, + ButtonSetting } from '@/components/SimpleProcessDesignerV2/src/consts' import * as UserApi from '@/api/system/user' -import { cloneDeep } from 'lodash-es' +import { useFormFieldsPermission } from '@/components/SimpleProcessDesignerV2/src/node' defineOptions({ name: 'ElementCustomConfig4UserTask' }) const props = defineProps({ @@ -206,8 +207,7 @@ const assignEmptyUserIds = ref() // 操作按钮 const buttonsSettingEl = ref() -const { buttonsSetting, btnDisplayNameEdit, changeBtnDisplayName, btnDisplayNameBlurEvent } = - useButtonsSetting() +const { btnDisplayNameEdit, changeBtnDisplayName, btnDisplayNameBlurEvent } = useButtonsSetting() // 字段权限 const fieldsPermissionEl = ref([]) @@ -300,6 +300,8 @@ const resetCustomConfigList = () => { ) fieldsPermissionEl.value = [] getNodeConfigFormFields() + // 由于默认添加了发起人元素,这里需要删掉 + fieldsPermissionConfig.value = fieldsPermissionConfig.value.slice(1) fieldsPermissionConfig.value.forEach((element) => { element.permission = fieldsPermissionList?.find((obj) => obj.field === element.field)?.permission ?? '1' @@ -454,69 +456,6 @@ function useButtonsSetting() { } } -// 表单字段权限设置 -function useFormFieldsPermission(defaultPermission) { - // 字段权限配置. 需要有 field, title, permissioin 属性 - const fieldsPermissionConfig = ref>>([]) - - const formType = inject>('formType') // 表单类型 - - const formFields = inject>('formFields') // 流程表单字段 - - const getNodeConfigFormFields = (nodeFormFields?: Array>) => { - nodeFormFields = toRaw(nodeFormFields) - fieldsPermissionConfig.value = - cloneDeep(nodeFormFields) || getDefaultFieldsPermission(unref(formFields)) - } - // 默认的表单权限: 获取表单的所有字段,设置字段默认权限为只读 - const getDefaultFieldsPermission = (formFields?: string[]) => { - const defaultFieldsPermission: Array> = [] - if (formFields) { - formFields.forEach((fieldStr: string) => { - parseFieldsSetDefaultPermission(JSON.parse(fieldStr), defaultFieldsPermission) - }) - } - return defaultFieldsPermission - } - // 解析字段。赋给默认权限 - const parseFieldsSetDefaultPermission = ( - rule: Record, - fieldsPermission: Array>, - parentTitle: string = '' - ) => { - const { /**type,*/ field, title: tempTitle, children } = rule - if (field && tempTitle) { - let title = tempTitle - if (parentTitle) { - title = `${parentTitle}.${tempTitle}` - } - fieldsPermission.push({ - field, - title, - permission: defaultPermission - }) - // TODO 子表单 需要处理子表单字段 - // if (type === 'group' && rule.props?.rule && Array.isArray(rule.props.rule)) { - // // 解析子表单的字段 - // rule.props.rule.forEach((item) => { - // parseFieldsSetDefaultPermission(item, fieldsPermission, title) - // }) - // } - } - if (children && Array.isArray(children)) { - children.forEach((rule) => { - parseFieldsSetDefaultPermission(rule, fieldsPermission) - }) - } - } - - return { - formType, - fieldsPermissionConfig, - getNodeConfigFormFields - } -} - const userOptions = ref([]) // 用户列表 onMounted(async () => { // 获得用户列表