Skip to content

Commit a911af3

Browse files
YunaiVgitee-org
authored andcommitted
!715 feat: 流程审批,预测下个节点是否需要选择审批人
Merge pull request !715 from SamllNorth_Lee/smallNorth/bpm
2 parents 520c9af + 3ef04b5 commit a911af3

File tree

4 files changed

+75
-11
lines changed

4 files changed

+75
-11
lines changed

src/views/bpm/processInstance/create/ProcessDefinitionDetail.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const getApprovalDetail = async (row: any) => {
183183
const data = await ProcessInstanceApi.getApprovalDetail({
184184
processDefinitionId: row.id,
185185
activityId: NodeId.START_USER_NODE_ID,
186-
processVariablesStr: JSON.stringify(row.processVariablesStr) // 解决 GET 无法传递对象的问题,后端 String 再转 JSON
186+
processVariablesStr: row.processVariablesStr // 解决 GET 无法传递对象的问题,后端 String 再转 JSON
187187
})
188188
189189
if (!data) {

src/views/bpm/processInstance/detail/ProcessInstanceOperationButton.vue

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@
4444
:rows="4"
4545
/>
4646
</el-form-item>
47+
<el-form-item
48+
label="选择下一个节点的审批人"
49+
prop="nextAssignees"
50+
v-if="dialogVisibleSelectApproveUser"
51+
>
52+
<ProcessInstanceTimeline
53+
ref="timelineRef"
54+
:activity-nodes="activityNodes"
55+
:show-status-icon="false"
56+
@select-user-confirm="selectUserConfirm"
57+
/>
58+
</el-form-item>
4759
<el-form-item
4860
v-if="runningTask.signEnable"
4961
label="签名"
@@ -506,11 +518,13 @@ import * as UserApi from '@/api/system/user'
506518
import {
507519
NodeType,
508520
OPERATION_BUTTON_NAME,
509-
OperationButtonType
521+
OperationButtonType,
522+
CandidateStrategy
510523
} from '@/components/SimpleProcessDesignerV2/src/consts'
511524
import { BpmModelFormType, BpmProcessInstanceStatus } from '@/utils/constants'
512525
import type { FormInstance, FormRules } from 'element-plus'
513526
import SignDialog from './SignDialog.vue'
527+
import ProcessInstanceTimeline from '../detail/ProcessInstanceTimeline.vue'
514528
515529
defineOptions({ name: 'ProcessInstanceBtnContainer' })
516530
@@ -548,6 +562,8 @@ const runningTask = ref<any>() // 运行中的任务
548562
const approveForm = ref<any>({}) // 审批通过时,额外的补充信息
549563
const approveFormFApi = ref<any>({}) // approveForms 的 fAPi
550564
const nodeTypeName = ref('审批') // 节点类型名称
565+
const activityNodes = ref<ProcessInstanceApi.ApprovalNodeInfo[]>([]) // 审批节点信息
566+
const dialogVisibleSelectApproveUser = ref(false) // 是否显示节点审批人选择框
551567
552568
// 审批通过意见表单
553569
const reasonRequire = ref()
@@ -556,14 +572,16 @@ const signRef = ref()
556572
const approveSignFormRef = ref()
557573
const approveReasonForm = reactive({
558574
reason: '',
559-
signPicUrl: ''
575+
signPicUrl: '',
576+
nextAssignees: {}
560577
})
561578
const approveReasonRule = computed(() => {
562579
return {
563580
reason: [
564581
{ required: reasonRequire.value, message: nodeTypeName + '意见不能为空', trigger: 'blur' }
565582
],
566-
signPicUrl: [{ required: true, message: '签名不能为空', trigger: 'change' }]
583+
signPicUrl: [{ required: true, message: '签名不能为空', trigger: 'change' }],
584+
nextAssignees: [{ required: true, message: '审批人不能为空', trigger: 'blur' }]
567585
}
568586
})
569587
// 拒绝表单
@@ -663,6 +681,11 @@ watch(
663681
}
664682
)
665683
684+
/** 选择下一个节点的审批人 */
685+
const selectUserConfirm = (id: string, userList: any[]) => {
686+
approveReasonForm.nextAssignees[id] = userList?.map((item: any) => item.id)
687+
}
688+
666689
/** 弹出气泡卡 */
667690
const openPopover = async (type: string) => {
668691
if (type === 'approve') {
@@ -672,6 +695,7 @@ const openPopover = async (type: string) => {
672695
message.warning('表单校验不通过,请先完善表单!!')
673696
return
674697
}
698+
initNextTaskSelectAssigneeFormField()
675699
}
676700
if (type === 'return') {
677701
// 获取退回节点
@@ -694,6 +718,34 @@ const closePropover = (type: string, formRef: FormInstance | undefined) => {
694718
formRef.resetFields()
695719
}
696720
popOverVisible.value[type] = false
721+
dialogVisibleSelectApproveUser.value = false
722+
}
723+
724+
/** // 流程通过时,根据表单变量查询新的流程节点,判断下一个节点类型是否为自选审批人 */
725+
const initNextTaskSelectAssigneeFormField = async () => {
726+
// 获取修改的流程变量, 暂时只支持流程表单
727+
const variables = getUpdatedProcessInstanceVariables()
728+
const param = {
729+
processInstanceId: props.processInstance.id,
730+
processVariablesStr: JSON.stringify(variables)
731+
}
732+
const res = await ProcessInstanceApi.getApprovalDetail(param)
733+
//当前待审批节点id
734+
const activityId = res.todoTask?.taskDefinitionKey
735+
if (res.activityNodes && res.activityNodes.length > 0) {
736+
// 找到当前节点的索引
737+
const currentNodeIndex = res.activityNodes.findIndex((node) => node.id === activityId)
738+
const nextNode = res.activityNodes[currentNodeIndex + 1]
739+
if (
740+
nextNode.candidateStrategy === CandidateStrategy.START_USER_SELECT &&
741+
!nextNode.tasks &&
742+
nextNode.candidateUsers?.length === 0
743+
) {
744+
// 自选审批人,则弹出选择审批人弹窗
745+
activityNodes.value = [nextNode]
746+
dialogVisibleSelectApproveUser.value = true
747+
}
748+
}
697749
}
698750
699751
/** 处理审批通过和不通过的操作 */
@@ -711,13 +763,21 @@ const handleAudit = async (pass: boolean, formRef: FormInstance | undefined) =>
711763
}
712764
713765
if (pass) {
714-
// 获取修改的流程变量, 暂时只支持流程表单
766+
// 如果需要自选审批人,则校验自选审批人
767+
if (
768+
dialogVisibleSelectApproveUser.value &&
769+
Object.keys(approveReasonForm.nextAssignees).length === 0
770+
) {
771+
message.warning('下一个节点的审批人不能为空!')
772+
return
773+
}
715774
const variables = getUpdatedProcessInstanceVariables()
716775
// 审批通过数据
717776
const data = {
718777
id: runningTask.value.id,
719778
reason: approveReasonForm.reason,
720-
variables // 审批通过, 把修改的字段值赋于流程实例变量
779+
variables, // 审批通过, 把修改的字段值赋于流程实例变量
780+
nextAssignees: approveReasonForm.nextAssignees // 下个自选节点选择的审批人信息
721781
}
722782
// 签名
723783
if (runningTask.value.signEnable) {
@@ -733,6 +793,7 @@ const handleAudit = async (pass: boolean, formRef: FormInstance | undefined) =>
733793
}
734794
await TaskApi.approveTask(data)
735795
popOverVisible.value.approve = false
796+
dialogVisibleSelectApproveUser.value = false
736797
message.success('审批通过成功')
737798
} else {
738799
// 审批不通过数据
@@ -1009,6 +1070,11 @@ const validateNormalForm = async () => {
10091070
}
10101071
}
10111072
1073+
/**
1074+
* TODO @小北 TO @芋道
1075+
* 问题:这里存在一种场景会出现问题,流程发起后,A节点审批完成,B节点没有可编辑的流程字段且B节点为自选审批人节点,会导致流程审批人为空,
1076+
* 原因:因为没有可编辑的流程字段时props.writableFields为空,参数variables传递时也为空
1077+
*/
10121078
/** 从可以编辑的流程表单字段,获取需要修改的流程实例的变量 */
10131079
const getUpdatedProcessInstanceVariables = () => {
10141080
const variables = {}

src/views/bpm/processInstance/detail/ProcessInstanceSimpleViewer.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ watch(
4242
const finishedSequenceFlowActivityIds: string[] = newModelView.finishedSequenceFlowActivityIds
4343
setSimpleModelNodeTaskStatus(
4444
newModelView.simpleModel,
45-
newModelView.processInstance.status,
45+
newModelView.processInstance?.status,
4646
rejectedTaskActivityIds,
4747
unfinishedTaskActivityIds,
4848
finishedActivityIds,
4949
finishedSequenceFlowActivityIds
5050
)
51-
simpleModel.value = newModelView.simpleModel
51+
simpleModel.value = newModelView.simpleModel ? newModelView.simpleModel : {}
5252
}
5353
}
5454
)
@@ -171,5 +171,4 @@ const setSimpleModelNodeTaskStatus = (
171171
}
172172
</script>
173173

174-
<style lang="scss" scoped>
175-
</style>
174+
<style lang="scss" scoped></style>

src/views/bpm/processInstance/detail/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ const writableFields: Array<string> = [] // 表单可以编辑的字段
179179
/** 获得详情 */
180180
const getDetail = () => {
181181
getApprovalDetail()
182-
183182
getProcessModelView()
184183
}
185184

0 commit comments

Comments
 (0)