Skip to content

Commit 22e9eb2

Browse files
committed
feat: bpm设计器适配Simple设计器,字段权限
1 parent 513ea33 commit 22e9eb2

File tree

3 files changed

+245
-4
lines changed

3 files changed

+245
-4
lines changed

src/components/bpmnProcessDesigner/package/designer/plugins/descriptor/flowableDescriptor.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,31 @@
13051305
"isAttr": true
13061306
}
13071307
]
1308+
},
1309+
{
1310+
"name": "FieldsPermission",
1311+
"superClass": ["Element"],
1312+
"meta": {
1313+
"allowedIn": ["bpmn:UserTask"]
1314+
},
1315+
"properties": [
1316+
{
1317+
"name": "flowable:field",
1318+
"type": "String",
1319+
"isAttr": true
1320+
},
1321+
{
1322+
"name": "flowable:title",
1323+
"type": "String",
1324+
"isAttr": true
1325+
},
1326+
{
1327+
"name": "flowable:permission",
1328+
"type": "String",
1329+
"isAttr": true
1330+
}
1331+
]
13081332
}
1309-
13101333
],
13111334
"emumerations": []
13121335
}

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

Lines changed: 207 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
2. 审批人拒绝时
44
3. 审批人为空时
55
4. 操作按钮
6+
5. 字段权限
67
-->
78
<template>
89
<div class="panel-tab__content">
@@ -104,6 +105,47 @@
104105
</div>
105106
</div>
106107
</div>
108+
109+
<el-divider content-position="left">字段权限</el-divider>
110+
<div class="field-setting-pane" v-if="formType === 10">
111+
<div class="field-permit-title">
112+
<div class="setting-title-label first-title"> 字段名称 </div>
113+
<div class="other-titles">
114+
<span class="setting-title-label">只读</span>
115+
<span class="setting-title-label">可编辑</span>
116+
<span class="setting-title-label">隐藏</span>
117+
</div>
118+
</div>
119+
<div class="field-setting-item" v-for="(item, index) in fieldsPermissionEl" :key="index">
120+
<div class="field-setting-item-label"> {{ item.title }} </div>
121+
<el-radio-group class="field-setting-item-group" v-model="item.permission">
122+
<div class="item-radio-wrap">
123+
<el-radio
124+
:value="FieldPermissionType.READ"
125+
size="large"
126+
:label="FieldPermissionType.READ"
127+
><span></span
128+
></el-radio>
129+
</div>
130+
<div class="item-radio-wrap">
131+
<el-radio
132+
:value="FieldPermissionType.WRITE"
133+
size="large"
134+
:label="FieldPermissionType.WRITE"
135+
><span></span
136+
></el-radio>
137+
</div>
138+
<div class="item-radio-wrap">
139+
<el-radio
140+
:value="FieldPermissionType.NONE"
141+
size="large"
142+
:label="FieldPermissionType.NONE"
143+
><span></span
144+
></el-radio>
145+
</div>
146+
</el-radio-group>
147+
</div>
148+
</div>
107149
</div>
108150
</template>
109151

