refactor: 使用Simple设计器的useFormFieldsPermission

pull/614/head
Lesan 2024-12-11 09:18:15 +08:00
parent 4bd020857f
commit fe2ac97f9d
1 changed files with 6 additions and 67 deletions

View File

@ -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<Array<Record<string, string>>>([])
const formType = inject<Ref<number>>('formType') //
const formFields = inject<Ref<string[]>>('formFields') //
const getNodeConfigFormFields = (nodeFormFields?: Array<Record<string, string>>) => {
nodeFormFields = toRaw(nodeFormFields)
fieldsPermissionConfig.value =
cloneDeep(nodeFormFields) || getDefaultFieldsPermission(unref(formFields))
}
//
const getDefaultFieldsPermission = (formFields?: string[]) => {
const defaultFieldsPermission: Array<Record<string, string>> = []
if (formFields) {
formFields.forEach((fieldStr: string) => {
parseFieldsSetDefaultPermission(JSON.parse(fieldStr), defaultFieldsPermission)
})
}
return defaultFieldsPermission
}
//
const parseFieldsSetDefaultPermission = (
rule: Record<string, any>,
fieldsPermission: Array<Record<string, string>>,
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<UserApi.UserVO[]>([]) //
onMounted(async () => {
//