Skip to content

Commit b346545

Browse files
committed
feat: 流程审批,预测下个节点是否需要选择审批人
1 parent de35fd0 commit b346545

File tree

4 files changed

+85
-32
lines changed

4 files changed

+85
-32
lines changed

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,24 @@ const initProcessInfo = async (row: any, formVariables?: any) => {
157157
}
158158
159159
/** 预测流程节点会因为输入的参数值而产生新的预测结果值,所以需重新预测一次 */
160-
// TODO @芋艿:这里我执行填写表单的时候不知道为啥一直报错,先注释了 @lesan:可以和群里的小北说下
161-
// watch(
162-
// detailForm.value,
163-
// (newValue) => {
164-
// if (newValue && Object.keys(newValue.value).length > 0) {
165-
// // 记录之前的节点审批人
166-
// tempStartUserSelectAssignees.value = startUserSelectAssignees.value
167-
// startUserSelectAssignees.value = {}
168-
// // 加载最新的审批详情
169-
// getApprovalDetail({
170-
// id: props.selectProcessDefinition.id,
171-
// processVariablesStr: JSON.stringify(newValue.value) // 解决 GET 无法传递对象的问题,后端 String 再转 JSON
172-
// })
173-
// }
174-
// },
175-
// {
176-
// immediate: true
177-
// }
178-
// )
160+
watch(
161+
detailForm.value,
162+
(newValue) => {
163+
if (newValue && Object.keys(newValue.value).length > 0) {
164+
// 记录之前的节点审批人
165+
tempStartUserSelectAssignees.value = startUserSelectAssignees.value
166+
startUserSelectAssignees.value = {}
167+
// 加载最新的审批详情
168+
getApprovalDetail({
169+
id: props.selectProcessDefinition.id,
170+
processVariablesStr: newValue.value // 解决 GET 无法传递对象的问题,后端 String 再转 JSON
171+
})
172+
}
173+
},
174+
{
175+
immediate: true
176+
}
177+
)
179178
180179
/** 获取审批详情 */
181180
const getApprovalDetail = async (row: any) => {

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

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
:rule="approveForm.rule"
3737
/>
3838
</el-card>
39+
<el-form-item
40+
label="选择审批人"
41+
prop="selectApproveUser"
42+
v-if="dialogVisibleSelectApproveUser"
43+
>
44+
<ProcessInstanceTimeline
45+
ref="timelineRef"
46+
:activity-nodes="activityNodes"
47+
:show-status-icon="false"
48+
@select-user-confirm="selectUserConfirm"
49+
/>
50+
</el-form-item>
3951
<el-form-item :label="`${nodeTypeName}意见`" prop="reason">
4052
<el-input
4153
v-model="approveReasonForm.reason"
@@ -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+
selectApproveUser: {}
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+
selectApproveUser: [{ required: true, message: '审批人不能为空', trigger: 'change' }]
567585
}
568586
})
569587
// 拒绝表单
@@ -663,6 +681,11 @@ watch(
663681
}
664682
)
665683
684+
/** 选择发起人 */
685+
const selectUserConfirm = (id: string, userList: any[]) => {
686+
approveReasonForm.selectApproveUser[id] = userList?.map((item: any) => item.id)
687+
}
688+
666689
/** 弹出气泡卡 */
667690
const openPopover = async (type: string) => {
668691
if (type === 'approve') {
@@ -694,6 +717,7 @@ const closePropover = (type: string, formRef: FormInstance | undefined) => {
694717
formRef.resetFields()
695718
}
696719
popOverVisible.value[type] = false
720+
dialogVisibleSelectApproveUser.value = false
697721
}
698722
699723
/** 处理审批通过和不通过的操作 */
@@ -711,13 +735,44 @@ const handleAudit = async (pass: boolean, formRef: FormInstance | undefined) =>
711735
}
712736
713737
if (pass) {
738+
// 如果需要自选审批人,则校验自选审批人
739+
if (
740+
dialogVisibleSelectApproveUser.value &&
741+
Object.keys(approveReasonForm.selectApproveUser).length === 0
742+
) {
743+
message.warning('审批人不能为空!')
744+
return
745+
}
714746
// 获取修改的流程变量, 暂时只支持流程表单
715747
const variables = getUpdatedProcessInstanceVariables()
748+
const param = {
749+
processInstanceId: props.processInstance.id,
750+
processVariablesStr: JSON.stringify(variables)
751+
}
752+
// 流程通过时,根据表单变量查询新的流程节点,判断下一个节点类型是否为自选审批人
753+
const res = await ProcessInstanceApi.getApprovalDetail(param)
754+
//当前待审批节点id
755+
const activityId = res.todoTask?.taskDefinitionKey
756+
if (res.activityNodes && res.activityNodes.length > 0) {
757+
// 找到当前节点的索引
758+
const currentNodeIndex = res.activityNodes.findIndex((node) => node.id === activityId)
759+
const nextNode = res.activityNodes[currentNodeIndex + 1]
760+
if (
761+
nextNode.candidateStrategy === CandidateStrategy.START_USER_SELECT &&
762+
!nextNode.tasks &&
763+
nextNode.candidateUsers?.length === 0
764+
) {
765+
// 自选审批人,则弹出选择审批人弹窗
766+
activityNodes.value = [nextNode]
767+
dialogVisibleSelectApproveUser.value = true
768+
}
769+
}
716770
// 审批通过数据
717771
const data = {
718772
id: runningTask.value.id,
719773
reason: approveReasonForm.reason,
720-
variables // 审批通过, 把修改的字段值赋于流程实例变量
774+
variables, // 审批通过, 把修改的字段值赋于流程实例变量
775+
startUserSelectAssignees: approveReasonForm.selectApproveUser // 下个自选节点选择的审批人信息
721776
}
722777
// 签名
723778
if (runningTask.value.signEnable) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ watch(
4848
finishedActivityIds,
4949
finishedSequenceFlowActivityIds
5050
)
51-
simpleModel.value = newModelView.simpleModel
51+
simpleModel.value = newModelView.simpleModel == null ? {} : newModelView.simpleModel
5252
}
5353
}
5454
)

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,21 @@ const writableFields: Array<string> = [] // 表单可以编辑的字段
178178
179179
/** 获得详情 */
180180
const getDetail = () => {
181-
getApprovalDetail()
182-
181+
const param = {
182+
processInstanceId: props.id,
183+
activityId: props.activityId,
184+
taskId: props.taskId
185+
}
186+
getApprovalDetail(param)
183187
getProcessModelView()
184188
}
185189
186190
/** 加载流程实例 */
187191
const BusinessFormComponent = ref<any>(null) // 异步组件
188192
/** 获取审批详情 */
189-
const getApprovalDetail = async () => {
193+
const getApprovalDetail = async (param?: any) => {
190194
processInstanceLoading.value = true
191195
try {
192-
const param = {
193-
processInstanceId: props.id,
194-
activityId: props.activityId,
195-
taskId: props.taskId
196-
}
197196
const data = await ProcessInstanceApi.getApprovalDetail(param)
198197
if (!data) {
199198
message.error('查询不到审批详情信息!')

0 commit comments

Comments
 (0)