@@ -115,9 +157,11 @@ import {
115157
ASSIGN_EMPTY_HANDLER_TYPES,
116158
AssignEmptyHandlerType,
117159
OPERATION_BUTTON_NAME,
118-
DEFAULT_BUTTON_SETTING
160+
DEFAULT_BUTTON_SETTING,
161+
FieldPermissionType
119162
} from '@/components/SimpleProcessDesignerV2/src/consts'
120163
import * as UserApi from '@/api/system/user'
164+
import { cloneDeep } from 'lodash-es'
121165
122166
defineOptions({ name: 'ElementCustomConfig' })
123167
const props = defineProps({
@@ -148,6 +192,12 @@ const buttonsSettingEl = ref()
148192
const { buttonsSetting, btnDisplayNameEdit, changeBtnDisplayName, btnDisplayNameBlurEvent } =
149193
useButtonsSetting()
150194
195+
// 字段权限
196+
const fieldsPermissionEl = ref()
197+
const { formType, fieldsPermissionConfig, getNodeConfigFormFields } = useFormFieldsPermission(
198+
FieldPermissionType.READ
199+
)
200+
151201
const elExtensionElements = ref()
152202
const otherExtensions = ref()
153203
const bpmnElement = ref()
@@ -218,6 +268,21 @@ const resetCustomConfigList = () => {
218268
})
219269
}
220270
271+
// 字段权限
272+
if (formType.value === 10) {
273+
fieldsPermissionEl.value = elExtensionElements.value.values?.filter(
274+
(ex) => ex.$type === `${prefix}:FieldsPermission`
275+
)
276+
if (fieldsPermissionEl.value.length === 0) {
277+
getNodeConfigFormFields()
278+
fieldsPermissionConfig.value.forEach((el) => {
279+
fieldsPermissionEl.value.push(
280+
bpmnInstances().moddle.create(`${prefix}:FieldsPermission`, el)
281+
)
282+
})
283+
}
284+
}
285+
221286
// 保留剩余扩展元素,便于后面更新该元素对应属性
222287
otherExtensions.value =
223288
elExtensionElements.value.values?.filter(
@@ -227,7 +292,8 @@ const resetCustomConfigList = () => {
227292
ex.$type !== `${prefix}:RejectReturnTaskId` &&
228293
ex.$type !== `${prefix}:AssignEmptyHandlerType` &&
229294
ex.$type !== `${prefix}:AssignEmptyUserIds` &&
230-
ex.$type !== `${prefix}:ButtonsSetting`
295+
ex.$type !== `${prefix}:ButtonsSetting` &&
296+
ex.$type !== `${prefix}:FieldsPermission`
231297
) ?? []
232298
233299
// 更新元素扩展属性,避免后续报错
@@ -276,7 +342,8 @@ const updateElementExtensions = () => {
276342
returnNodeIdEl.value,
277343
assignEmptyHandlerTypeEl.value,
278344
assignEmptyUserIdsEl.value,
279-
...buttonsSettingEl.value
345+
...buttonsSettingEl.value,
346+
...fieldsPermissionEl.value
280347
]
281348
})
282349
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
@@ -359,6 +426,69 @@ function useButtonsSetting() {
359426
}
360427
}
361428
429+
// 表单字段权限设置
430+
function useFormFieldsPermission(defaultPermission) {
431+
// 字段权限配置. 需要有 field, title, permissioin 属性
432+
const fieldsPermissionConfig = ref<Array<Record<string, string>>>([])
433+
434+
const formType = inject<Ref<number>>('formType') // 表单类型
435+
436+
const formFields = inject<Ref<string[]>>('formFields') // 流程表单字段
437+
438+
const getNodeConfigFormFields = (nodeFormFields?: Array<Record<string, string>>) => {
439+
nodeFormFields = toRaw(nodeFormFields)
440+
fieldsPermissionConfig.value =
441+
cloneDeep(nodeFormFields) || getDefaultFieldsPermission(unref(formFields))
442+
}
443+
// 默认的表单权限: 获取表单的所有字段,设置字段默认权限为只读
444+
const getDefaultFieldsPermission = (formFields?: string[]) => {
445+
const defaultFieldsPermission: Array<Record<string, string>> = []
446+
if (formFields) {
447+
formFields.forEach((fieldStr: string) => {
448+
parseFieldsSetDefaultPermission(JSON.parse(fieldStr), defaultFieldsPermission)
449+
})
450+
}
451+
return defaultFieldsPermission
452+
}
453+
// 解析字段。赋给默认权限
454+
const parseFieldsSetDefaultPermission = (
455+
rule: Record<string, any>,
456+
fieldsPermission: Array<Record<string, string>>,
457+
parentTitle: string = ''
458+
) => {
459+
const { /**type,*/ field, title: tempTitle, children } = rule
460+
if (field && tempTitle) {
461+
let title = tempTitle
462+
if (parentTitle) {
463+
title = `${parentTitle}.${tempTitle}`
464+
}
465+
fieldsPermission.push({
466+
field,
467+
title,
468+
permission: defaultPermission
469+
})
470+
// TODO 子表单 需要处理子表单字段
471+
// if (type === 'group' && rule.props?.rule && Array.isArray(rule.props.rule)) {
472+
// // 解析子表单的字段
473+
// rule.props.rule.forEach((item) => {
474+
// parseFieldsSetDefaultPermission(item, fieldsPermission, title)
475+
// })
476+
// }
477+
}
478+
if (children && Array.isArray(children)) {
479+
children.forEach((rule) => {
480+
parseFieldsSetDefaultPermission(rule, fieldsPermission)
481+
})
482+
}
483+
}
484+
485+
return {
486+
formType,
487+
fieldsPermissionConfig,
488+
getNodeConfigFormFields
489+
}
490+
}
491+
362492
const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
363493
onMounted(async () => {
364494
// 获得用户列表
@@ -449,4 +579,78 @@ onMounted(async () => {
449579
}
450580
}
451581
}
582+
583+
.field-setting-pane {
584+
display: flex;
585+
flex-direction: column;
586+
font-size: 14px;
587+
588+
.field-setting-desc {
589+
padding-right: 8px;
590+
margin-bottom: 16px;
591+
font-size: 16px;
592+
font-weight: 700;
593+
}
594+
595+
.field-permit-title {
596+
display: flex;
597+
justify-content: space-between;
598+
align-items: center;
599+
height: 45px;
600+
padding-left: 12px;
601+
line-height: 45px;
602+
background-color: #f8fafc0a;
603+
border: 1px solid #1f38581a;
604+
605+
.first-title {
606+
text-align: left !important;
607+
}
608+
609+
.other-titles {
610+
display: flex;
611+
justify-content: space-between;
612+
}
613+
614+
.setting-title-label {
615+
display: inline-block;
616+
width: 100px;
617+
padding: 5px 0;
618+
font-size: 13px;
619+
font-weight: 700;
620+
color: #000;
621+
text-align: center;
622+
}
623+
}
624+
625+
.field-setting-item {
626+
align-items: center;
627+
display: flex;
628+
justify-content: space-between;
629+
height: 38px;
630+
padding-left: 12px;
631+
border: 1px solid #1f38581a;
632+
border-top: 0;
633+
634+
.field-setting-item-label {
635+
display: inline-block;
636+
width: 100px;
637+
min-height: 16px;
638+
overflow: hidden;
639+
text-overflow: ellipsis;
640+
white-space: nowrap;
641+
cursor: text;
642+
}
643+
644+
.field-setting-item-group {
645+
display: flex;
646+
justify-content: space-between;
647+
648+
.item-radio-wrap {
649+
display: inline-block;
650+
width: 100px;
651+
text-align: center;
652+
}
653+
}
654+
}
655+
}
452656
</style>

src/views/bpm/model/editor/index.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ import CustomContentPadProvider from '@/components/bpmnProcessDesigner/package/d
3131
// 自定义左侧菜单(修改 默认任务 为 用户任务)
3232
import CustomPaletteProvider from '@/components/bpmnProcessDesigner/package/designer/plugins/palette'
3333
import * as ModelApi from '@/api/bpm/model'
34+
import { getForm, FormVO } from '@/api/bpm/form'
3435
3536
defineOptions({ name: 'BpmModelEditor' })
3637
3738
const router = useRouter() // 路由
3839
const { query } = useRoute() // 路由的查询
3940
const message = useMessage() // 国际化
4041
42+
// 表单信息
43+
const formFields = ref<string[]>([])
44+
const formType = ref(20)
45+
provide('formFields', formFields)
46+
provide('formType', formType)
47+
4148
const xmlString = ref(undefined) // BPMN XML
4249
const modeler = ref(null) // BPMN Modeler
4350
const controlForm = ref({
@@ -99,6 +106,13 @@ onMounted(async () => {
99106
</bpmndi:BPMNDiagram>
100107
</definitions>`
101108
}
109+
110+
formType.value = data.formType
111+
if (data.formType === 10) {
112+
const bpmnForm = (await getForm(data.formId)) as unknown as FormVO
113+
formFields.value = bpmnForm?.fields
114+
}
115+
102116
model.value = {
103117
...data,
104118
bpmnXml: undefined // 清空 bpmnXml 属性

0 commit comments

Comments
 (0)